from django.conf import settings
from django.contrib.auth.decorators import login_required, permission_required
-from django.core.paginator import Paginator, InvalidPage, EmptyPage
+
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.utils import simplejson as json
#
@with_repo
def file_list(request, repo):
- paginator = Paginator( repo.file_list('default'), 100);
+ latest_default = repo.repo.branchtags()['default']
+ files = list( repo.repo[latest_default] )
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={
- 'files': files, 'page': page, 'bookform': bookform,
+ 'files': files, 'bookform': bookform,
})
@permission_required('explorer.can_add_files')
@login_required
@with_repo
def display_editor(request, path, repo):
- path = unicode(path).encode("utf-8")
+
if not repo.file_exists(path, models.user_branch(request.user)):
try:
data = repo.get_file(path, 'default')
repo.in_branch(new_file, models.user_branch(request.user) )
except hg.RepositoryException, e:
- return direct_to_templace(request, 'explorer/file_unavailble.html',\
+ return direct_to_template(request, 'explorer/file_unavailble.html',\
extra_context = { 'path': path, 'error': e })
return direct_to_template(request, 'explorer/editor.html', extra_context={
@ajax_login_required
@with_repo
def xmleditor_panel(request, path, repo):
- form = forms.BookForm()
text = repo.get_file(path, models.user_branch(request.user))
return direct_to_template(request, 'explorer/panels/xmleditor.html', extra_context={
# -*- coding: utf-8 -*-
import os
-import codecs
-from mercurial import localrepo, ui, match, node, encoding, util
+from mercurial import localrepo, ui, encoding, util
import mercurial.merge, mercurial.error
encoding.encoding = 'utf-8'
--- /dev/null
+/*
+ Document : filelist
+ Created on : 2009-09-04, 20:44:44
+ Author : lreqc
+ Description:
+ Dodatkowe style dla listy plików na stronie głównej.
+*/
+
+#main-page-widgets > div {
+ float: left;
+ border: 1px solid black;
+ padding: 0.5em 2em;
+ margin: 1em;
+}
+
+.file-list-widget {
+ background: #DDF;
+ max-width: 60%;
+}
+
+.file-list-widget .page-nav-wrap button {
+ width: 2.5em;
+}
+
+.upload-file-widget {
+ min-width: 20%;
+ width: 25%;
+}
+
+
+
+
+
action_buttons.each(function() {
var button = $(this);
var hk = button.attr('ui:hotkey');
+ var params = $.evalJSON(button.attr('ui:action-params'));
var callback = function() {
- editor.callScriptlet(button.attr('ui:action'),
- self, eval(button.attr('ui:action-params')) );
+ editor.callScriptlet(button.attr('ui:action'), self, params);
};
// connect button
$('.panel-overlay', mydata.root).css('display', 'block');
return false;
},
- resize_changed: function(event) {
+ resize_changed: function(event) {
var old_width = parseInt(event.data.overlay.css('width'));
var delta = event.pageX + event.data.hotspot_x - old_width;
event.data.overlay.css({'width': old_width + delta});
--- /dev/null
+(function($) {
+
+ var settings = {
+ items: [],
+ itemsPerPage: 20,
+ page: 0
+ };
+
+ $.fn.filterItems = function(condition)
+ {
+ settings.items = $('p', this);
+
+ if(condition) settings.items = settings.items.filter(function() {
+ return condition( $(this).attr('title') );
+ });
+
+ var pageCount = Math.ceil(settings.items.length / settings.itemsPerPage);
+ var buttons = $('.page-nav-wrap button', this.parent());
+ buttons.show().filter(function(i) { return i >= pageCount; }).hide();
+ this.switchToPage();
+ };
+
+ $.fn.switchToPage = function(index)
+ {
+ index = index || settings.page;
+ var start = index * settings.itemsPerPage;
+ var end = start + settings.itemsPerPage;
+ $('p', this).hide();
+
+ var visibleItems = settings.items.filter(function(i) { return i >= start && i < end; });
+ visibleItems.show();
+ }
+
+ $.fn.paginate = function(options)
+ {
+ var list = this;
+
+ // apply defaults
+ if (options) $.extend(settings, options);
+ settings.items = $('p', list);
+
+ var nav = $('<p class="page-nav-wrap"></p>');
+ list.before(nav);
+ var pageCount = Math.floor(settings.items.length / settings.itemsPerPage);
+ var orphanCount = settings.items.length - (pageCount * settings.itemsPerPage);
+ var button = null;
+
+ for(var i=0; i < pageCount; i++)
+ {
+ button = $("<button type='button'>"+(i+1)+"</button>");
+ button.bind('click', i, function(event) { list.switchToPage(event.data); });
+ nav.append(button);
+ }
+
+ if(orphanCount > 0)
+ {
+ i = pageCount;
+ button = $("<button type='button'>"+(i+1)+"</button>");
+ button.bind('click', i, function(event) { list.switchToPage(event.data); });
+ nav.append(button);
+ }
+
+ list.filterItems(function(){return true;});
+ list.switchToPage(0);
+ };
+})(jQuery);
{% extends "base.html" %}
+{% block extrahead %}
+<link rel="stylesheet" href="{{ STATIC_URL }}css/filelist.css" type="text/css" />
+<script type="text/javascript" charset="utf-8" src="{{ STATIC_URL }}js/jquery.paginate.js"></script>
+<script type="text/javascript" charset="utf-8">
+$(function() {
+ $('#file-list').paginate({itemsPerPage: 15});
+
+ $('#file-list-find-button').click(function(event)
+ {
+ var expr = new RegExp( $('#file-list-filter').val() );
+
+ $('#file-list').filterItems( function(filename) {
+ return expr.test(filename);
+ });
+
+ event.preventDefault();
+ });
+
+ $('#file-list-reset-button').click(function(event)
+ {
+ $('#file-list').filterItems();
+ event.preventDefault();
+ });
+});
+</script>
+{% endblock extrahead %}
+
{% block maincontent %}
+<div id="main-page-widgets">
+
+<div class="file-list-widget">
+ <form action="#" method="GET">
+ <p><input name="filter" id="file-list-filter" type="text" size="60" />
+ <input type="submit" value="Znajdź" id="file-list-find-button"/>
+ <input type="reset" value="Wyczyść" id="file-list-reset-button"/>
+ </p>
+ </form>
+ <div id="file-list">
+ {% for file in files %}
+ <p title="{{file}}"><a href="{% url editor_view file %}">{{ file }}</a></p>
+ {% endfor %}
+ </div>
+</div>
{% if perms.explorer.can_add_files %}
+<div class="upload-file-widget">
<h2>Dodaj nowy utwór</h2>
-
<form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
{{ bookform.as_p }}
<p><button type="submit">Dodaj książkę</button></p>
</form>
+</div>
{% 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>
-
-
+</div>
{% endblock maincontent %}