# HG changeset patch # User cavaliet # Date 1354281712 -3600 # Node ID fa742e491ce130a3e466c798e7147e97b6be2dcc # Parent e36c35fb44682a370fc65adefb01302c1de7a4d6 add profile page. diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/models.py --- a/src/hashcut/models.py Thu Nov 29 19:28:10 2012 +0100 +++ b/src/hashcut/models.py Fri Nov 30 14:21:52 2012 +0100 @@ -17,7 +17,7 @@ branding = models.ForeignKey(Branding) def __unicode__(self): - return unicode(self.id) + u"::" + unicode(self.branding.name) + u"::" + unicode(self.project.ldt_id) + return unicode(self.id) + u"::" + unicode(self.branding.name) + u"::" + unicode(self.project.owner) + u"::" + unicode(self.project.ldt_id) def creator(): #@NoSelf def fget(self): diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/templates/bpi_mashup_hashcut.html --- a/src/hashcut/templates/bpi_mashup_hashcut.html Thu Nov 29 19:28:10 2012 +0100 +++ b/src/hashcut/templates/bpi_mashup_hashcut.html Fri Nov 30 14:21:52 2012 +0100 @@ -27,7 +27,7 @@ -

Hashcut » {{proj.title}}

+

Hashcut » {{proj.title}}

@@ -80,7 +80,7 @@ {% for m in mashups %}
{% thumbnail m.project.image "142x95" crop="center" format="PNG" as im %}{% empty %} {% endthumbnail %} -

{% if m.project.title|length > 30 %}{{m.project.title|slice:":30"}}...{% else %}{{m.project.title}}{% endif %} par {{ m.creator }} | 02:24

+

{% if m.project.title|length > 30 %}{{m.project.title|slice:":30"}}...{% else %}{{m.project.title}}{% endif %} par {{ m.creator }} | 02:24

{% endfor %} diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/templates/bpi_mashup_profile.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hashcut/templates/bpi_mashup_profile.html Fri Nov 30 14:21:52 2012 +0100 @@ -0,0 +1,51 @@ +{% extends "bpi_mashup_home.html" %} +{% load static %} +{% load i18n %} +{% load analytics %} +{% load thumbnail %} + {% block title %}Hashcut Profile - BPI{% endblock %} + {% block css_page %} + + {% endblock %} + +{% block wrap_header %} +
+
+ {% include 'partial/bpi_mashup_popin_user.html' %} + {% include 'partial/bpi_hashcut_logo.html' %} +
+ +
+
+{% endblock %} + +{% block content %} +
+

Hashcuts de {{username}}

+ +
+ {% for m in mashups %} +
+ {% thumbnail m.project.image "302x202" crop="center" format="PNG" as im %}{% empty %} {% endthumbnail %} +

{% if m.project.title|length > 30 %}{{m.project.title|slice:":30"}}...{% else %}{{m.project.title}}{% endif %} par {{ m.creator }} | 02:24

+
+ {% endfor %} +
+ +
+{% endblock %} + diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/templates/iri_mashup_hashcut.html --- a/src/hashcut/templates/iri_mashup_hashcut.html Thu Nov 29 19:28:10 2012 +0100 +++ b/src/hashcut/templates/iri_mashup_hashcut.html Fri Nov 30 14:21:52 2012 +0100 @@ -27,7 +27,7 @@ -

Hashcut » {{proj.title}}

+

Hashcut » {{proj.title}}

@@ -80,7 +80,7 @@ {% for m in mashups %}
{% thumbnail m.project.image "142x95" crop="center" format="PNG" as im %}{% empty %} {% endthumbnail %} -

{% if m.project.title|length > 30 %}{{m.project.title|slice:":30"}}...{% else %}{{m.project.title}}{% endif %} par {{ m.creator }} | 02:24

+

{% if m.project.title|length > 30 %}{{m.project.title|slice:":30"}}...{% else %}{{m.project.title}}{% endif %} par {{ m.creator }} | 02:24

{% endfor %} diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/templates/iri_mashup_profile.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hashcut/templates/iri_mashup_profile.html Fri Nov 30 14:21:52 2012 +0100 @@ -0,0 +1,51 @@ +{% extends "iri_mashup_home.html" %} +{% load static %} +{% load i18n %} +{% load analytics %} +{% load thumbnail %} + {% block title %}Hashcut Profile - IRI{% endblock %} + {% block css_page %} + + {% endblock %} + +{% block wrap_header %} +
+
+ {% include 'partial/iri_mashup_popin_user.html' %} + {% include 'partial/iri_hashcut_logo.html' %} +
+ +
+
+{% endblock %} + +{% block content %} +
+

Hashcuts de {{username}}

+ +
+ {% for m in mashups %} +
+ {% thumbnail m.project.image "302x202" crop="center" format="PNG" as im %}{% empty %} {% endthumbnail %} +

{% if m.project.title|length > 30 %}{{m.project.title|slice:":30"}}...{% else %}{{m.project.title}}{% endif %} par {{ m.creator }} | 02:24

+
+ {% endfor %} +
+ +
+{% endblock %} + diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/templates/partial/bpi_mashup_popin_user.html --- a/src/hashcut/templates/partial/bpi_mashup_popin_user.html Thu Nov 29 19:28:10 2012 +0100 +++ b/src/hashcut/templates/partial/bpi_mashup_popin_user.html Fri Nov 30 14:21:52 2012 +0100 @@ -5,7 +5,7 @@

{{creator}}

{{email_creator}}

- {{nb_mashup_creator}} Hashcuts + {{nb_mashup_creator}} Hashcuts

diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/templates/partial/iri_mashup_popin_user.html --- a/src/hashcut/templates/partial/iri_mashup_popin_user.html Thu Nov 29 19:28:10 2012 +0100 +++ b/src/hashcut/templates/partial/iri_mashup_popin_user.html Fri Nov 30 14:21:52 2012 +0100 @@ -5,7 +5,7 @@

{{creator}}

{{email_creator}}

- {{nb_mashup_creator}} Hashcuts + {{nb_mashup_creator}} Hashcuts

diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/urls.py --- a/src/hashcut/urls.py Thu Nov 29 19:28:10 2012 +0100 +++ b/src/hashcut/urls.py Fri Nov 30 14:21:52 2012 +0100 @@ -1,11 +1,12 @@ from django.conf.urls.defaults import patterns, url -from hashcut.views import MashupHome, MashupEdit, MashupHashcut, MashupContent +from hashcut.views import MashupHome, MashupEdit, MashupHashcut, MashupContent, MashupProfile urlpatterns = patterns('', url(r'^(?P.*)/edit/$', MashupEdit.as_view(), name="mashup_edit"), url(r'^(?P.*)/save/$', 'hashcut.views.save_mashup', name="mashup_save"), url(r'^(?P.*)/hashcut/(?P.*)/$', MashupHashcut.as_view(), name="mashup_hashcut"), url(r'^(?P.*)/media/(?P.*)/$', MashupContent.as_view(), name="mashup_content"), + url(r'^(?P.*)/profile/(?P.*)/$', MashupProfile.as_view(), name="mashup_profile"), url(r'^(?P.*)/$', MashupHome.as_view(), name="mashup_home"), url(r'^$', MashupHome.as_view()), ) diff -r e36c35fb4468 -r fa742e491ce1 src/hashcut/views.py --- a/src/hashcut/views.py Thu Nov 29 19:28:10 2012 +0100 +++ b/src/hashcut/views.py Fri Nov 30 14:21:52 2012 +0100 @@ -5,6 +5,7 @@ from ldt.ldt_utils.models import Project, Content import logging from hashcut.models import Mashup, Branding +from django.contrib.auth.models import User class MashupContextView(View): @@ -108,7 +109,6 @@ if rtrn and rtrn['Location']: # The api return the api location of the created project (i.e. /a/b/ldt_id/). So we just get the id to get the project object. proj_ldt_id = rtrn['Location'].split("/")[-2] - proj = None try: proj = Project.objects.get(ldt_id=proj_ldt_id) except Project.DoesNotExist: @@ -150,7 +150,10 @@ self.branding = branding if not ldt_id: return HttpResponseNotFound("A project id must be given.") - proj = Project.objects.get(ldt_id=ldt_id) + try: + proj = Project.objects.get(ldt_id=ldt_id) + except Project.DoesNotExist: + raise ObjectDoesNotExist("MashupHashcut : project not found. project_ldt_id = " + ldt_id) context = self.get_context_dict(request) context.update({"ldt_id":ldt_id, "proj": proj}) return self.render_to_response(context) @@ -184,14 +187,53 @@ self.branding = branding if not ctt_id: return HttpResponseNotFound("A content id must be given.") - content = Content.objects.get(iri_id=ctt_id) + try: + content = Content.objects.get(iri_id=ctt_id) + except Content.DoesNotExist: + raise ObjectDoesNotExist("MashupContent : content not found. ctt_id = " + ctt_id) context = self.get_context_dict(request) context.update({"ctt_id":ctt_id, "content": content}) return self.render_to_response(context) + + +class MashupProfile(TemplateResponseMixin, MashupContextView): + # iri = default brand name + branding = "iri" + template_suffix = "mashup_profile.html" + template_name = "iri_mashup_profile.html" + def get_template_names(self): + """ + Return a list of template names to be used for the request. Must return + a list. May not be called if get_template is overridden. + """ + try: + names = super(MashupProfile, self).get_template_names() + except ImproperlyConfigured: + raise ImproperlyConfigured("Class MashupContent requires either a definition of 'template_name'") + + # the branding template is supposed to override the default template. So we insert instead of append + if self.branding and self.branding != "": + names.insert(0,"%s_%s" % (self.branding, self.template_suffix)) + + return names + def get(self, request, branding="iri", username=None, **kwargs): + self.branding = branding + if not username or username=="": + return HttpResponseNotFound("A username must be given.") + brd = Branding.objects.get(name=self.branding) + try: + user = User.objects.get(username=username) + except: + return HttpResponseNotFound("User not found.") + mashups = Mashup.objects.filter(branding=brd, project__owner=user) + + context = self.get_context_dict(request) + context.update({"username":username, "mashups":mashups}) + return self.render_to_response(context) \ No newline at end of file