Commits

Konstantine Rybnikov committed 55db85a

ok, now repository adding should work. At least I know django better now

  • Participants
  • Parent commits 818e1f0

Comments (0)

Files changed (10)

fat/fat_po_editor/forms.py

+# -*- coding: utf-8 -*-
+
+from django import forms
+
+class RepositoryForm(forms.Form):
+    path = forms.CharField(max_length=256)

fat/fat_po_editor/static/css/main.css

   #js-messages .error {
     background: rgba(255, 50, 50, 0.1); }
 
-#repositories-list .repo-name {
-  width: 500px; }
+#repositories-list #id_path {
+  width: 400px; }
 #repositories-list .repository-list {
   list-style: none; }
-  #repositories-list .repository-list li.repo {
-    cursor: pointer;
-    font-weight: bold;
-    text-decoration: underline; }
+#repositories-list div.add-form {
+  display: inline-block; }

fat/fat_po_editor/static/css/main.scss

 }
 
 #repositories-list {
-    .repo-name {
-        width: 500px;
+    #id_path {
+        width: 400px;
     }
     .repository-list {
         list-style: none;
-        li.repo {
-            cursor: pointer;
-            font-weight: bold;
-            text-decoration: underline;
-        }
+    }
+    div.add-form {
+        display: inline-block;
     }
 }

fat/fat_po_editor/templates/fat_po_editor/repositories_list.html

 {% end_add_js %}
 <h3>List of repositories</h2>
 <div id="repositories-list">
-    <form action="{% url fat_po_editor.views.repository.add %}" method="POST">{% csrf_token %}
-        {% if repositories %}
+    {% if repositories %}
         <ul class="repository-list">
             {% for repository in repositories %}
             <li class="repo">{{ repository.path }}</li>
         </ul>
         {% else %}
         {% trans "No repository path's have been added yet. Go ahead!" %}
-        {% endif %}
-        <div>
-            <input type="text" name="path" value="" class="repo-name" />
-            <input type="submit" name="Add" value="{% trans 'Add' %}" />
-            {% comment %}
-            <a href="javascript:void(0)"
-               class="add-repo pseudo">Add</a>
-            {% domready %}
-                var repolist = (
-                    new RepositoriesList({
-                        $list: $('#repositories-list'),
-                        add_url: '{% url fat_po_editor.views.repository.add %}',
-                        autocomplete_url: "{% url fat_po_editor.views.repository.path_autocomplete %}"}));
-            {% enddomready %}
-            {% endcomment %}
+    {% endif %}
+    <form action="{% url fat_po_editor.views.repository.add %}" method="POST">{% csrf_token %}
+        <div class="add-form">
+            {{ add_repo_form.as_p }}
         </div>
+        <input type="submit" name="Add" value="{% trans 'Add' %}" class="add" />
+        {% domready %}
+            $('#id_path')
+                .autocomplete({
+                    source: "{% url fat_po_editor.views.repository.path_autocomplete %}"});
+        {% enddomready %}
     </form>
 </div>

fat/fat_po_editor/templatetags/repository.py

 
 @register.inclusion_tag('fat_po_editor/repositories_list.html', takes_context=True)
 def repositories_list(context, repositories):
+    from fat_po_editor.forms import RepositoryForm
+    
+    add_repo_form = RepositoryForm()
+    
     return {'repositories': repositories,
-            'STATIC_URL': context['STATIC_URL']}
+            'STATIC_URL': context['STATIC_URL'],
+            'add_repo_form': add_repo_form}

fat/fat_po_editor/urls.py

 
 urlpatterns = patterns(
     'fat_po_editor.views',
-    (r'^$', 'index'),
+    (r'^$', 'repository.index'),
     (r'^repository/add$', 'repository.add'),
     (r'^path_autocomplete', 'repository.path_autocomplete')
     )

fat/fat_po_editor/views/__init__.py

 # -*- coding: utf-8 -*-
 
-from django.shortcuts import render_to_response
-from django.template import RequestContext
-from fat_po_editor import bl
+# from repository import index
 
-def index(request):
-    repositories = bl.repository.get_all()
-    return (
-        render_to_response(
-            'fat_po_editor/index.html', {
-                'repositories': repositories,
-                },
-            context_instance=RequestContext(request)))
+# from django.shortcuts import render_to_response
+# from django.template import RequestContext
+# from fat_po_editor import bl
+
+# def index(request):
+#     repositories = bl.repository.get_all()
+#     return (
+#         render_to_response(
+#             'fat_po_editor/index.html', {
+#                 'repositories': repositories,
+#                 },
+#             context_instance=RequestContext(request)))

fat/fat_po_editor/views/repository.py

 # -*- coding: utf-8 -*-
 
-from django.http import HttpResponse
+from django.shortcuts import render_to_response
+from django.http import HttpResponseRedirect
+from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext as _
+from django.template import RequestContext
 
-from fat_po_editor.util.json import json_http_response_success
 from fat_po_editor.util.json import json_http_response_fail
 from fat_po_editor.util.json import json_http_response
-from fat_po_editor.bl import repository
+
+from fat_po_editor import bl
+
+def index(request):
+    repositories = bl.repository.get_all()
+    return (
+        render_to_response(
+            'fat_po_editor/index.html', {
+                'repositories': repositories,
+                },
+            context_instance=RequestContext(request)))
 
 def add(request):
+    from django.contrib import messages
+    from fat_po_editor.forms import RepositoryForm
+    
     if request.method == 'POST':
-        repository_path = request.POST.get('path', '')
-        try:
-            repository.add(repository_path)
-        except repository.UserAlertError as e:
-            return HttpResponse({
-                        'message': e.message})
+        form = RepositoryForm(request.POST)
+        if form.is_valid():
+            try:
+                bl.repository.add(form.cleaned_data["path"])
+            except bl.repository.UserAlertError as e:
+                messages.add_message(request, messages.ERROR, e.message)
+                return HttpResponseRedirect(reverse(index))
         
-        repositories = list(x.path for x in repository.get_all() or [])
-
-        return HttpResponse({
-                'message': _(u'Repository path %(repository_path)s was added') % dict(
-                    repository_path=repository_path),
-                'repositories': repositories})
-    else:
-        return HttpResponse(u'Waiting for POST data')
+        messages.add_message(request,
+                             messages.SUCCESS,
+                             (_(u'Repository path %(repository_path)s was added') % dict(
+                                 repository_path=form.cleaned_data["path"])))
+    return HttpResponseRedirect(reverse(index))
 
 def path_autocomplete(request):
     from fat_po_editor.util.path import autocomplete
     path = request.GET.get('term', '')
     try:
         paths = autocomplete(path)
-    except repository.UserAlertError as e:
+    except bl.repository.UserAlertError as e:
         return json_http_response_fail({
                     'message': e.message})
     return json_http_response(paths)
 # timezone as the operating system.
 # If running in a Windows environment this must be set to the same as your
 # system time zone.
-TIME_ZONE = 'America/Chicago'
+TIME_ZONE = 'Europe/Kiev'
 
 # Language code for this installation. All choices can be found here:
 # http://www.i18nguy.com/unicode/language-identifiers.html
 #     'django.template.loaders.eggs.Loader',
 )
 
-MIDDLEWARE_CLASSES = (
-    'django.middleware.common.CommonMiddleware',
-    'django.contrib.sessions.middleware.SessionMiddleware',
-    'django.middleware.csrf.CsrfViewMiddleware',
-    'django.contrib.auth.middleware.AuthenticationMiddleware',
-    'django.contrib.messages.middleware.MessageMiddleware',
-)
-
 ROOT_URLCONF = 'fat.urls'
 
 ROOT_PATH = os.getcwd()
     'django.contrib.admin',
     'django.contrib.admindocs',
     'django.contrib.staticfiles',
+    'debug_toolbar',
 )
 
 import mongoengine
     "django.core.context_processors.static",
     "django.contrib.messages.context_processors.messages",
     )
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'debug_toolbar.middleware.DebugToolbarMiddleware',
+    )
+
+DEBUG_TOOLBAR_PANELS = (
+    'debug_toolbar.panels.version.VersionDebugPanel',
+    'debug_toolbar.panels.timer.TimerDebugPanel',
+    'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
+    'debug_toolbar.panels.headers.HeaderDebugPanel',
+    'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
+    'debug_toolbar.panels.template.TemplateDebugPanel',
+    'debug_toolbar.panels.sql.SQLDebugPanel',
+    'debug_toolbar.panels.signals.SignalDebugPanel',
+    'debug_toolbar.panels.logger.LoggingPanel',
+)
+
+INTERNAL_IPS = ('127.0.0.1')
 
 urlpatterns = patterns(
     '',
-    (r'^$', 'fat_po_editor.views.index'),
-    (r'^fat/', include('fat_po_editor.urls')),
-
     (r'^admin/doc/', include('django.contrib.admindocs.urls')),
     (r'^admin/', include(admin.site.urls)),
+    
+    # (r'^fat/', include('fat_po_editor.urls')),
 )
 
 urlpatterns += staticfiles_urlpatterns()
+
+urlpatterns += patterns('',
+    (r'^', include('fat_po_editor.urls')))