.DS_Store
media
files
+nbproject
+nbproject/*
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)
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
#
# 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
#
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"
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'):
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)
'toolbar',
)
-REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books'
+
+# REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books'
IMAGE_DIR = 'images'
try:
top: 2.4em; left: 0px; right: 0px; bottom: 0px;
overflow: auto;
background-color: white;
+ padding: 0.2em 1em;
}
ul {
.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
},
error: function(request, textStatus, errorThrown) {
$.log('ajax', url, this.target, 'error:', textStatus, errorThrown);
+ $(self.contentDiv).html("<p>Wystapił błąd podczas wczytywania panelu.");
}
});
}
{% 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> </td>
+ </tr>
+ {% endfor %}
+</table>
+
+
{% endblock maincontent %}
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'),