From: Guillaume Pellerin Date: Mon, 17 Nov 2014 17:54:14 +0000 (+0100) Subject: fix collection for new item in a collection X-Git-Tag: 1.5.0rc1~27^2~4^2~13 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=1c85bf5c6e62875dea5337f7b67a74286a18f26d;p=telemeta.git fix collection for new item in a collection --- diff --git a/telemeta/templates/telemeta/collection_detail.html b/telemeta/templates/telemeta/collection_detail.html index e4dedacd..0a8442ce 100644 --- a/telemeta/templates/telemeta/collection_detail.html +++ b/telemeta/templates/telemeta/collection_detail.html @@ -30,11 +30,11 @@ {% endblock %} -{% if object %} +{% if collection %} {% block title %} - Collection : {{ object.title }} + Collection : {{ collection.title }} {% endblock %} {% block title_buttons %} diff --git a/telemeta/views/collection.py b/telemeta/views/collection.py index a39978a9..78824fb3 100644 --- a/telemeta/views/collection.py +++ b/telemeta/views/collection.py @@ -37,6 +37,7 @@ from telemeta.views.core import * + class CollectionView(object): """Provide Collections web UI methods""" @@ -239,8 +240,7 @@ class CollectionViewMixin(object): pass else: obj = obj[0] - self.pk = obj.pk - return get_object_or_404(self.model, pk=self.pk) + return obj class CollectionListView(ListView): diff --git a/telemeta/views/item.py b/telemeta/views/item.py index 9f678c5d..d70e8d50 100644 --- a/telemeta/views/item.py +++ b/telemeta/views/item.py @@ -755,6 +755,17 @@ class ItemAddView(ItemViewMixin, CreateWithInlinesView): form_class = MediaItemForm template_name = 'telemeta/mediaitem_add.html' + def get_initial(self): + obj = MediaItem() + # new item for a specific collection + if 'public_id' in self.kwargs: + public_id = self.kwargs['public_id'] + collections = MediaCollection.objects.filter(code=public_id) + if collections: + collection = collections[0] + obj.collection = collection + return model_to_dict(obj) + def get_success_url(self): return reverse_lazy('telemeta-items')