user fragment page and enhance pertimm display.
authorcavaliet
Mon, 25 Feb 2013 13:54:58 +0100
changeset 67 a085d708c407
parent 66 3a6b48269fa0
child 68 dc6f8802c08a
user fragment page and enhance pertimm display.
src/egonomy/models.py
src/egonomy/templates/egonomy_all_fragments.html
src/egonomy/templates/egonomy_annotate_picture.html
src/egonomy/templates/egonomy_create_fragment.html
src/egonomy/templates/egonomy_home.html
src/egonomy/templates/egonomy_view_fragment.html
src/egonomy/urls.py
src/egonomy/views.py
--- a/src/egonomy/models.py	Mon Feb 25 12:25:48 2013 +0100
+++ b/src/egonomy/models.py	Mon Feb 25 13:54:58 2013 +0100
@@ -37,6 +37,10 @@
     titre_pertimm = models.TextField(null=True, blank=True)
     description_pertimm = models.TextField(null=True, blank=True)
     thesaurus_pertimm = models.TextField(null=True, blank=True)
+    
+    @property
+    def thesaurus_pertimm_str(self):
+        return self.thesaurus_pertimm.replace("|", ",")
 
 
 class ImageInfo(models.Model):
--- a/src/egonomy/templates/egonomy_all_fragments.html	Mon Feb 25 12:25:48 2013 +0100
+++ b/src/egonomy/templates/egonomy_all_fragments.html	Mon Feb 25 13:54:58 2013 +0100
@@ -16,8 +16,11 @@
                         <h2>{% trans "Search results for" %} &laquo;&nbsp;{{ search }}&nbsp;&raquo;&nbsp;:
                       {% endifequal %}
                         <span class="right"><a href="{% url 'all_fragments' %}" alt="{% trans "All fragments" %}">{% trans "All fragments" %}</a></span></h2>
+                     {% elif user_fragments %}
+                        <h2>{% trans "Fragments created by" %} : {{ username }}</h2>
+                        <span class="right"><a href="{% url 'all_fragments' %}" alt="{% trans "All fragments" %}">{% trans "All fragments" %}</a></span></h2>
                      {% else %}
-                        <h2>{% trans "All pictures" %}</h2> 
+                        <h2>{% trans "All fragments" %}</h2> 
                      {% endif %}
 						{% if nb_pages %}<p>{% build_pagination nb_pages cur_page_nb url_pagination "contents_page clickable" %}</p>{% endif %}
                         <ul class="fullwidth">
@@ -53,7 +56,7 @@
                                 </div>
                              </div>
                              <h3>{{ frg.highlighted.title|first|safe|default:frg.title }}</h3></a>
-                             <p>{% trans "Annotated by" %} <strong>{{ frg.author }}</strong></p>
+                             <p>{% trans "Annotated by" %} <strong><a href="{% url 'user_fragments' username=frg.author %}">{{ frg.author }}</a></strong></p>
                             </li>
                           {% endfor %}
                         </ul>
--- a/src/egonomy/templates/egonomy_annotate_picture.html	Mon Feb 25 12:25:48 2013 +0100
+++ b/src/egonomy/templates/egonomy_annotate_picture.html	Mon Feb 25 13:54:58 2013 +0100
@@ -69,7 +69,7 @@
                             </tr>
                             <tr>
                                 <th>{% trans "Pertimm thesaurus" %}&nbsp;:</th>
-                                <td>{{ img.metadata.thesaurus_pertimm|default:"" }}</td>
+                                <td>{{ img.metadata.thesaurus_pertimm_str|default:"" }}</td>
                             </tr>
                             <!--tr>
                                 <th> </th>
@@ -120,7 +120,7 @@
                                     </div>
                                 </div>
                                 <h3>{{ frg.title }}</h3></a>
-                                <p>{% trans "Annotated by" %} <strong>{{ frg.author }}</strong></p>
+                                <p>{% trans "Annotated by" %} <strong><a href="{% url 'user_fragments' username=frg.author %}">{{ frg.author }}</a></strong></p>
                             </li>
                           {% endfor %}
                         </ul>
--- a/src/egonomy/templates/egonomy_create_fragment.html	Mon Feb 25 12:25:48 2013 +0100
+++ b/src/egonomy/templates/egonomy_create_fragment.html	Mon Feb 25 13:54:58 2013 +0100
@@ -125,7 +125,7 @@
                                 {% if img.metadata.thesaurus_pertimm %}
 	                            <tr>
 	                                <th>{% trans "Pertimm thesaurus" %}&nbsp;:</th>
-	                                <td><span id="pertimm_thesaurus_tags">{{ img.metadata.thesaurus_pertimm|default:"" }}</span><br/><span id="add_pertimm_thesaurus" class="right add_tag_btn">+ {% trans 'Add Pertimm thesaurus keywords to yours' %}</span></td>
+	                                <td><span id="pertimm_thesaurus_tags">{{ img.metadata.thesaurus_pertimm_str|default:"" }}</span><br/><span id="add_pertimm_thesaurus" class="right add_tag_btn">+ {% trans 'Add Pertimm thesaurus keywords to yours' %}</span></td>
 	                            </tr>
                                 {% endif %}
                             </table>
@@ -169,7 +169,7 @@
                                     </div>
                                 </div>
                                 <h3>{{ frg.title }}</h3></a>
-                                <p>{% trans "Annotated by" %} <strong>{{ frg.author }}</strong></p>
+                                <p>{% trans "Annotated by" %} <strong><a href="{% url 'user_fragments' username=frg.author %}">{{ frg.author }}</a></strong></p>
                             </li>
                           {% endfor %}
                         </ul>
--- a/src/egonomy/templates/egonomy_home.html	Mon Feb 25 12:25:48 2013 +0100
+++ b/src/egonomy/templates/egonomy_home.html	Mon Feb 25 13:54:58 2013 +0100
@@ -78,7 +78,7 @@
                                 </div>
                                 <h3>{{ frg.title }}</h3></a>
                                 <h4>{% trans "Fragment from" %} <a href="{% url 'annotate_picture' image_id=frg.image.id %}">{{ frg.image.metadata.titre|default:_("No title") }}</a></h4>
-                                <p>{% trans "Annotated by" %} <strong>{{ frg.author }}</strong></p>
+                                <p>{% trans "Annotated by" %} <strong><a href="{% url 'user_fragments' username=frg.author %}">{{ frg.author }}</a></strong></p>
                             </li>
                           {% endfor %}
                         </ul>
--- a/src/egonomy/templates/egonomy_view_fragment.html	Mon Feb 25 12:25:48 2013 +0100
+++ b/src/egonomy/templates/egonomy_view_fragment.html	Mon Feb 25 13:54:58 2013 +0100
@@ -97,7 +97,7 @@
                                     </div>
                                 </div>
                                 <h3>{{ frg.title }}</h3></a>
-                                <p>{% trans "Annotated by" %} <strong>{{ frg.author }}</strong></p>
+                                <p>{% trans "Annotated by" %} <strong><a href="{% url 'user_fragments' username=frg.author %}">{{ frg.author }}</a></strong></p>
                             </li>
                           {% endfor %}
                         </ul>
--- a/src/egonomy/urls.py	Mon Feb 25 12:25:48 2013 +0100
+++ b/src/egonomy/urls.py	Mon Feb 25 13:54:58 2013 +0100
@@ -15,6 +15,7 @@
     url(r'^savefragment/$', 'egonomy.views.save_fragment', name='save_fragment'),
     url(r'^allpictures/$', 'egonomy.views.all_pictures', name='all_pictures'),
     url(r'^allfragments/$', 'egonomy.views.all_fragments', name='all_fragments'),
+    url(r'^userfragments/(?P<username>.*)/$', 'egonomy.views.user_fragments', name='user_fragments'),
 
     # Uncomment the admin/doc line below to enable admin documentation:
     url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
--- a/src/egonomy/views.py	Mon Feb 25 12:25:48 2013 +0100
+++ b/src/egonomy/views.py	Mon Feb 25 13:54:58 2013 +0100
@@ -11,6 +11,7 @@
 from egonomy.search_indexes.query import ModelRelatedSearchQuerySet
 from haystack.query import RelatedSearchQuerySet
 import logging
+from django.contrib.auth.models import User
 
 logger = logging.getLogger(__name__)
 
@@ -165,4 +166,28 @@
                               context_instance=RequestContext(request))
 
 
+def user_fragments(request, username):
+        
+    # Get the cur_page_nb number parameter if possible
+    cur_page_nb = request.GET.get("page") or 1
+    cur_page_nb = int(cur_page_nb)
+    # get the username
+    user = get_object_or_404(User, username=username)
+    
+    frg_list = Fragment.objects.filter(author=user).order_by('-date_saved').select_related('image', 'image__info', 'image__metadata','author')
+    nb = request.GET.get("limit") or getattr(settings,"IMAGES_PER_PAGE", 32)
+    paginator = Paginator(frg_list, nb)
+        
+    try:
+        results = paginator.page(cur_page_nb)
+    except (EmptyPage, InvalidPage):
+        results = paginator.page(paginator.num_pages)
+        
+    url_pagination = reverse("user_fragments", args=[username]) + "?limit=" + str(nb)
 
+    return render_to_response("egonomy_all_fragments.html",
+                              {"user_fragments":True, 'username':username, 'results':results, 'nb_pages':paginator.num_pages, "search":None, 'cur_page_nb':cur_page_nb, "url_pagination":url_pagination},
+                              context_instance=RequestContext(request))
+
+
+