From: Łukasz Rekucki Date: Fri, 4 Sep 2009 20:43:27 +0000 (+0200) Subject: Dodano wyszukiwarke na stronie glownej. Refs #75. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/f62465929c480c1c05310df665fae32b5a24fb98?page=%7B%7B%20files.previous_page_number%20%7D%7D Dodano wyszukiwarke na stronie glownej. Refs #75. --- diff --git a/apps/explorer/views.py b/apps/explorer/views.py index 7d186887..d6118acb 100644 --- a/apps/explorer/views.py +++ b/apps/explorer/views.py @@ -5,7 +5,7 @@ from librarian import html, parser, dcparser, ParseError, ValidationError 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 @@ -40,21 +40,12 @@ def ajax_login_required(view): # @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') @@ -186,7 +177,7 @@ def file_dc(request, path, repo): @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') @@ -199,7 +190,7 @@ def display_editor(request, path, repo): 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={ @@ -215,7 +206,6 @@ def display_editor(request, path, repo): @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={ diff --git a/lib/hg.py b/lib/hg.py index 18a8d18a..07ec9a79 100644 --- a/lib/hg.py +++ b/lib/hg.py @@ -1,7 +1,6 @@ # -*- 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' diff --git a/project/static/css/filelist.css b/project/static/css/filelist.css new file mode 100755 index 00000000..f5b8ce0c --- /dev/null +++ b/project/static/css/filelist.css @@ -0,0 +1,33 @@ +/* + 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%; +} + + + + + diff --git a/project/static/js/editor.js b/project/static/js/editor.js index e615b790..879762cd 100644 --- a/project/static/js/editor.js +++ b/project/static/js/editor.js @@ -151,10 +151,10 @@ Panel.prototype.connectToolbar = function() 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 diff --git a/project/static/js/jquery.hpanel.js b/project/static/js/jquery.hpanel.js index bec82e06..1ad0d17f 100644 --- a/project/static/js/jquery.hpanel.js +++ b/project/static/js/jquery.hpanel.js @@ -11,7 +11,7 @@ $('.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}); diff --git a/project/static/js/jquery.lazyload.js b/project/static/js/jquery.lazyload.js old mode 100644 new mode 100755 diff --git a/project/static/js/jquery.paginate.js b/project/static/js/jquery.paginate.js new file mode 100644 index 00000000..710b1846 --- /dev/null +++ b/project/static/js/jquery.paginate.js @@ -0,0 +1,66 @@ +(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 = $(''); + 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.bind('click', i, function(event) { list.switchToPage(event.data); }); + nav.append(button); + } + + if(orphanCount > 0) + { + i = pageCount; + button = $(""); + button.bind('click', i, function(event) { list.switchToPage(event.data); }); + nav.append(button); + } + + list.filterItems(function(){return true;}); + list.switchToPage(0); + }; +})(jQuery); diff --git a/project/templates/explorer/file_list.html b/project/templates/explorer/file_list.html index 25136371..a36d353a 100644 --- a/project/templates/explorer/file_list.html +++ b/project/templates/explorer/file_list.html @@ -1,43 +1,58 @@ {% extends "base.html" %} +{% block extrahead %} + + + +{% endblock extrahead %} + {% block maincontent %} +
+ +
+
+

+ + +

+
+
+ {% for file in files %} +

{{ file }}

+ {% endfor %} +
+
{% if perms.explorer.can_add_files %} +

Dodaj nowy utwór

-
{{ 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 %}