From f32fa7850a8cf57e38d2a7bb4f19c4aeb5d6224a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Mon, 5 Oct 2009 10:29:33 +0200 Subject: [PATCH 1/1] Fixed file upload. --- apps/api/management/commands/doc_share.py | 20 ++----- apps/explorer/views.py | 53 ++++++------------ project/static/css/autumn.css | 13 ++++- project/static/css/master.css | 13 +++++ project/static/css/toolbar.css | 61 +-------------------- project/templates/explorer/editor.html | 6 +- project/templates/explorer/file_list.html | 2 +- project/templates/explorer/file_upload.html | 13 ++--- project/templates/toolbar_api/scriptlets.js | 30 ---------- 9 files changed, 57 insertions(+), 154 deletions(-) delete mode 100644 project/templates/toolbar_api/scriptlets.js diff --git a/apps/api/management/commands/doc_share.py b/apps/api/management/commands/doc_share.py index cf454c53..08d61fe1 100644 --- a/apps/api/management/commands/doc_share.py +++ b/apps/api/management/commands/doc_share.py @@ -3,20 +3,12 @@ __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']: diff --git a/apps/explorer/views.py b/apps/explorer/views.py index 4e1c8938..9d01fc21 100644 --- a/apps/explorer/views.py +++ b/apps/explorer/views.py @@ -74,43 +74,26 @@ def file_list(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 # diff --git a/project/static/css/autumn.css b/project/static/css/autumn.css index a5f03fd3..dddd8996 100644 --- a/project/static/css/autumn.css +++ b/project/static/css/autumn.css @@ -30,11 +30,20 @@ body { } a:link, a:visited, a:active { - color: #395428; + color: #860000; 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; +} + diff --git a/project/static/css/master.css b/project/static/css/master.css index 5f81f17e..06196c7d 100644 --- a/project/static/css/master.css +++ b/project/static/css/master.css @@ -336,4 +336,17 @@ input.image-gallery-current-page { .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 diff --git a/project/static/css/toolbar.css b/project/static/css/toolbar.css index 4eddaad3..b5df66f3 100644 --- a/project/static/css/toolbar.css +++ b/project/static/css/toolbar.css @@ -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; } -.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 diff --git a/project/templates/explorer/editor.html b/project/templates/explorer/editor.html index 83843f14..1e0b8544 100644 --- a/project/templates/explorer/editor.html +++ b/project/templates/explorer/editor.html @@ -110,7 +110,7 @@
<% for (var i=0; i < buttons.length; i++) { %> - <%= buttons[i].name %> + <% }; %>
@@ -118,9 +118,9 @@ diff --git a/project/templates/explorer/file_list.html b/project/templates/explorer/file_list.html index a9b59e4c..f44a105c 100644 --- a/project/templates/explorer/file_list.html +++ b/project/templates/explorer/file_list.html @@ -82,7 +82,7 @@ $(function() {

Dodaj nowy utwór

-
+ {{ bookform }}

diff --git a/project/templates/explorer/file_upload.html b/project/templates/explorer/file_upload.html index 7c52626d..1deedac4 100755 --- a/project/templates/explorer/file_upload.html +++ b/project/templates/explorer/file_upload.html @@ -1,22 +1,17 @@ {% extends "base.html" %} {% block maincontent %} - - - - -

Dodawanie nowego utworu:

-{% if other_errors %} +{% if errors %}
-{% for error in other_errors %} -

{{ error }}

+{% for error in errors %} +

{{ error }}: {{ error.errors }}

{% endfor %}
{% endif %}
- {{ form.as_p }} + {{ bookform.as_p }}

{% endblock maincontent %} diff --git a/project/templates/toolbar_api/scriptlets.js b/project/templates/toolbar_api/scriptlets.js deleted file mode 100644 index 6f5258c9..00000000 --- a/project/templates/toolbar_api/scriptlets.js +++ /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 -- 2.20.1