Mozliwosc dodawania nowych plikow do repozytorium
authorŁukasz Rekucki <lrekucki@gmail.com>
Mon, 31 Aug 2009 14:16:30 +0000 (16:16 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Mon, 31 Aug 2009 14:16:30 +0000 (16:16 +0200)
apps/explorer/forms.py
apps/explorer/views.py
lib/hg.py
project/settings.py
project/static/css/master.css
project/static/js/editor.js
project/templates/explorer/file_list.html
project/urls.py

index c2f7c3a..81e9f26 100644 (file)
@@ -9,6 +9,9 @@ class BookForm(forms.Form):
     content = forms.CharField(widget=forms.Textarea)
     commit_message = forms.CharField(required=False)
 
     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)
     
 class ImageFoldersForm(forms.Form):
     folders = forms.ChoiceField(required=False)
     
index 7a34cad..dbf5f3a 100644 (file)
@@ -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.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
 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
 #
 #
 # View all files
 #
-
 @with_repo
 def file_list(request, repo):
 @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={
     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
 #
 #
 # 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 '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"
 
             print repo.in_branch(save_action, models.user_branch(request.user) );
             result = "ok"
index b8795b7..29229dd 100644 (file)
--- 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)
         
             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'):
         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'), [])
 
     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)
 
     def _commit(self, message, user=None):
         return self.repo.commit(text=message, user=user)
index a418706..e958113 100644 (file)
@@ -114,7 +114,8 @@ INSTALLED_APPS = (
     'toolbar',
 )
 
     'toolbar',
 )
 
-REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books'
+
+# REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books'
 IMAGE_DIR = 'images'
 
 try:
 IMAGE_DIR = 'images'
 
 try:
index 3f5741c..040549e 100644 (file)
@@ -35,6 +35,7 @@ body {
     top: 2.4em; left: 0px; right: 0px; bottom: 0px;
     overflow: auto;    
     background-color: white;
     top: 2.4em; left: 0px; right: 0px; bottom: 0px;
     overflow: auto;    
     background-color: white;
+    padding: 0.2em 1em;
 }
 
 ul {
 }
 
 ul {
@@ -382,6 +383,37 @@ div.isection p {
 
 .msg-warning {
     background-color: yellow;
 
 .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
index 3b750ca..f9f0900 100644 (file)
@@ -51,6 +51,7 @@ Panel.prototype.load = function (url) {
                },
         error: function(request, textStatus, errorThrown) {
             $.log('ajax', url, this.target, 'error:', textStatus, errorThrown);
                },
         error: function(request, textStatus, errorThrown) {
             $.log('ajax', url, this.target, 'error:', textStatus, errorThrown);
+            $(self.contentDiv).html("<p>Wystapił błąd podczas wczytywania panelu.");
         }
     });
 }
         }
     });
 }
index bfbafe1..28c6b28 100644 (file)
@@ -1,9 +1,42 @@
 {% extends "base.html" %}
 
 {% block maincontent %}
 {% extends "base.html" %}
 
 {% block maincontent %}
-<ul>
-{% for blob in objects %}
-    <li><a href="{% url editor_view blob %}">{{ blob }}</a></li>
-{% endfor %}
-</ul>
+<h2>Dodaj nowy utwór</h2>
+
+{% if perms.explorer.can_add_files %}
+<form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
+    {{ bookform.as_p }}
+    <p><button type="submit">Dodaj książkę</button></p>
+</form>
+{% endif %}
+
+<h2>Wszystkie utwory:</h2>
+<table class="object-list" cellspacing="0">
+    <tr><th>Lp.</th><th>Nazwa utworu</th><th>Wersje</th></tr>
+    <tr><td colspan="3" class="page-navigation">
+        {% if files.has_previous %}
+        <span class="prev-page-marker">
+            <a href="?page={{ files.previous_page_number }}">Poprzednia</a>
+        </span>
+        {% endif %}
+
+        <span>Strona {{files.number}} z {{files.paginator.num_pages}}</span>
+
+        {% if files.has_next %}
+        <span class="next-page-marker">
+            <a href="?page={{ files.next_page_number }}">Następna</a>
+        </span>
+        {% endif %}
+    </td>
+    </tr>
+    {% for file in files.object_list %}
+    <tr>
+        <td>{{forloop.counter0|add:files.start_index}}.</td>
+        <td><a href="{% url editor_view file %}">{{ file }}</a></td>
+        <td> &nbsp; </td>
+    </tr>
+    {% endfor %}
+</table>
+
+
 {% endblock maincontent %}
 {% endblock maincontent %}
index 22627ac..551f2e0 100644 (file)
@@ -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/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<folder>[^/]+)/$', 'explorer.views.folder_images', name='folder_image'),
     url(r'^images/$', 'explorer.views.folder_images', {'folder': '.'}, name='folder_image_ajax'),
 
     url(r'^images/(?P<folder>[^/]+)/$', 'explorer.views.folder_images', name='folder_image'),
     url(r'^images/$', 'explorer.views.folder_images', {'folder': '.'}, name='folder_image_ajax'),