From 7865b42cf4bfacb013b0230ac8d593983c4ec984 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Fri, 19 Sep 2014 03:34:35 +0200 Subject: [PATCH] CBV for collection edit and detail, rm collection player --- telemeta/forms/media.py | 10 +++ .../templates/telemeta/collection_detail.html | 13 ---- .../templates/telemeta/collection_edit.html | 77 ++++++++++++------- .../templates/telemeta/collection_list.html | 7 +- .../telemeta/inc/collection_list.html | 4 +- .../telemeta/inc/mediaitem_list.html | 4 +- .../templates/telemeta/mediaitem_list.html | 2 + telemeta/urls.py | 9 +-- telemeta/views/collection.py | 53 ++++++++----- telemeta/views/resource.py | 22 +----- 10 files changed, 108 insertions(+), 93 deletions(-) diff --git a/telemeta/forms/media.py b/telemeta/forms/media.py index 07115957..7fb4ba0a 100644 --- a/telemeta/forms/media.py +++ b/telemeta/forms/media.py @@ -150,3 +150,13 @@ class CorpusRelatedInline(InlineFormSet): model = MediaCorpusRelated + +class CollectionRelatedInline(InlineFormSet): + + model = MediaCollectionRelated + + +class ItemRelatedInline(InlineFormSet): + + model = MediaItemRelated + diff --git a/telemeta/templates/telemeta/collection_detail.html b/telemeta/templates/telemeta/collection_detail.html index e6de75da..0f9b3726 100644 --- a/telemeta/templates/telemeta/collection_detail.html +++ b/telemeta/templates/telemeta/collection_detail.html @@ -64,19 +64,6 @@ (M3U, XSPF) - -

- Get Flash to see this player. -

- {% endif %} diff --git a/telemeta/templates/telemeta/collection_edit.html b/telemeta/templates/telemeta/collection_edit.html index a03ebbab..147e4960 100644 --- a/telemeta/templates/telemeta/collection_edit.html +++ b/telemeta/templates/telemeta/collection_edit.html @@ -1,43 +1,62 @@ {% extends "telemeta/collection_detail.html" %} {% load i18n %} {% load telemeta_utils %} +{% load bootstrap3 %} {% block title %} Collection : {{ collection }} {% endblock %} + {% block title_buttons %} - {% trans "Cancel" %} - {% trans "Save" %} + {% trans "Cancel" %} {% endblock %} {% block infos %} -
-
{% csrf_token %} - - - {% for field in form %} - - {% if field.html_name == "copied_from_item" %} - - {% else %} - - - {% endif %} - - {% endfor %} - - - - -
{% for error in form.non_field_errors %}
  • {{ error }}
  • {% endfor %}
    {{ field.label_tag.as_hidden }}{{ field.as_hidden }}
    {{ field.errors }}
    {{ field.label_tag }}: {{ field }}
    {% trans "Related media" %}:{% trans "Edit"%} {% trans "related media"%}
    -
    - {% trans "Cancel" %} - {% trans "Save" %} -
    -
    -
    + +
    +
    {% csrf_token %} + + + +
    + +
    + + + + + {{ form.media }} + {% bootstrap_form form %} +
    + + + +
    + + +
    + {% trans "Cancel" %} + {% if perms.telemeta.change_mediacollection %} + + {% endif %} + {# {% trans "Save" %} #} +
    + +
    +
    + {% endblock infos%} {% block delete %} diff --git a/telemeta/templates/telemeta/collection_list.html b/telemeta/templates/telemeta/collection_list.html index 79d7cab6..a50e1689 100644 --- a/telemeta/templates/telemeta/collection_list.html +++ b/telemeta/templates/telemeta/collection_list.html @@ -32,13 +32,14 @@ - {% if user.is_authenticated and perms.telemeta.add_mediacollection %} + {% if user.is_authenticated and perms.telemeta.add_mediacollection %} {% trans "Add" %} - {% endif %} + {% endif %} {% endblock %} {% block content %}
    +{% with object_list as collections %} {% include "telemeta/inc/collection_list.html" %} -
    +{% endwith %} {% endblock %} diff --git a/telemeta/templates/telemeta/inc/collection_list.html b/telemeta/templates/telemeta/inc/collection_list.html index 64c11409..d215e818 100644 --- a/telemeta/templates/telemeta/inc/collection_list.html +++ b/telemeta/templates/telemeta/inc/collection_list.html @@ -1,7 +1,7 @@ {% load telemeta_utils %} {% load i18n %} -{% if object_list %} +{% if collections %} @@ -12,7 +12,7 @@ -{% for collection in object_list %} +{% for collection in collections %}
    {% trans "Recording period" %} {% trans "Sound" %}
    {{ collection.title }} diff --git a/telemeta/templates/telemeta/inc/mediaitem_list.html b/telemeta/templates/telemeta/inc/mediaitem_list.html index 041f86e1..bcd53d3c 100644 --- a/telemeta/templates/telemeta/inc/mediaitem_list.html +++ b/telemeta/templates/telemeta/inc/mediaitem_list.html @@ -1,7 +1,7 @@ {% load telemeta_utils %} {% load i18n %} -{% if object_list %} +{% if items %} @@ -16,7 +16,7 @@ -{% for item in object_list %} +{% for item in items %}
    {% trans "Year of recording" %} {% trans "Sound" %}
    {{ item }} diff --git a/telemeta/templates/telemeta/mediaitem_list.html b/telemeta/templates/telemeta/mediaitem_list.html index 014deda5..df1a3d81 100644 --- a/telemeta/templates/telemeta/mediaitem_list.html +++ b/telemeta/templates/telemeta/mediaitem_list.html @@ -37,7 +37,9 @@ {% endblock %} {% block content %} +{% with object_list as items %}
    {% include "telemeta/inc/mediaitem_list.html" %}
    +{% endwith %} {% endblock %} diff --git a/telemeta/urls.py b/telemeta/urls.py index b67b9343..728005bf 100644 --- a/telemeta/urls.py +++ b/telemeta/urls.py @@ -127,8 +127,7 @@ urlpatterns = patterns('', url(r'^archives/collections_published/$', CollectionPublishedListView.as_view(), name="telemeta-collections-published"), url(r'^archives/collections_sound/$', CollectionSoundListView.as_view(), name="telemeta-collections-sound"), - url(r'^archives/collections/(?P[A-Za-z0-9._-]+)/$', collection_view.collection_detail, - dict(template="telemeta/collection_detail.html"), name="telemeta-collection-detail"), + url(r'^archives/collections/(?P[A-Za-z0-9._-]+)/$', CollectionDetailView.as_view(), name="telemeta-collection-detail"), url(r'^archives/collections/(?P[A-Za-z0-9._-]+)/dc/$', collection_view.collection_detail, dict(template="telemeta/collection_detail_dc.html"), name="telemeta-collection-dublincore"), url(r'^archives/collections/(?P[A-Za-z0-9._-]+)/collection_xspf.xml$', @@ -139,8 +138,7 @@ urlpatterns = patterns('', collection_view.collection_playlist, dict(template="telemeta/collection.m3u", mimetype="audio/mpegurl"), name="telemeta-collection-m3u"), - url(r'^archives/collections/(?P[A-Za-z0-9._-]+)/edit/$', collection_view.collection_edit, - dict(template='telemeta/collection_edit.html'), name="telemeta-collection-edit"), + url(r'^archives/collections/(?P[A-Za-z0-9._-]+)/edit/$', CollectionEditView.as_view(), name="telemeta-collection-edit"), url(r'^archives/collections/(?P[A-Za-z0-9._-]+)/copy/$', collection_view.collection_copy, dict(template='telemeta/collection_edit.html'), name="telemeta-collection-copy"), url(r'^archives/collection_new/add/$', collection_view.collection_add, @@ -159,9 +157,8 @@ urlpatterns = patterns('', # Generic resources url(r'^archives/(?P[A-Za-z0-9._-]+)/$', ResourceListView.as_view(), name="telemeta-resource-list"), url(r'^archives/(?P[A-Za-z0-9._-]+)/(?P[A-Za-z0-9._-]+)/$', ResourceDetailView.as_view(), name="telemeta-resource-detail"), - url(r'^archives/(?P[A-Za-z0-9._-]+)/(?P[A-Za-z0-9._-]+)/edit2/$', ResourceFormSetView.as_view(), name="telemeta-resource-detail2"), - url(r'^archives/(?P[A-Za-z0-9._-]+)/(?P[A-Za-z0-9._-]+)/dc/$', ResourceDetailDCView.as_view(), name="telemeta-resource-dublincore"), url(r'^archives/(?P[A-Za-z0-9._-]+)/(?P[A-Za-z0-9._-]+)/edit/$', ResourceEditView.as_view(), name="telemeta-resource-edit"), + url(r'^archives/(?P[A-Za-z0-9._-]+)/(?P[A-Za-z0-9._-]+)/dc/$', ResourceDetailDCView.as_view(), name="telemeta-resource-dublincore"), url(r'^archives/(?P[A-Za-z0-9._-]+)/(?P[A-Za-z0-9._-]+)/copy/$', ResourceCopyView.as_view(), name="telemeta-resource-copy"), url(r'^archives/(?P[A-Za-z0-9._-]+)_add$', ResourceAddView.as_view(), name="telemeta-resource-add"), url(r'^archives/(?P[A-Za-z0-9._-]+)/(?P[A-Za-z0-9._-]+)/delete/$', ResourceDeleteView.as_view(), name="telemeta-resource-delete"), diff --git a/telemeta/views/collection.py b/telemeta/views/collection.py index 74cdf88d..3d35cfc6 100644 --- a/telemeta/views/collection.py +++ b/telemeta/views/collection.py @@ -52,7 +52,7 @@ class CollectionView(object): messages.error(request, title) return render(request, 'telemeta/messages.html', {'description' : description}) - playlists = get_playlists(request) + playlists = get_playlists_names(request) related_media = MediaCollectionRelated.objects.filter(collection=collection) check_related_media(related_media) @@ -225,6 +225,15 @@ class CollectionPackageView(View): return super(CollectionPackageView, self).dispatch(*args, **kwargs) +class CollectionViewMixin(object): + + model = MediaCollection + + def get_object(self): + self.pk = self.model.objects.get(code=self.kwargs['public_id']).pk + return get_object_or_404(self.model, pk=self.pk) + + class CollectionListView(ListView): model = MediaCollection @@ -253,40 +262,48 @@ class CollectionSoundListView(CollectionListView): queryset = MediaCollection.objects.sound().order_by('code', 'old_code') -class CollectionViewMixin(object): - - model = MediaCollection - type = 'collection' - - class CollectionDetailView(CollectionViewMixin, DetailView): - - def get_object(self): - return self.model.objects.get(code=self.kwargs['public_id']) + template_name = 'telemeta/collection_detail.html' def get_context_data(self, **kwargs): context = super(CollectionDetailView, self).get_context_data(**kwargs) collection = self.get_object() items = collection.items.enriched() - items = items.order_by('code', 'old_code') + context['collection'] = collection + context['items'] = items.order_by('code', 'old_code') if collection.public_access == 'none' and not (request.user.is_staff or request.user.is_superuser): mess = ugettext('Access not allowed') title = ugettext('Collection') + ' : ' + public_id + ' : ' + mess description = ugettext('Please login or contact the website administator to get a private access.') messages.error(request, title) - return render(request, 'telemeta/messages.html', {'description' : description}) + return render(self.request, 'telemeta/messages.html', {'description' : description}) - playlists = get_playlists(self.request) - related_media = MediaCollectionRelated.objects.filter(collection=collection) - check_related_media(related_media) - parents = MediaCorpus.objects.filter(children=collection) + context['playlists'] = get_playlists_names(self.request) + context['related_media'] = MediaCollectionRelated.objects.filter(collection=collection) + check_related_media(context['related_media']) + context['parents'] = MediaCorpus.objects.filter(children=collection) revisions = Revision.objects.filter(element_type='collection', element_id=collection.id).order_by('-time') if revisions: - last_revision = revisions[0] + context['last_revision'] = revisions[0] else: - last_revision = None + context['last_revision'] = None return context + + +class CollectionEditView(CollectionViewMixin, UpdateWithInlinesView): + + template_name = 'telemeta/collection_edit.html' + inlines = [CollectionRelatedInline, ] + + def form_valid(self, form): + messages.info(self.request, _("You have successfully updated your collection.")) + return super(CollectionEditView, self).form_valid(form) + + def get_success_url(self): + return reverse_lazy('telemeta-collection-detail', kwargs={'public_id':self.kwargs['public_id']}) + + diff --git a/telemeta/views/resource.py b/telemeta/views/resource.py index cd36723d..b342f42b 100644 --- a/telemeta/views/resource.py +++ b/telemeta/views/resource.py @@ -293,23 +293,6 @@ class ResourceDetailDCView(ResourceDetailView): template_name = "telemeta/resource_detail_dc.html" -class ResourceEditView(ResourceSingleMixin, UpdateView): - - template_name = 'telemeta/resource_edit.html' - - def get_form_class(self): - self.type = self.kwargs['type'] - self.setup(self.type) - return self.form - - def form_valid(self, form): - messages.info(self.request, _("You have successfully updated your resource.")) - return super(ResourceEditView, self).form_valid(form) - - def get_success_url(self): - return reverse_lazy('telemeta-resource-detail', kwargs={'type':self.kwargs['type'], 'public_id':self.kwargs['public_id']}) - - class ResourceAddView(ResourceMixin, CreateView): template_name = 'telemeta/resource_add.html' @@ -344,10 +327,9 @@ class ResourceDeleteView(ResourceSingleMixin, DeleteView): return reverse_lazy('telemeta-resource-list', kwargs={'type':self.kwargs['type']}) +class ResourceEditView(ResourceSingleMixin, UpdateWithInlinesView): -class ResourceFormSetView(ResourceSingleMixin, UpdateWithInlinesView): - - template_name = 'telemeta/resource_edit2.html' + template_name = 'telemeta/resource_edit.html' def get_success_url(self): return reverse_lazy('telemeta-resource-detail', kwargs={'type':self.kwargs['type'], 'public_id':self.kwargs['public_id']}) -- 2.39.5