Merge
authorAnthony Ly <anthonyly.com@gmail.com>
Thu, 27 Jun 2013 15:27:01 +0200
changeset 173 480ab94bf0fe
parent 172 8c3517f6f21e (current diff)
parent 171 1a1f3958c551 (diff)
child 174 6d37a4bd893a
child 176 96d470b37c65
Merge
integration/v2/css/style.css
--- a/integration/v2/css/style.css	Thu Jun 27 15:26:35 2013 +0200
+++ b/integration/v2/css/style.css	Thu Jun 27 15:27:01 2013 +0200
@@ -122,7 +122,7 @@
 .list-projets-3 li img{max-width: 465px; display: block; margin: 0 auto;}
 .list-projets-3 li.horizontal .col-left{ width: 225px;}
 .list-projets-3 li.horizontal .col-right{height:100%; width: 240px; }
-.list-projets-3 .project-title{position:relative; padding-left: 14px; font-size: 18px;height: 60px; border-bottom: 1px solid #CCC;}
+.list-projets-3 .project-title{position:relative; padding-left: 14px; font-size: 18px;min-height: 60px; border-bottom: 1px solid #CCC;}
 .project-title h3{ font-family: 'Lato'; font-weight : bold; padding-top: 12px; margin-bottom: 4px; }
 .project-title h4{ font-family: 'Lato';  font-weight: 300; font-style: italic;}
 .project-title a.edit{ position: absolute; top: 10px; right: 10px; opacity: 0.7;}
--- a/src/egonomy/migrations/0003_add_collection_and_items.py	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/migrations/0003_add_collection_and_items.py	Thu Jun 27 15:27:01 2013 +0200
@@ -25,7 +25,7 @@
         db.create_table(u'egonomy_collectionitem', (
             (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
             ('content_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'])),
-            ('object_id', self.gf('django.db.models.fields.PositiveIntegerField')()),
+            ('object_id', self.gf('django.db.models.fields.CharField')(max_length=15)),
             ('description', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
             ('order', self.gf('django.db.models.fields.IntegerField')()),
             ('collection', self.gf('django.db.models.fields.related.ForeignKey')(related_name='items', to=orm['egonomy.Collection'])),
@@ -95,7 +95,7 @@
             'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
             'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
             u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'object_id': ('django.db.models.fields.CharField', [], {'max_length': '15'}),
             'order': ('django.db.models.fields.IntegerField', [], {})
         },
         u'egonomy.fragment': {
--- a/src/egonomy/models.py	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/models.py	Thu Jun 27 15:27:01 2013 +0200
@@ -196,7 +196,7 @@
 class CollectionItem(models.Model):
     
     content_type = models.ForeignKey(ContentType) # can be image ou fragment
-    object_id = models.PositiveIntegerField()
+    object_id = models.CharField(null=False, blank=False, max_length=15) # has to be char because of image id
     content_object = generic.GenericForeignKey('content_type', 'object_id')
     description = models.TextField(blank=True, null=True)
     order = models.IntegerField()
--- a/src/egonomy/static/egonomy/css/style.css	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/static/egonomy/css/style.css	Thu Jun 27 15:27:01 2013 +0200
@@ -106,7 +106,7 @@
 .list-projets-2 .bot p{color: #333; background-color: #fff; font-family: 'Lato';  font-weight: 300; font-style: italic; padding: 8px 14px 0 14px; font-size: 14px; height: 104px; border-bottom: 1px solid #000; border-left: 1px solid #BBB; border-right: 1px solid #BBB;}
 .list-projets-2 .bot{height: 113px;  overflow: hidden;}
 
-li .toggle{display: block;}
+li .toggle{display: none;}
 li:hover .toggle{ display:block; }
 
 .tools{  text-align:right; width:100%; position:absolute; bottom:0; left:0;  background: rgba(255, 255, 255, .85);}
@@ -119,10 +119,10 @@
 .list-projets-3{margin-bottom: 50px;}
 .list-projets-3>li{width: 465px; background-color: #eee; margin-bottom: 20px;}
 .list-projets-3 .col-left{position: relative;}
-.list-projets-3 li img{max-width: 465px; display: inherit;}
+.list-projets-3 li img{max-width: 465px; display: block; margin: 0 auto;}
 .list-projets-3 li.horizontal .col-left{ width: 225px;}
 .list-projets-3 li.horizontal .col-right{height:100%; width: 240px; }
-.list-projets-3 .project-title{position:relative; padding-left: 14px; font-size: 18px;height: 60px; border-bottom: 1px solid #CCC;}
+.list-projets-3 .project-title{position:relative; padding-left: 14px; font-size: 18px;min-height: 60px; border-bottom: 1px solid #CCC;}
 .project-title h3{ font-family: 'Lato'; font-weight : bold; padding-top: 12px; margin-bottom: 4px; }
 .project-title h4{ font-family: 'Lato';  font-weight: 300; font-style: italic;}
 .project-title a.edit{ position: absolute; top: 10px; right: 10px; opacity: 0.7;}
@@ -153,7 +153,7 @@
 .tool.cut{background-position: -86px 0;}
 .tool.save{background-position: -144px 0;}
 .tool.trash{background-position: -117px 0;}
-
+.tool.edit{background-position:-174px 0;}
 
 .box-shadow{ -webkit-box-shadow: 1px 1px 5px rgba(50, 50, 50, 0.75);-moz-box-shadow: 1px 1px 5px rgba(50, 50, 50, 0.75);box-shadow: 1px 1px 5px rgba(50, 50, 50, 0.75);}
 .box-shadow-2{ -webkit-box-shadow: 1px 1px 2px rgba(50, 50, 50, 0.75);-moz-box-shadow: 1px 1px 2px rgba(50, 50, 50, 0.75);box-shadow: 1px 1px 2px rgba(50, 50, 50, 0.75);}
@@ -262,7 +262,7 @@
 .content-project p{font-family: 'Lato'; font-size: 13px; font-weight: 300; line-height: 15px; padding: 10px;}
 
 body{overflow: auto !important;}
-#map{width: 100%; height: 400px;}
+#map{width: 100%; height: 360px; margin-bottom: 20px;}
 
 
 /* imported */
Binary file src/egonomy/static/egonomy/img/icon-pencil-15.png has changed
Binary file src/egonomy/static/egonomy/img/tools-sprite.png has changed
--- a/src/egonomy/static/egonomy/js/main.js	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/static/egonomy/js/main.js	Thu Jun 27 15:27:01 2013 +0200
@@ -81,7 +81,7 @@
 			iconAction = li.find('.icon-action'),
 			index = li.index(),
 			keyword = $(this).attr('data-keyword');
-		enabledDisplayKeyword(li, keyword, iconAction);
+		
 
 		ul.find('li').each(function(k, v){
 			if(index != k){
@@ -91,12 +91,15 @@
 				disabledDisplayKeyword($(v), keyword, iconAction);
 			}
 		});
+
+		enabledDisplayKeyword(li, keyword, iconAction);
 	});
 	$('.icon-action').bind('click', function(e){
 		e.preventDefault();
 		var li = $(this).parents('li');
 		toggleDisplayKeyword(li);
 	});
+/*
 	function toggleDisplayKeyword(li){
 		var displayKeyword = li.find('.display-keyword'),
 			iconAction = li.find('.icon-action'),
@@ -119,5 +122,83 @@
 		$('li.keyword-'+keyword).find('.curtain').show();
 		iconAction.addClass('circle');
 	}
+*/
+	function toggleDisplayKeyword(li){
+		var displayKeyword = li.find('.display-keyword'),
+			iconAction = li.find('.icon-action'),
+			keyword = displayKeyword.attr('data-keyword');
+		if(li.hasClass('disabled')){
+			enabledDisplayKeyword(li, keyword, iconAction);
+		}else{
+			disabledDisplayKeyword(li, keyword, iconAction);
+		}
+	}
+	function enabledDisplayKeyword(li, keyword, iconAction){
+		iconAction.removeClass('cross').removeClass('circle');
+		li.removeClass('disabled');
+		$('ul.mosaic > li').each(function(k, v){
+
+			var keywords = $(v).attr('data-keywords'),
+				item = $(v);
+			keywords = keywords.split(',');
+			for(var i=0; i<= keywords.length; i++){
+				if($.trim(keywords[i]) == keyword){
+					item.find('.curtain').hide();
+				}
+			}
+		});
+		$('li.keyword-'+keyword).find('.curtain').hide();
+		iconAction.addClass('cross');
+	}
+	function disabledDisplayKeyword(li, keyword, iconAction){
+		iconAction.removeClass('cross').removeClass('circle');
+		li.addClass('disabled');
+		$('ul.mosaic > li').each(function(k, v){
+
+			var keywords = $(v).attr('data-keywords'),
+				item = $(v);
+			keywords = keywords.split(',');
+			for(var i=0; i<= keywords.length; i++){
+				if($.trim(keywords[i]) == keyword){
+					item.find('.curtain').show();
+				}
+			}
+		});
+		iconAction.addClass('circle');
+	}
+
 	
-});//ready
+	// add item to collection behaviour
+	$('.additemtocollection').bind('click', function(e){
+		// When an item meant to be added to a collection is clicked,
+		// we fill the form in the add-to-collection div
+		console.log(this + ", " + $(this) + ", " + $(this).attr('data-type') + ", " + $(this).attr('data-id'));
+		$('#add-to-collection .item-type').val($(this).attr('data-type'));
+		$('#add-to-collection .item-id').val($(this).attr('data-id'));
+	});
+	
+	
+	//map
+	if($('#map').length){
+		initmap()
+	}
+function initmap() {
+	// set up the map
+	map = new L.Map('map');
+
+	// create the tile layer with correct attribution
+	var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
+	var osm = new L.TileLayer(osmUrl, {minZoom: 3, maxZoom: 20});		
+
+	// start the map in South-East England
+	map.setView(new L.LatLng(48.833, 2.333),4);
+	map.addLayer(osm);
+
+	// markers
+	var marker1 = L.marker([48.833, 2.333]).addTo(map);
+	marker1.bindPopup("Beaux-Arts de Paris");
+	var marker2 = L.marker([47.233,-1.583]).addTo(map);
+	marker2.bindPopup("Beaux-Arts de Nantes");
+}
+
+});//ready
\ No newline at end of file
--- a/src/egonomy/templates/egonomy_all_collections.html	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/templates/egonomy_all_collections.html	Thu Jun 27 15:27:01 2013 +0200
@@ -15,7 +15,6 @@
 {% endblock %}
 
 {% block popins %}
-    <div class="popin-wrap">
         <div id="new-collection" class="popin popin-new-collection box-shadow">
             <header>
                 <h2>{% trans "New collection" %}</h2>
@@ -38,7 +37,6 @@
                 </form>
             </section>
         </div>
-    </div>
 {% endblock %}
 
 {% block content %}
--- a/src/egonomy/templates/egonomy_annotate_picture.html	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/templates/egonomy_annotate_picture.html	Thu Jun 27 15:27:01 2013 +0200
@@ -20,7 +20,7 @@
                     </li>
                     <li>
                       {% if user.is_authenticated %}
-                        <a class="icon plus open-popin" href="#add-to-collection">{% trans "Add to a collection" %}</a>
+                        <a class="icon plus open-popin additemtocollection" data-type="image" data-id="{{ img.id }}" href="#add-to-collection">{% trans "Add to a collection" %}</a>
                       {% else %}
                         <a class="icon plus" href="{% url 'login' %}?next={% url 'annotate_picture' image_id=img.id %}">{% trans "Add to a collection" %}</a>
                       {% endif %}
--- a/src/egonomy/templates/egonomy_newbase.html	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/templates/egonomy_newbase.html	Thu Jun 27 15:27:01 2013 +0200
@@ -21,19 +21,19 @@
 </head>
 {% endblock %}
 <body>
-    {% if current_user_collection_list %}
     <div class="popin-wrap">
+      {% if current_user_collection_list %}
         <div id="add-to-collection" class="popin popin-new-collection box-shadow">
             <header>
                 <h2>{% trans "Add to the collection" %}</h2>
                 <a href="#" class="close-popin"></a>
             </header>
             <section>
-                <form action="#">
+                <form action="{% url 'add_item' %}" method="POST">
                     <p>
                         <label for="collection-name">{% trans "Add to" %} :</label>
                         <label class="styled-select">
-                            <select name="collection_pk">
+                            <select name="collection-pk">
                               {% for c in current_user_collection_list %}
                                 <option value="{{ c.pk }}">{{ c.title }}</option>
                               {% endfor %}
@@ -41,19 +41,21 @@
                         </label>
                     </p>
                     <p>
-                        <label class="block" for="image-description">{% trans "Image comment" %} :</label>
-                        <textarea name="" id="image-description"></textarea>
+                        <label class="block" for="item-description">{% trans "Image comment" %} :</label>
+                        <textarea name="item-description" id="item-description"></textarea>
                     </p>
                     <div class="buttons">
                         <a href="#" class="btn close-popin">{% trans "Cancel" %}</a>
                         <input class="btn" type="submit" value="{% trans 'Submit' %}">
                     </div>
+                    <input class="item-type" name="item-type" type="hidden" value="">
+                    <input class="item-id" name="item-id" type="hidden" value="">{% csrf_token %}
                 </form>
             </section>
         </div>
+      {% endif %}
+      {% block popins %}{% endblock %}
     </div>
-    {% endif %}
-    {% block popins %}{% endblock %}
     <div class="wrap">
         <header class="clearfix">
             <h1><a href="{% url 'home' %}">egonomy</a></h1>
--- a/src/egonomy/templates/egonomy_view_collection.html	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/templates/egonomy_view_collection.html	Thu Jun 27 15:27:01 2013 +0200
@@ -6,7 +6,6 @@
 {% block title %}{% trans "View a fragment" %}{% endblock %}
 
 {% block popins %}
-    <div class="popin-wrap">
         <div id="collection-parameters" class="popin big-popin box-shadow">
             <header>
                 <h2>PARAMÈTRES DE LA COLLECTION</h2>
@@ -58,16 +57,16 @@
                      <ul class="list-projets-2 clearfix">
                         <li>
                             <div class="top clearfix">
-                                <img src="img/113x113.png" alt="">
-                                <img src="img/113x113-2.png" alt="">
+                                <img src="{% static 'egonomy/img/empty.gif' %}" width="113px" height="113px" alt="" />
+                                <img src="{% static 'egonomy/img/empty.gif' %}" width="113px" height="113px" alt="" />
                             </div>
                             <div class="mid">
                                 <h3>Collection n°1</h3>
                                 <p>par Hubert Trucchose</p>
                             </div>
                             <div class="bot clearfix">
-                                <img src="img/113x113.png" alt="">
-                                <img src="img/113x113-2.png" alt="">
+                                <img src="{% static 'egonomy/img/empty.gif' %}" width="113px" height="113px" alt="" />
+                                <img src="{% static 'egonomy/img/empty.gif' %}" width="113px" height="113px" alt="" />
                             </div>
                         </li>
                     </ul>
@@ -78,12 +77,11 @@
                 </form>
             </section>
         </div>
-    </div>
 {% endblock %}
 
 {% block content %}
             <div class="title-page">
-                <h2>{{ col.title }}</h2>
+                <h2>{{ col.title }} / <span>par {{ col.author }}</span></h2>
                 <ul class="sub-nav title-menu clearfix">
                     <li><a href="#" class="active">argumentaire</a></li>
                     <li><span class="dot-6"></span></li>
@@ -101,6 +99,105 @@
                     <li><a class="open-popin" href="#collection-parameters">Paramètres de la collection</a></li>
                 </ul>
             </div>
+        {% if items %}
+          {% ifequal display "slideshow" %}
+            <ul class="list-projets-3 clearfix masonry-465">
+             {% for item in items %}
+              {% ifequal item.content_type.model "fragment" %}
+                <li class="clearfix horizontal item-masonry">
+                    {% with fragment=item.content_object %}
+                    <div class="col-left">
+						<a href="{% url 'view_fragment' fragment_pk=frg.pk %}">
+						<div class="center-image">
+						    <div class="image-and-fragment square-fragment-225">
+						        {% with image=fragment.image.info.image_file %}
+						        {% include "partial/fragment_only.html" %}
+						        {% endwith %}
+						    </div>
+						</div>
+						</a>
+                        <div class="tools toggle">
+                            <ul class="clearfix">
+                                <li><a class="tool twitter" href="#" title="{% trans 'Share on Twitter'%}"></a></li>
+                                <li><a class="tool facebook" href="#" title="{% trans 'Share on Facebook'%}"></a></li>
+                                <li>{% if user.is_authenticated %}
+			                        <a class="tool plus open-popin additemtocollection" data-type="fragment" data-id="{{ fragment.pk }}" href="#add-to-collection" title="{% trans 'Add to a collection' %}"></a>
+			                      {% else %}
+			                        <a class="tool plus" href="{% url 'login' %}?next={% url 'view_fragment' fragment_pk=fragment.pk %}" title="{% trans 'Add to a collection' %}"></a>
+			                      {% endif %}</li>
+                                <li><a class="tool cut" href="{% url 'create_fragment' image_id=fragment.image.id %}" title="{% trans 'Create a fragment'%}"></a></li>
+                                <li><a title="Supprimer" class="tool trash" href="#"></a></li>
+                            </ul>
+                        </div>
+                    </div>
+                    <div class="col-right">
+                        <div class="project-title">
+                            {% if col.author == user %}<a class="tool edit toggle" href="#"></a>{% endif %}
+                            <h3>{{ fragment.title }}</h3>
+                            <h4>{{ fragment.author }}</h4>
+                        </div>
+                        <p>desc : {{ item.description }}<br/>contenttype : {{ item.content_type.model }}<br/>object_id : {{ item.object_id }}<br/>content_object : {{ item.content_object }}</p>
+                    </div>
+                    {% endwith %}
+                </li>
+              {% else %}
+              {% with img=item.content_object %}
+               {% with img.info.image_file as image %}
+				{% if image %}
+				 {% if image|is_portrait %}
+				<li class="clearfix horizontal item-masonry">
+                    <div class="col-left">
+                        <a href="{% url 'annotate_picture' image_id=img.id %}">
+				          {% thumbnail image "225" format="PNG" crop="center" as im %}
+				            <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"/>
+				          {% empty %}
+				            <img src="{% static 'egonomy/img/empty.gif' %}" width="225" height="225" class="placeholder" />
+				          {% endthumbnail %}
+				        </a>
+				 {% else %}
+				<li class="item-masonry">
+                    <div class="col-left">
+                        <a href="{% url 'annotate_picture' image_id=img.id %}">
+                          {% thumbnail image "469" format="PNG" crop="center" as im %}
+                            <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"/>
+                          {% empty %}
+                            <img src="{% static 'egonomy/img/empty.gif' %}" width="469" height="225" class="placeholder" />
+                          {% endthumbnail %}
+                        </a>
+                 {% endif %}
+                        <div class="tools toggle">
+                            <ul class="clearfix">
+                                <li><a class="tool twitter" href="#" title="{% trans 'Share on Twitter'%}"></a></li>
+                                <li><a class="tool facebook" href="#" title="{% trans 'Share on Facebook'%}"></a></li>
+                                <li>{% if user.is_authenticated %}
+                                    <a class="tool plus open-popin additemtocollection" data-type="image" data-id="{{ img.id }}" href="#add-to-collection" title="{% trans 'Add to a collection' %}"></a>
+                                  {% else %}
+                                    <a class="tool plus" href="{% url 'login' %}?next={% url 'annotation_picture' image_id=img.id %}" title="{% trans 'Add to a collection' %}"></a>
+                                  {% endif %}</li>
+                                <li><a class="tool cut" href="{% url 'create_fragment' image_id=img.id %}" title="{% trans 'Create a fragment'%}"></a></li>
+                                <li><a title="Supprimer" class="tool trash" href="#"></a></li>
+                            </ul>
+                        </div>
+                    </div>
+                    <div class="col-right">
+                        <div class="project-title">
+                            {% if col.author == user %}<a class="tool edit toggle" href="#"></a>{% endif %}
+                            <h3>{{ img.metadata.titre }}</h3>
+                            <h4>{{ img.metadata.auteur }}</h4>
+                        </div>
+                        <p>desc : {{ item.description }}<br/>contenttype : {{ item.content_type.model }}<br/>object_id : {{ item.object_id }}<br/>content_object : {{ item.content_object }}</p>
+                    </div>
+                  </li>
+				{% else %}
+				     <img src="{% static 'egonomy/img/empty.gif' %}" width=225" height="225" class="placeholder" />
+				{% endif %}
+				{% endwith %}
+              {% endwith %}
+              {% endifequal %}
+             {% endfor %}
+            </ul>
+          {% endifequal %}
+        {% else %}
             <div class="empty-block">
                 <form class="search-form-big" id="search-form-big" action="{% if search_fragment %}{% url 'all_fragments' %}{% else %}{% url 'all_pictures' %}{% endif %}" method="GET">
                     <p>
@@ -115,6 +212,7 @@
                     </p>
                 </form>
             </div>
+          {% endif %}
 {% endblock %}
 
 {% block js_page %}
--- a/src/egonomy/templates/egonomy_view_fragment.html	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/templates/egonomy_view_fragment.html	Thu Jun 27 15:27:01 2013 +0200
@@ -31,7 +31,7 @@
                     </li>
                     <li>
                       {% if user.is_authenticated %}
-                        <a class="icon plus open-popin" href="#add-to-collection">{% trans "Add to a collection" %}</a>
+                        <a class="icon plus open-popin additemtocollection" data-type="fragment" data-id="{{ fragment.pk }}" href="#add-to-collection">{% trans "Add to a collection" %}</a>
                       {% else %}
                         <a class="icon plus" href="{% url 'login' %}?next={% url 'view_fragment' fragment_pk=fragment.pk %}">{% trans "Add to a collection" %}</a>
                       {% endif %}
@@ -40,9 +40,6 @@
                         <a class="icon save" href="#">Enregistrer sous</a>
                     </li>
                     <li>
-                        <a class="icon plus open-popin" href="#add-to-collection">Ajouter à ma collection</a>
-                    </li>
-                    <li>
                         <form action="#">
                             <p>
                                 <input class="search-form" id="id_search" type="text" placeholder="Romantisme noir">
--- a/src/egonomy/templates/partial/fragment_in_list.html	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/templates/partial/fragment_in_list.html	Thu Jun 27 15:27:01 2013 +0200
@@ -19,11 +19,11 @@
     <ul class="clearfix">
         <li><a class="tool twitter" href="#" title="{% trans 'Share on Twitter'%}"></a></li>
         <li><a class="tool facebook" href="#" title="{% trans 'Share on Facebook'%}"></a></li>
-        {% if user.is_authenticated %}
-        <li><a class="tool plus open-popin" href="#add-to-collection" title="{% trans 'Add to a collection'%}"></a></li>
-        {% else %}
+      {% if user.is_authenticated %}
+        <li><a class="tool plus open-popin additemtocollection" data-type="fragment" data-id="{{ frg.pk }}" href="#add-to-collection" title="{% trans 'Add to a collection'%}"></a></li>
+      {% else %}
         <li><a class="tool plus" href="{% url 'login' %}" title="{% trans 'Log in to add to a collection' %}"></a></li>
-        {% endif %}
+      {% endif %}
         <li><a class="tool cut" href="{% url 'create_fragment' image_id=fragment.image.id %}" title="{% trans 'Create a fragment'%}"></a></li>
       {% if user_fragments and username = user.username %}
         <li><a class="tool trash" href="{% url 'delete_fragment' %}?fragment_pk={{ frg.pk }}&next={% url 'user_fragments' user.username %}%3Fpage%3D{{ cur_page_nb }}" onclick="return confirm('{% trans "Do you really want to delete this fragment ? Warning : this action est irreversible." %}')" title="{% trans "Delete this fragment" %}"></a></li>
--- a/src/egonomy/templates/partial/image_in_list.html	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/templates/partial/image_in_list.html	Thu Jun 27 15:27:01 2013 +0200
@@ -33,11 +33,11 @@
     <ul class="clearfix">
         <li><a class="tool twitter" href="#" title="{% trans 'Share on Twitter'%}"></a></li>
         <li><a class="tool facebook" href="#" title="{% trans 'Share on Facebook'%}"></a></li>
-        {% if user.is_authenticated %}
-        <li><a class="tool plus open-popin" href="#add-to-collection" title="{% trans 'Add to a collection'%}"></a></li>
-        {% else %}
+      {% if user.is_authenticated %}
+        <li><a class="tool plus open-popin additemtocollection" data-type="image" data-id="{{ img.id }}" href="#add-to-collection" title="{% trans 'Add to a collection'%}"></a></li>
+      {% else %}
         <li><a class="tool plus" href="{% url 'login' %}" title="{% trans 'Log in to add to a collection' %}"></a></li>
-        {% endif %}
+      {% endif %}
         <li><a class="tool cut" href="{% url 'create_fragment' image_id=img.id %}" title="{% trans 'Create a fragment'%}"></a></li>
     </ul>
 </div>
\ No newline at end of file
--- a/src/egonomy/urls.py	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/urls.py	Thu Jun 27 15:27:01 2013 +0200
@@ -23,6 +23,7 @@
     url(r'^usercollections/(?P<username>.*)/$', 'egonomy.views.user_collections', name='user_collections'),
     url(r'^newcollection/$', 'egonomy.views.new_collection', name='new_collection'),
     url(r'^viewcollection/(?P<collection_pk>.*)/$', 'egonomy.views.view_collection', name='view_collection'),
+    url(r'^additem/$', 'egonomy.views.add_item_to_collection', name='add_item'),
 
     # Uncomment the admin/doc line below to enable admin documentation:
     url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
--- a/src/egonomy/views.py	Thu Jun 27 15:26:35 2013 +0200
+++ b/src/egonomy/views.py	Thu Jun 27 15:27:01 2013 +0200
@@ -1,6 +1,7 @@
 from django.conf import settings
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import User
+from django.contrib.contenttypes.models import ContentType
 from django.core.paginator import Paginator, InvalidPage, EmptyPage
 from django.core.urlresolvers import reverse
 from django.db.models.aggregates import Max
@@ -8,7 +9,8 @@
 from django.shortcuts import get_object_or_404, render_to_response, redirect
 from django.template import RequestContext
 from django.utils.translation import ugettext as _
-from egonomy.models import ImageMetadata, Image, Fragment, ImageInfo, Collection
+from egonomy.models import ImageMetadata, Image, Fragment, ImageInfo, Collection,\
+    CollectionItem
 from egonomy.search_indexes import QueryParser
 from egonomy.search_indexes.paginator import SearchPaginator
 from egonomy.search_indexes.query import ModelRelatedSearchQuerySet
@@ -371,7 +373,7 @@
     cur_page_nb = request.GET.get("page") or 1
     cur_page_nb = int(cur_page_nb)
     
-    collections = Collection.objects.filter(public=True).order_by('-creation').select_related('items')
+    collections = Collection.objects.filter(public=True).order_by('-creation').select_related('author', 'items')
     nb = request.GET.get("limit") or getattr(settings,"IMAGES_PER_PAGE", 32)
     paginator = Paginator(collections, nb)
         
@@ -398,10 +400,10 @@
     
     if user==request.user:
         user_collections = True
-        collections = Collection.objects.filter(author=user).order_by('-creation').select_related('items')
+        collections = Collection.objects.filter(author=user).order_by('-creation').select_related('author', 'items')
     else:
         user_collections = False
-        collections = Collection.objects.filter(author=user).filter(public=True).order_by('-creation').select_related('items')
+        collections = Collection.objects.filter(author=user).filter(public=True).order_by('-creation').select_related('author', 'items')
         
     nb = request.GET.get("limit") or getattr(settings,"IMAGES_PER_PAGE", 32)
     paginator = Paginator(collections, nb)
@@ -438,10 +440,16 @@
 
 def view_collection(request, collection_pk):
     
-    col = get_object_or_404(Collection.objects.select_related('items'), pk=collection_pk)
+    display = request.GET.get("display") or "slideshow"
+    if display!="slideshow" and display!="mosaic" and display!="geographical":
+        display = "slideshow"
+    
+    col = get_object_or_404(Collection.objects.select_related('author'), pk=collection_pk)
+    items = CollectionItem.objects.filter(collection=col).select_related('author', 'content_type', 'object_id', 'content_object').order_by("order")
     
     return render_to_response("egonomy_view_collection.html",
-                              {'col':col},
+                              {'col':col, 'items':items, 'display':display,
+                               'current_user_collection_list':current_user_collection_list(request)},
                               context_instance=RequestContext(request))
 
 
@@ -454,3 +462,48 @@
     else:
         return None
 
+
+
+
+def add_item_to_collection(request):
+    
+    col_pk = request.POST["collection-pk"]
+    item_desc = request.POST["item-description"]
+    item_type = request.POST["item-type"]
+    item_id = request.POST["item-id"]
+    
+    # Test collection
+    try:
+        col_pk = int(col_pk)
+    except:
+        return HttpResponse("Collection number invalid.", status_code=400)
+    col = get_object_or_404(Collection, pk=col_pk)
+    
+    if item_type=="image":
+        # Test image
+        item = get_object_or_404(Image, id=item_id)
+    elif item_type=="fragment":
+        # Test fragment
+        try:
+            item_id = int(item_id)
+        except:
+            return HttpResponse("Fragment number invalid.", status_code=400)
+        item = get_object_or_404(Fragment, pk=item_id)
+    else:
+        return HttpResponse("item-type must be 'image' or 'fragment'.", status_code=400)
+    
+    col_item = CollectionItem()
+    col_item.collection = col
+    col_item.content_type = ContentType.objects.get_for_model(item)
+    col_item.object_id = str(item_id)
+    col_item.content_object = item
+    col_item.description = item_desc
+    # Get the collection's max order and set the new item's one
+    max_order = CollectionItem.objects.filter(collection=col).aggregate(Max('order'))['order__max']
+    if not max_order:
+        max_order = 0
+    col_item.order = max_order + 1
+    col_item.save()
+        
+    return redirect("view_collection", collection_pk=col.pk)
+