# HG changeset patch # User Anthony Ly # Date 1372339621 -7200 # Node ID 480ab94bf0feb781da8d191d6a2af058e563c154 # Parent 8c3517f6f21ecf91fb6d21b0f0765f165babb84b# Parent 1a1f3958c5519c44cfbd23e558d1941a83e46c6b Merge diff -r 8c3517f6f21e -r 480ab94bf0fe 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;} diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/migrations/0003_add_collection_and_items.py --- 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': { diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/models.py --- 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() diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/static/egonomy/css/style.css --- 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 */ diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/static/egonomy/img/icon-pencil-15.png Binary file src/egonomy/static/egonomy/img/icon-pencil-15.png has changed diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/static/egonomy/img/tools-sprite.png Binary file src/egonomy/static/egonomy/img/tools-sprite.png has changed diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/static/egonomy/js/main.js --- 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 diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/templates/egonomy_all_collections.html --- 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 %} -

{% trans "New collection" %}

@@ -38,7 +37,6 @@
-
{% endblock %} {% block content %} diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/templates/egonomy_annotate_picture.html --- 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 @@
  • {% if user.is_authenticated %} - {% trans "Add to a collection" %} + {% trans "Add to a collection" %} {% else %} {% trans "Add to a collection" %} {% endif %} diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/templates/egonomy_newbase.html --- 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 @@ {% endblock %} - {% if current_user_collection_list %}
    + {% if current_user_collection_list %}

    {% trans "Add to the collection" %}

    -
    +

    - - + +

    + + {% csrf_token %}
    + {% endif %} + {% block popins %}{% endblock %}
    - {% endif %} - {% block popins %}{% endblock %}

    egonomy

    diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/templates/egonomy_view_collection.html --- 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 %} -

    PARAMÈTRES DE LA COLLECTION

    @@ -58,16 +57,16 @@
    • - - + +

      Collection n°1

      par Hubert Trucchose

      - - + +
    @@ -78,12 +77,11 @@
    -
    {% endblock %} {% block content %}
    -

    {{ col.title }}

    +

    {{ col.title }} / par {{ col.author }}

    + {% if items %} + {% ifequal display "slideshow" %} + + {% endifequal %} + {% else %}

    @@ -115,6 +212,7 @@

    + {% endif %} {% endblock %} {% block js_page %} diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/templates/egonomy_view_fragment.html --- 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 @@
  • {% if user.is_authenticated %} - {% trans "Add to a collection" %} + {% trans "Add to a collection" %} {% else %} {% trans "Add to a collection" %} {% endif %} @@ -40,9 +40,6 @@ Enregistrer sous
  • - Ajouter à ma collection -
  • -
  • diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/templates/partial/fragment_in_list.html --- 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 @@

    • - {% if user.is_authenticated %} -
    • - {% else %} + {% if user.is_authenticated %} +
    • + {% else %}
    • - {% endif %} + {% endif %}
    • {% if user_fragments and username = user.username %}
    • diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/templates/partial/image_in_list.html --- 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 @@
      • - {% if user.is_authenticated %} -
      • - {% else %} + {% if user.is_authenticated %} +
      • + {% else %}
      • - {% endif %} + {% endif %}
      \ No newline at end of file diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/urls.py --- 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.*)/$', 'egonomy.views.user_collections', name='user_collections'), url(r'^newcollection/$', 'egonomy.views.new_collection', name='new_collection'), url(r'^viewcollection/(?P.*)/$', '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')), diff -r 8c3517f6f21e -r 480ab94bf0fe src/egonomy/views.py --- 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) +