# HG changeset patch # User veltr # Date 1381242840 -7200 # Node ID 752062bdeb109308252e86b0d297af45af474e19 # Parent e2043b49682d1833eab3281f63bb5f13acb05a99 Corrected image load bug and added describe prev/next diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/management/commands/populate_notice_years.py --- a/src/jocondelab/management/commands/populate_notice_years.py Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/management/commands/populate_notice_years.py Tue Oct 08 16:34:00 2013 +0200 @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- -from django.core.management.base import BaseCommand +from django.core.management.base import NoArgsCommand from core.models import (Notice) from core.utils import show_progress from jocondelab.models import NoticeYears from django.db import reset_queries, transaction +from optparse import make_option import re -class Command(BaseCommand): +class Command(NoArgsCommand): help = "Extract Years from MILL field" diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/static/jocondelab/css/front-notice.css --- a/src/jocondelab/static/jocondelab/css/front-notice.css Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/static/jocondelab/css/front-notice.css Tue Oct 08 16:34:00 2013 +0200 @@ -15,11 +15,23 @@ } .describe-mode .notice-images li { - margin: 0; box-shadow: 0 0 3px #999999; display: inline-block; max-width: 100%; + margin: 0; display: inline-block; max-width: 80%; +} + +.describe-mode .notice-images li:nth-child(n+2) { + float: right; clear: right; width: 20%; } .describe-mode .notice-images img { - max-height: 500px; + max-height: 480px; +} + +.describe-mode .notice-images li:nth-child(n+2) img { + max-height: 160px; +} + +.describe-title { + font-size: 18px; margin: 5px 0; clear: both; font-weight: bold; } .notice-colright-wrapper { diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/static/jocondelab/img/default-image.png Binary file src/jocondelab/static/jocondelab/img/default-image.png has changed diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/static/jocondelab/js/front-common.js --- a/src/jocondelab/static/jocondelab/js/front-common.js Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/static/jocondelab/js/front-common.js Tue Oct 08 16:34:00 2013 +0200 @@ -1,3 +1,24 @@ +/* Image load events may be triggered before jQuery is loaded. + * Here we bind temporary functions to the Window namespace */ + +(function() { + + function tmpBind(property) { + window[property] = function() { + var arglist = Array.prototype.slice.call(arguments); + setTimeout(function() { + window[property].apply(window, arglist); + }, 500); + }; + } + + var propsToBind = [ "onWikiImageLoad", "onWikiImageError", "onResultImageError" ]; + for (var i = 0; i < propsToBind.length; i++) { + tmpBind(propsToBind[i]); + } + +})(); + $(function() { /* SEARCH TAG-IT */ @@ -332,6 +353,11 @@ adaptGrid(); }; + window.onResultImageError = function(img) { + img.src = urls.img_if_404; + throttledCheckSizes(); + }; + /* END NOTICE LIST MANAGEMENT */ /* AJAX SCROLL LOAD */ @@ -398,6 +424,7 @@ window.loadSearchResults = function(query) { $(".hide-on-search").hide(); $win.off("scroll.ajaxload"); + $(".wiki-info img").off("load error"); $results.empty(); $(".loading-please-wait").show(); $.ajax({ @@ -443,11 +470,17 @@ } } - /* */ - resizeWikiInfo(); - $(".wiki-info img").on("load", resizeWikiInfo); + window.onWikiImageLoad = function() { + resizeWikiInfo(true); + }; + window.onWikiImageError = function(img) { + $(img).hide(); + resizeWikiInfo(true); + }; + + /* */ $win.resize(function() { adaptGrid(); diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/static/jocondelab/js/front-notice.js --- a/src/jocondelab/static/jocondelab/js/front-notice.js Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/static/jocondelab/js/front-notice.js Tue Oct 08 16:34:00 2013 +0200 @@ -291,4 +291,5 @@ }); return false; }); + }); diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/templates/jocondelab/front_base.html --- a/src/jocondelab/templates/jocondelab/front_base.html Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/templates/jocondelab/front_base.html Tue Oct 08 16:34:00 2013 +0200 @@ -31,7 +31,8 @@ diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/templates/jocondelab/front_describe.html --- a/src/jocondelab/templates/jocondelab/front_describe.html Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/templates/jocondelab/front_describe.html Tue Oct 08 16:34:00 2013 +0200 @@ -2,13 +2,12 @@ {% load i18n %} {% block title %}JocondeLab » {% trans "Contribuer" %}{% endblock %} - -{% block breadcrumbs %}{% trans "Contribuer" %}{% endblock %} +{% url 'front_about' as url %} +{% block breadcrumbs %}{% trans "Contribuer" %}{% endblock %} {% block main %}
- {{object.id}} {% block images %}{{block.super}}{% endblock %} -

{{object.titr}}

+

{{object.titr}}

{% block contribution %}

{% trans "Décrivez le sujet de cette œuvre" %}

@@ -16,7 +15,8 @@
{% endblock %} diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/templates/jocondelab/partial/notice_list.html --- a/src/jocondelab/templates/jocondelab/partial/notice_list.html Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/templates/jocondelab/partial/notice_list.html Tue Oct 08 16:34:00 2013 +0200 @@ -4,7 +4,7 @@
  • - {{notice.imagetitle}} + {{notice.imagetitle}}
  • {% if wkinfo.thumbnail %} - {{wkinfo.label}} + {{wkinfo.label}} {% endif %}

    diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/urls.py --- a/src/jocondelab/urls.py Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/urls.py Tue Oct 08 16:34:00 2013 +0200 @@ -39,7 +39,8 @@ url(r'^timeline/$', TemplateView.as_view(template_name="jocondelab/front_timeline.html"), name='front_timeline'), url(r'^about/$', TemplateView.as_view(template_name="jocondelab/front_about.html"), name='front_about'), url(r'^notice/(?P\d+)/$', NoticeView.as_view(), name='front_notice'), - url(r'^describe/$', NoticeView.as_view(template_name="jocondelab/front_describe.html", show_contributions=False), name='random_describe'), + url(r'^describe/(?P\d+)/$', NoticeView.as_view(template_name="jocondelab/front_describe.html", show_contributions=False), name='front_describe'), + url(r'^describe/$', 'jocondelab.views.front_office.describe_view', name='random_describe'), url(r'^ajax/terms/$', 'jocondelab.views.ajax.terms', name='ajax_terms'), url(r'^ajax/years/$', 'jocondelab.views.ajax.years', name='ajax_years'), url(r'^ajax/geocoords/$', 'jocondelab.views.ajax.geo_coords', name='ajax_geo_coords'), diff -r e2043b49682d -r 752062bdeb10 src/jocondelab/views/front_office.py --- a/src/jocondelab/views/front_office.py Mon Oct 07 13:32:09 2013 +0200 +++ b/src/jocondelab/views/front_office.py Tue Oct 08 16:34:00 2013 +0200 @@ -13,6 +13,7 @@ from django.views.generic import DetailView, TemplateView from django.db.models import Sum, Count import random +from django.shortcuts import redirect class SearchView(TemplateView): @@ -94,9 +95,8 @@ } for t in Term.objects.filter(noticeterm__notice=n,dbpedia_fields__language_code=lang).distinct()] termsbythesaurus = {} for term in terms: - if not term["thesaurus"] in termsbythesaurus: - termsbythesaurus[term["thesaurus"]] = [] - termsbythesaurus[term["thesaurus"]].append(term) + th = termsbythesaurus.setdefault(term["thesaurus"], []) + th.append(term) noticedict = { "id": n.id, "imagetitle": n.titr if n.titr else n.deno, @@ -147,12 +147,8 @@ "translated": False, "label": nt.label } - if not term["thesaurus"] in termsbythesaurus: - termsbythesaurus[term["thesaurus"]] = { - "translated": [], - "untranslated": [] - } - termsbythesaurus[term["thesaurus"]]["untranslated"].append(term) + th = termsbythesaurus.setdefault(term["thesaurus"], { "translated": [], "untranslated": [] }) + th["untranslated"].append(term) for nt in Term.objects.filter(noticeterm__notice=self.object, dbpedia_fields__language_code=lang).select_related('thesaurus,dbpedia_fields').order_by('dbpedia_fields__label').distinct(): term = { "thesaurus": nt.thesaurus.label, @@ -160,12 +156,8 @@ "translated": True, "label": nt.dbpedia_fields.get(language_code = lang).label } - if not term["thesaurus"] in termsbythesaurus: - termsbythesaurus[term["thesaurus"]] = { - "translated": [], - "untranslated": [] - } - termsbythesaurus[term["thesaurus"]]["translated"].append(term) + th = termsbythesaurus.setdefault(term["thesaurus"], { "translated": [], "untranslated": [] }) + th["translated"].append(term) context["terms_by_thesaurus"] = termsbythesaurus if self.show_contributions: @@ -183,14 +175,26 @@ context['wikipedia_urls'] = json.dumps(settings.WIKIPEDIA_URLS) context['JOCONDE_NOTICE_BASE_URL'] = settings.JOCONDE_NOTICE_BASE_URL + notice_history = self.request.session.get('notice_history',None) + if self.object.id in notice_history: + p = notice_history.index(self.object.id) + if p < len(notice_history) - 1: + context['next_notice'] = notice_history[p + 1] + if p > 0: + context['prev_notice'] = notice_history[p - 1] + return context - - def get_object(self): - if self.pk_url_kwarg in self.kwargs: - return super(NoticeView, self).get_object() - else: - queryset = self.get_queryset().filter(image=True, repr='', peri__contains='4e quart 19e siècle', noticeterm__term__id__in=ContributableTerm.objects.values('term__id')) - return queryset[random.randint(0, queryset.count() - 1)] + +def describe_view(request): + notice_history = request.session.get('notice_history',[]) + queryset = Notice.objects.filter(image=True, repr='', peri__contains='4e quart 19e siècle', noticeterm__term__id__in=ContributableTerm.objects.values('term__id')) + for i in range(10): + id = queryset[random.randint(0, queryset.count() - 1)].id + if id not in notice_history: + break + notice_history.append(id) + request.session['notice_history'] = notice_history + return redirect('front_describe', pk=id) class FrontTermListView(TemplateView):