Fixed file upload.
authorŁukasz Rekucki <lrekucki@gmail.com>
Mon, 5 Oct 2009 08:29:33 +0000 (10:29 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Mon, 5 Oct 2009 08:29:33 +0000 (10:29 +0200)
apps/api/management/commands/doc_share.py
apps/explorer/views.py
project/static/css/autumn.css
project/static/css/master.css
project/static/css/toolbar.css
project/templates/explorer/editor.html
project/templates/explorer/file_list.html
project/templates/explorer/file_upload.html
project/templates/toolbar_api/scriptlets.js [deleted file]

index cf454c5..08d61fe 100644 (file)
@@ -3,20 +3,12 @@
 __author__="lreqc"
 __date__ ="$2009-09-08 14:31:26$"
 
 __author__="lreqc"
 __date__ ="$2009-09-08 14:31:26$"
 
-from django.core.management.base import BaseCommand
-from django.utils import simplejson as json
-from django.test.client import Client
-from django.core.urlresolvers import reverse
-
-from optparse import make_option
-
-class Command(BaseCommand):
-    
-    option_list = BaseCommand.option_list + (
-        make_option('-u', '--user', action='store', dest='username'),
-        make_option('-p', '--password', action='store', dest='password'),     
-    )
-    
+from django.core.management.base import NoArgsCommand
+
+# from optparse import make_option
+
+class Command(NoArgsCommand):
+      
     def handle(self, *args, **options):
         client = Client()
         if not options['username'] or not options['password']:
     def handle(self, *args, **options):
         client = Client()
         if not options['username'] or not options['password']:
index 4e1c893..9d01fc2 100644 (file)
@@ -74,43 +74,26 @@ 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):
-    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')
-                fileid = form.cleaned_data['bookname'].lower()
-                rpath = file_path(fileid)
-
-                if form.cleaned_data['autoxml']:
-                    decoded = librarian.wrap_text(decoded, unicode(date.today()) )
-                
-                def upload_action():
-                    repo._add_file(rpath, decoded.encode('utf-8') )
-                    repo._commit(message="File %s uploaded by user %s" % \
-                        (rpath, request.user.username), user=request.user.username)
-
-                repo.in_branch(upload_action, 'default')
+    from api.resources import library_resource
+    from api.forms import DocumentUploadForm
+    from django.http import HttpRequest, HttpResponseRedirect
 
 
-                # if everything is ok, redirect to the editor
-                return HttpResponseRedirect( reverse('editor_view',
-                        kwargs={'path': fileid}) )
+    response = library_resource.handler.create(request)
 
 
-            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',\
-        extra_context = {'form' : form, 'other_errors': other_errors})
-   
+    if isinstance(response, HttpResponse):
+        data = json.loads(response.content)
+        
+        if response.status_code == 201:
+            return HttpResponseRedirect( \
+                reverse("editor_view", args=[ data['name'] ]) )
+        else:
+            bookform = DocumentUploadForm(request.POST, request.FILES)
+            bookform.is_valid()
+            
+            return direct_to_template(request, 'explorer/file_upload.html',
+                extra_context={'bookform': bookform } )
+    
+       
 #
 # Edit the file
 #
 #
 # Edit the file
 #
index a5f03fd..dddd899 100644 (file)
@@ -30,11 +30,20 @@ body {
 }
 
 a:link, a:visited, a:active {
 }
 
 a:link, a:visited, a:active {
-    color: #395428;
+    color: #860000;
     text-decoration: none;
     font-weight: bold;
 }
 
 a:hover {
     text-decoration: underline;
     text-decoration: none;
     font-weight: bold;
 }
 
 a:hover {
     text-decoration: underline;
-}
\ No newline at end of file
+}
+
+.toolbar-buttons-container {
+    background-color: #E2CF62;
+}
+
+.toolbar-tabs-container {
+    background-color: #860000;
+}
+
index 5f81f17..06196c7 100644 (file)
@@ -336,4 +336,17 @@ input.image-gallery-current-page {
 .image-gallery-page-container img {
     /* border: 2px solid green; */
     margin: 0px;
 .image-gallery-page-container img {
     /* border: 2px solid green; */
     margin: 0px;
+}
+
+body#base button {
+    background-color: #DDD;
+    border-width: 1px;
+    padding: 0px 0.5em;    
+    font-family: Sans-Serif;
+    color: #000;
+    margin: 2px 4px;
+}
+
+body#base button:hover {
+    background-color: #EEE;
 }
\ No newline at end of file
 }
\ No newline at end of file
index 4eddaad..b5df66f 100644 (file)
@@ -1,64 +1,5 @@
-/* .toolbar {
-    overflow: hidden;
-    z-index: 100;
-    background: #AAA;
-    position: absolute;
-    top: 0px; left:0px; right: 0px; 
-    height: auto;
-    padding: 2px;
-    margin: 0px;
-}
-
-.toolbar p {
-    margin: 0px;
-
-    padding: 0px;
-    padding-left: 0.5em;
-
-    border: none;
-    background: #AAA;
-    font-size: 10px;
-    line-height: 12px;
-}
-
-.toolbar div {
-    background: green;
-    margin: 0px;
-    padding: 0px;
-} */
-
-.toolbar-buttons-container {
-    background: #DDD;
+.toolbar-buttons-container {    
     padding-top: 2px;
     padding-bottom: 2px;
 }
 
     padding-top: 2px;
     padding-bottom: 2px;
 }
 
-.toolbar-buttons-container a {
-    background: #DDD;
-    border: none;
-    padding: 2px 0.5em;
-    background: #AAA;
-    font-family: Sans-Serif;
-    color: #000;
-    text-decoration: none;
-}
-
-.toolbar-buttons-container a:hover {
-    background: #EEE;
-}
-
-.toolbar-buttons-container a:active {
-    background: yellow;
-}
-
-.panel-toolbar-extra a {
-    background: inherit;    
-}
-
-.toolbar-tabs-container a {
-    background: #CCC;
-}
-
-.toolbar-tabs-container a.active {
-    background: #DDD;
-}
\ No newline at end of file
index 83843f1..1e0b854 100644 (file)
                <div class="buttontoolbarview panel-toolbar">
                        <div class="buttontoolbarview-tabs toolbar-tabs-container toolbar-buttons-container">
                        <% for (var i=0; i < buttons.length; i++) { %>
                <div class="buttontoolbarview panel-toolbar">
                        <div class="buttontoolbarview-tabs toolbar-tabs-container toolbar-buttons-container">
                        <% for (var i=0; i < buttons.length; i++) { %>
-                               <a href="#" class="buttontoolbarview-tab" ui:groupindex="<%= i %>"><%= buttons[i].name %></a>
+                               <button type="button" class="buttontoolbarview-tab" ui:groupindex="<%= i %>"><%= buttons[i].name %></button>
                        <% }; %>
                        </div>
                        <div class="buttontoolbarview-groups ">
                        <% }; %>
                        </div>
                        <div class="buttontoolbarview-groups ">
                                <div class="buttontoolbarview-group toolbar-buttons-container" ui:groupIndex="<%= i %>" style="display: none">
                                        <% for (var j=0; j < buttons[i].buttons.length; j++) { %>
                                                <% if (buttons[i].buttons[j].scriptlet_id) { %>
                                <div class="buttontoolbarview-group toolbar-buttons-container" ui:groupIndex="<%= i %>" style="display: none">
                                        <% for (var j=0; j < buttons[i].buttons.length; j++) { %>
                                                <% if (buttons[i].buttons[j].scriptlet_id) { %>
-                                               <a href="#" class="buttontoolbarview-button" ui:groupindex="<%= i %>" ui:buttonindex="<%= j %>">
+                                               <button type="button" class="buttontoolbarview-button" ui:groupindex="<%= i %>" ui:buttonindex="<%= j %>">
                                                        <%= buttons[i].buttons[j].label %>
                                                        <%= buttons[i].buttons[j].label %>
-                                               </a>
+                                               </button>
                                                <% } %>
                                        <% } %>
                                </div>
                                                <% } %>
                                        <% } %>
                                </div>
index a9b59e4..f44a105 100644 (file)
@@ -82,7 +82,7 @@ $(function() {
 <div class="upload-file-widget">
 <h2>Dodaj nowy utwór</h2>
 
 <div class="upload-file-widget">
 <h2>Dodaj nowy utwór</h2>
 
-<form action="/api/documents" method="POST" enctype="multipart/form-data">
+<form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
     {{ bookform }}
     <p><button type="submit">Dodaj książkę</button></p>
 </form>
     {{ bookform }}
     <p><button type="submit">Dodaj książkę</button></p>
 </form>
index 7c52626..1deedac 100755 (executable)
@@ -1,22 +1,17 @@
 {% extends "base.html" %}
 
 {% block maincontent %}
 {% extends "base.html" %}
 
 {% block maincontent %}
-
-
-
-
-
 <h2>Dodawanie nowego utworu:</h2>
 
 <h2>Dodawanie nowego utworu:</h2>
 
-{% if other_errors %}
+{% if errors %}
 <div class="errorlist">
 <div class="errorlist">
-{% for error in other_errors %}
-<p>{{ error }}</p>
+{% for error in errors %}
+<p>{{ error }}: {{ error.errors }}</p>
 {% endfor %}
 </div>
 {% endif %}
 <form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
 {% endfor %}
 </div>
 {% endif %}
 <form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
-    {{ form.as_p }}
+    {{ bookform.as_p }}
     <p><button type="submit">Dodaj książkę</button></p>
 </form>
 {% endblock maincontent %}
     <p><button type="submit">Dodaj książkę</button></p>
 </form>
 {% endblock maincontent %}
diff --git a/project/templates/toolbar_api/scriptlets.js b/project/templates/toolbar_api/scriptlets.js
deleted file mode 100644 (file)
index 6f5258c..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-function ScriptletCenter() {
-
-    this.scriptlets = {
-        {% for scriptlet in scriptlets %}
-        "{{scriptlet.name}}": function(context, params) {
-            {{scriptlet.code|safe}}
-        },
-        {% endfor %}
-
-        _none: null
-    };   
-            
-}
-
-ScriptletCenter.prototype.XMLEditorSelectedText = function(panel) {
-    return panel.contentView.editor.selection();
-}
-
-ScriptletCenter.prototype.XMLEditorReplaceSelectedText = function(panel, replacement)
-{
-    panel.contentView.editor.replaceSelection(replacement);
-    /* TODO: fire the change event */
-}
-
-ScriptletCenter.prototype.XMLEditorMoveCursorForward = function(panel, n) {
-    var pos = panel.contentView.editor.cursorPosition();
-    panel.contentView.editor.selectLines(pos.line, pos.character + n);
-}
-
-scriptletCenter = new ScriptletCenter();
\ No newline at end of file