From: Łukasz Rekucki Date: Mon, 31 Aug 2009 14:16:30 +0000 (+0200) Subject: Mozliwosc dodawania nowych plikow do repozytorium X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/ab2c0be6275e50a83cd07fff92a08e01a663abae?ds=inline;hp=-c Mozliwosc dodawania nowych plikow do repozytorium --- ab2c0be6275e50a83cd07fff92a08e01a663abae diff --git a/apps/explorer/forms.py b/apps/explorer/forms.py index c2f7c3a0..81e9f261 100644 --- a/apps/explorer/forms.py +++ b/apps/explorer/forms.py @@ -9,6 +9,9 @@ class BookForm(forms.Form): content = forms.CharField(widget=forms.Textarea) commit_message = forms.CharField(required=False) +class BookUploadForm(forms.Form): + file = forms.FileField() + class ImageFoldersForm(forms.Form): folders = forms.ChoiceField(required=False) diff --git a/apps/explorer/views.py b/apps/explorer/views.py index 7a34cad2..dbf5f3a1 100644 --- a/apps/explorer/views.py +++ b/apps/explorer/views.py @@ -6,6 +6,10 @@ from django.views.generic.simple import direct_to_template from django.conf import settings from django.http import HttpResponseRedirect, HttpResponse + +from django.core.urlresolvers import reverse +from django.core.paginator import Paginator, InvalidPage, EmptyPage + from django.contrib.auth.decorators import login_required from explorer import forms, models @@ -34,12 +38,38 @@ def ajax_login_required(view): # # View all files # - @with_repo def file_list(request, repo): + paginator = Paginator( repo.file_list(), 100); + bookform = forms.BookUploadForm() + + try: + page = int(request.GET.get('page', '1')) + except ValueError: + page = 1 + + try: + files = paginator.page(page) + except (EmptyPage, InvalidPage): + files = paginator.page(paginator.num_pages) + return direct_to_template(request, 'explorer/file_list.html', extra_context={ - 'objects': repo.all_files(), + 'files': files, 'page': page, 'bookform': bookform, }) + +@login_required +@with_repo +def file_upload(request, repo): + form = forms.BookUploadForm(request.POST, request.FILES) + if form.is_valid(): + f = request.FILES['file'] + print 'Adding file: %s' % f.name + repo.add_file(f.name, f.read().decode('utf-8')) + return HttpResponseRedirect( reverse('editor_view', kwargs={'path': f.name}) ) + + return direct_to_template(request, 'explorer/file_upload.html', + extra_context = {'form' : form} ) + # # Edit the file # @@ -53,9 +83,8 @@ def file_xml(request, repo, path): print 'Saving whole text.', request.user.username def save_action(): print 'In branch: ' + repo.repo[None].branch() - print repo._add_file(path, form.cleaned_data['content']) - print repo.repo.status() - print repo._commit(message=(form.cleaned_data['commit_message'] or 'Lokalny zapis platformy.'), user=request.user.username) + repo._add_file(path, form.cleaned_data['content']) + repo._commit(message=(form.cleaned_data['commit_message'] or 'Lokalny zapis platformy.'), user=request.user.username) print repo.in_branch(save_action, models.user_branch(request.user) ); result = "ok" diff --git a/lib/hg.py b/lib/hg.py index b8795b71..29229dd2 100644 --- a/lib/hg.py +++ b/lib/hg.py @@ -35,10 +35,10 @@ class Repository(object): return localrepo.localrepository(self.ui, path, create=1) raise RepositoryDoesNotExist("Repository %s does not exist." % path) - def all_files(self, branch='default'): - return self.in_branch(lambda: self._all_files(), branch) + def file_list(self, branch='default'): + return self.in_branch(lambda: self._file_list(), branch) - def _all_files(self): + def _file_list(self): return list(self.repo[None]) def get_file(self, path, branch='default'): @@ -52,11 +52,6 @@ class Repository(object): def _add_file(self, path, value): return self.repo.wwrite(path, value.encode('utf-8'), []) -# f = codecs.open(os.path.join(self.real_path, path), 'w', encoding='utf-8') -# f.write(value) -# f.close() -# if path not in self._pending_files: -# self._pending_files.append(path) def _commit(self, message, user=None): return self.repo.commit(text=message, user=user) diff --git a/project/settings.py b/project/settings.py index a4187068..e958113d 100644 --- a/project/settings.py +++ b/project/settings.py @@ -114,7 +114,8 @@ INSTALLED_APPS = ( 'toolbar', ) -REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books' + +# REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books' IMAGE_DIR = 'images' try: diff --git a/project/static/css/master.css b/project/static/css/master.css index 3f5741c1..040549e1 100644 --- a/project/static/css/master.css +++ b/project/static/css/master.css @@ -35,6 +35,7 @@ body { top: 2.4em; left: 0px; right: 0px; bottom: 0px; overflow: auto; background-color: white; + padding: 0.2em 1em; } ul { @@ -382,6 +383,37 @@ div.isection p { .msg-warning { background-color: yellow; - border-color: yellow; - + border-color: yellow; } + + +/* + * Object list table + */ + table.object-list { + border-top: 2px solid black; + border-left: 2px solid black; + border-right: 1px solid black; + border-bottom: 1px solid black; + width: 60%; + margin: auto; + } + + + table.object-list td, table.object-list th { + border-bottom: 1px solid black; + border-right: 1px solid black; + padding: 0.2em 0.5em; + } + + table.object-list th { + text-align: center; + background-color: #8080d0; + font-size: 120% + } + + table.object-list td.page-navigation { + position: relative; + text-align: center; + background-color: #CCC; + } \ No newline at end of file diff --git a/project/static/js/editor.js b/project/static/js/editor.js index 3b750cab..f9f09003 100644 --- a/project/static/js/editor.js +++ b/project/static/js/editor.js @@ -51,6 +51,7 @@ Panel.prototype.load = function (url) { }, error: function(request, textStatus, errorThrown) { $.log('ajax', url, this.target, 'error:', textStatus, errorThrown); + $(self.contentDiv).html("

Wystapił błąd podczas wczytywania panelu."); } }); } diff --git a/project/templates/explorer/file_list.html b/project/templates/explorer/file_list.html index bfbafe13..28c6b28e 100644 --- a/project/templates/explorer/file_list.html +++ b/project/templates/explorer/file_list.html @@ -1,9 +1,42 @@ {% extends "base.html" %} {% block maincontent %} -

+

Dodaj nowy utwór

+ +{% if perms.explorer.can_add_files %} +
+ {{ bookform.as_p }} +

+
+{% endif %} + +

Wszystkie utwory:

+ + + + + {% for file in files.object_list %} + + + + + + {% endfor %} +
Lp.Nazwa utworuWersje
{{forloop.counter0|add:files.start_index}}.{{ file }}  
+ + {% endblock maincontent %} diff --git a/project/urls.py b/project/urls.py index 22627ac6..551f2e07 100644 --- a/project/urls.py +++ b/project/urls.py @@ -11,6 +11,7 @@ urlpatterns = patterns('', url(r'^file/text/'+PATH_END, 'explorer.views.file_xml', name='file_xml'), url(r'^file/dc/'+PATH_END, 'explorer.views.file_dc', name='file_dc'), + url(r'^file/upload', 'explorer.views.file_upload', name='file_upload'), url(r'^images/(?P[^/]+)/$', 'explorer.views.folder_images', name='folder_image'), url(r'^images/$', 'explorer.views.folder_images', {'folder': '.'}, name='folder_image_ajax'),