]> git.parisson.com Git - telemeta.git/commitdiff
fix collection for new item in a collection
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 17 Nov 2014 17:54:14 +0000 (18:54 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 17 Nov 2014 17:54:14 +0000 (18:54 +0100)
telemeta/templates/telemeta/collection_detail.html
telemeta/views/collection.py
telemeta/views/item.py

index e4dedacdfdfac8d73714da98d21481692550eca9..0a8442ce119b5ef7765d6bbb3e3900135bec1c92 100644 (file)
 </script>
 {% endblock %}
 
-{% if object %}
+{% if collection %}
 
 {% block title %}
     <img src="{{ STATIC_URL }}telemeta/images/collections_red.png" style="vertical-align:middle" />
-    Collection : {{ object.title }}
+    Collection : {{ collection.title }}
 {% endblock %}
 
 {% block title_buttons %}
index a39978a9881f3c3a7ec718c35016d9b20b7cae5a..78824fb35047157e7875340c363d85e3fc11a20b 100644 (file)
@@ -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):
index 9f678c5d045c30aa2e0f6bbdd3a62647a15a8904..d70e8d50cca899460507faec8b56be2ddf7514f8 100644 (file)
@@ -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')