Poprawki do file upload i toolbar.
authorŁukasz Rekucki <lrekucki@gmail.com>
Fri, 4 Sep 2009 08:43:37 +0000 (10:43 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Fri, 4 Sep 2009 08:43:37 +0000 (10:43 +0200)
apps/explorer/views.py
lib/hg.py
project/static/js/codemirror/util.js
project/static/js/jquery.logging.js
project/templates/base.html
project/templates/explorer/editor.html
project/templates/explorer/file_list.html

index ed58191..0c558fb 100644 (file)
@@ -60,21 +60,44 @@ def file_list(request, repo):
 @permission_required('explorer.can_add_files')
 @with_repo
 def file_upload(request, repo):
 @permission_required('explorer.can_add_files')
 @with_repo
 def file_upload(request, repo):
-    form = forms.BookUploadForm(request.POST, request.FILES)
-    if form.is_valid():
-        f = request.FILES['file']        
-
-        def upload_action():
-            print 'Adding file: %s' % f.name
-            repo._add_file(f.name, f.read().decode('utf-8'))
-            repo._commit(message="File %s uploaded from platform by %s" %
-                (f.name, request.user.username), user=request.user.username)
-
-        repo.in_branch(upload_action, 'default')
-        return HttpResponseRedirect( reverse('editor_view', kwargs={'path': f.name}) )
+    other_errors = []
 
 
+    if request.method == 'POST':
+        form = forms.BookUploadForm(request.POST, request.FILES)
+        if form.is_valid():
+            try:
+                # prepare the data
+                f = request.FILES['file']
+                decoded = f.read().decode('utf-8')
+
+                def upload_action():
+                    print 'Adding file: %s' % f.name
+                    repo._add_file(f.name, f.read().decode('utf-8'))
+                    repo._commit(
+                        message="File %s uploaded from platform by %s" %\
+                            (f.name, request.user.username), \
+                        user=request.user.username \
+                    )
+                    
+                    # end of upload
+
+                repo.in_branch(upload_action, 'default')
+
+                # if everything is ok, redirect to the editor
+                return HttpResponseRedirect( reverse('editor_view',
+                        kwargs={'path': f.name}) )
+
+            except hg.RepositoryException, e:
+                other_errors.append(u'Błąd repozytorium: ' + unicode(e) )
+            except UnicodeDecodeError, e:
+                other_errors.append(u'Niepoprawne kodowanie pliku: ' + e.reason \
+                 + u'. Żądane kodowanie: ' + e.encoding)
+        # invalid form
+
+    # get
+    form = forms.BookUploadForm()
     return direct_to_template(request, 'explorer/file_upload.html',
     return direct_to_template(request, 'explorer/file_upload.html',
-        extra_context = {'form' : form)
+        extra_context = {'form' : form, 'other_errors': other_errors})
    
 #
 # Edit the file
    
 #
 # Edit the file
index 9e08e51..b94b0d6 100644 (file)
--- a/lib/hg.py
+++ b/lib/hg.py
@@ -7,8 +7,7 @@ import mercurial.merge, mercurial.error
 encoding.encoding = 'utf-8'
 
 
 encoding.encoding = 'utf-8'
 
 
-class RepositoryDoesNotExist(Exception):
-    pass
+
 
 class Repository(object):
     """Abstrakcja repozytorium Mercurial. Działa z Mercurial w wersji 1.3.1."""
 
 class Repository(object):
     """Abstrakcja repozytorium Mercurial. Działa z Mercurial w wersji 1.3.1."""
@@ -100,7 +99,7 @@ class Repository(object):
         except KeyError, ke:
             raise RepositoryException("Can't switch to branch '%s': no such branch." % bname , ke)
         except util.Abort, ae:
         except KeyError, ke:
             raise RepositoryException("Can't switch to branch '%s': no such branch." % bname , ke)
         except util.Abort, ae:
-            raise repositoryException("Can't switch to branch '%s': %s"  % (bname, ae.message), ae)
+            raise RepositoryException("Can't switch to branch '%s': %s"  % (bname, ae.message), ae)
         finally:
             wlock.release()
 
         finally:
             wlock.release()
 
@@ -114,3 +113,6 @@ class RepositoryException(Exception):
     def __init__(self, msg, cause=None):
         Exception.__init__(self, msg)
         self.cause = cause
     def __init__(self, msg, cause=None):
         Exception.__init__(self, msg)
         self.cause = cause
+
+class RepositoryDoesNotExist(RepositoryException):
+    pass
index a1390a9..61f927d 100644 (file)
@@ -112,5 +112,5 @@ function addEventHandler(node, type, handler, removeFunc) {
 }
 
 function nodeText(node) {
 }
 
 function nodeText(node) {
-  return node.innerText || node.textContent || node.nodeValue || "";
+  return node.textContent || node.innerText || node.nodeValue || "";
 }
 }
index 0f0df51..315d48f 100644 (file)
@@ -1,9 +1,8 @@
 (function($) {
 (function($) {
-       const LEVEL_DEBUG = 1;
-       const LEVEL_INFO = 2;
-       const LEVEL_WARN = 3;
-
-       const LOG_LEVEL = LEVEL_DEBUG;
+       var LEVEL_DEBUG = 1;
+       var LEVEL_INFO = 2;
+       var LEVEL_WARN = 3;
+       var LOG_LEVEL = LEVEL_DEBUG;
 
        var mozillaLog = function() {
                if (window.console)
 
        var mozillaLog = function() {
                if (window.console)
index 86b63ad..5480999 100644 (file)
@@ -12,7 +12,7 @@
     </head>
     <body id="{% block bodyid %}base{% endblock %}">
        <div id="header">
     </head>
     <body id="{% block bodyid %}base{% endblock %}">
        <div id="header">
-               <span id="breadcrumbs">{% block breadcrumbs %}Platforma Redakcyjna{% endblock breadcrumbs %}</span>
+               <span id="breadcrumbs">{% block breadcrumbs %}<a href="{% url file_list %}">Platforma Redakcyjna</a>{% endblock breadcrumbs %}</span>
                <span id="header-right-toolbar">
                        {% block header-toolbar %}{% endblock %}
                        <span id="login_info">{% include "registration/head_login.html" %}</span>
                <span id="header-right-toolbar">
                        {% block header-toolbar %}{% endblock %}
                        <span id="login_info">{% include "registration/head_login.html" %}</span>
index 4d37618..6dce904 100644 (file)
@@ -26,7 +26,7 @@
     </script>
 {% endblock extrabody %}
 
     </script>
 {% endblock extrabody %}
 
-{% block breadcrumbs %}<a href="{% url file_list %}">Platforma Redakcyjna</a>  plik {{ hash }}{% endblock breadcrumbs %}
+{% block breadcrumbs %}<a href="{% url file_list %}">Platforma Redakcyjna</a> &gt; plik {{ hash }}{% endblock breadcrumbs %}
 
 {% block header-toolbar %}
        <button type="button" class="toolbar-button" id="toolbar-button-commit">Commit</button>
 
 {% block header-toolbar %}
        <button type="button" class="toolbar-button" id="toolbar-button-commit">Commit</button>
index 28c6b28..2513637 100644 (file)
@@ -1,9 +1,10 @@
 {% extends "base.html" %}
 
 {% block maincontent %}
 {% extends "base.html" %}
 
 {% block maincontent %}
-<h2>Dodaj nowy utwór</h2>
 
 {% if perms.explorer.can_add_files %}
 
 {% if perms.explorer.can_add_files %}
+<h2>Dodaj nowy utwór</h2>
+
 <form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
     {{ bookform.as_p }}
     <p><button type="submit">Dodaj książkę</button></p>
 <form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
     {{ bookform.as_p }}
     <p><button type="submit">Dodaj książkę</button></p>