From f43451705d1232a8ead2b44222f04e0e6bce43a7 Mon Sep 17 00:00:00 2001 From: yomguy Date: Tue, 15 Feb 2011 11:59:23 +0100 Subject: [PATCH] remove collection prev next, fix item prev next --- telemeta/urls.py | 8 +------- telemeta/web/base.py | 35 +++++++++++------------------------ 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/telemeta/urls.py b/telemeta/urls.py index 0afa28fb..0d9fb499 100644 --- a/telemeta/urls.py +++ b/telemeta/urls.py @@ -110,13 +110,7 @@ urlpatterns = patterns('', name="telemeta-collection-m3u"), url(r'^collections/(?P[A-Za-z0-9._-]+)/edit/$', web_view.collection_detail_edit, dict(template='telemeta/collection_detail_edit.html'), name="telemeta-collection-detail-edit"), - url(r'^collections/(?P[A-Za-z0-9._-]+)/previous/$', - web_view.collection_detail_previous, - name="telemeta-collection-detail-previous"), - url(r'^collections/(?P[A-Za-z0-9._-]+)/next/$', - web_view.collection_detail_next, - name="telemeta-collection-detail-next"), - + # search url(r'^search/$', web_view.search, name="telemeta-search"), url(r'^search/collections/$', web_view.search, {'type': 'collections'}, diff --git a/telemeta/web/base.py b/telemeta/web/base.py index 56adfd1f..20f2f526 100644 --- a/telemeta/web/base.py +++ b/telemeta/web/base.py @@ -126,22 +126,6 @@ class WebView(object): formset = MediaCollectionFormSet(queryset=MediaCollection.objects.filter(code=public_id)) return render(request, template, {'collection': collection, "formset": formset,}) - def collection_detail_previous(self, request, public_id): - collection = MediaCollection.objects.get(public_id=public_id) - while True: - previous = MediaCollection.objects.get(pk=collection.pk-1) - if previous: - break - return self.collection_detail(request, previous.public_id) - - def collection_detail_next(self, request, public_id): - collection = MediaCollection.objects.get(public_id=public_id) - while True: - next = MediaCollection.objects.get(pk=collection.pk+1) - if next: - break - return self.collection_detail(request, next.public_id) - def item_previous_next(self, item): # Get previous and next items pks = [] @@ -152,17 +136,20 @@ class WebView(object): for pk in pks: if pk == item.pk: if pk == pks[0]: - previous = pks[-1] - next = pks[1] + previous_pk = pks[-1] + next_pk = pks[1] elif pk == pks[-1]: - previous = pks[-2] - next = pks[0] + previous_pk = pks[-2] + next_pk = pks[0] else: - previous = pks[pks.index(pk)-1] - next = pks[pks.index(pk)+1] - previous = MediaItem.objects.get(pk=previous) + previous_pk = pks[pks.index(pk)-1] + next_pk = pks[pks.index(pk)+1] + for it in items: + if it.pk == previous_pk: + previous = it + if it.pk == next_pk: + next = it previous = previous.public_id - next = MediaItem.objects.get(pk=next) next = next.public_id return previous, next -- 2.39.5