From 38596ce829139ace25261d6474475816fd714877 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 15 Dec 2012 01:04:00 +0530 Subject: [PATCH] media gallery --- itf/app/models.py | 12 +- itf/itfprofiles/models.py | 2 +- itf/mediagallery/models.py | 4 + itf/mediagallery/urls.py | 4 + itf/mediagallery/views.py | 32 +++++- itf/templates/comments/form.html | 30 ++++- itf/templates/comments/list.html | 11 ++ itf/templates/mediagallery/upload.html | 103 ++++++++++++++++-- .../modules/itfprofiles/production.html | 63 ++++++++--- itf/templates/noel/staticpage.html | 4 +- 10 files changed, 227 insertions(+), 38 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 1b2eb7d..eb8ee73 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -302,6 +302,8 @@ class ItfModel(models.Model): qset = qset.order_by(sort) + hasResults = True + #FIXME: This is a very ugly hack where to make sure the object that is currently selected displays on the current page, we make it the first item and remove it from the qset. if options['object_id'] != False and options['object_id'] != '': object_id = options['object_id'] @@ -312,11 +314,11 @@ class ItfModel(models.Model): except: pass - #Another slight hack - if there are 0 results returned, we set hasResults to False and return the entire queryset, telling the template to display a "No Results Found" message and let the user see all the items in the list. - hasResults = True - if qset.count() == 0: - hasResults = False - qset = kls.get_qset() + else: + #Another slight hack - if there are 0 results returned, we set hasResults to False and return the entire queryset, telling the template to display a "No Results Found" message and let the user see all the items in the list. + if qset.count() == 0: + hasResults = False + qset = kls.get_qset() ''' r0 = options['range'][0] diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index 932a231..e1155d4 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -374,7 +374,7 @@ from scriptbank.models import Script class Production(ItfModel): # user = models.ForeignKey(User) - fts_fields = ['name', 'group__name'] + fts_fields = ['name', 'synopsis', 'group__name', 'director__firstname', 'director__lastname', 'playwright__firstname', 'playwright__lastname', 'anecdotes'] form_names = ['ProductionForm', 'PopupProductionForm'] main_form = 'ProductionForm' added_by = models.ForeignKey(User) diff --git a/itf/mediagallery/models.py b/itf/mediagallery/models.py index ca971ac..4ee8664 100644 --- a/itf/mediagallery/models.py +++ b/itf/mediagallery/models.py @@ -58,6 +58,10 @@ class YoutubeVideo(GalleryItem): def thumbnail(self): return "http://i.ytimg.com/vi/%s/default.jpg" % self.youtube_id + +class GalleryLink(GalleryItem): + url = models.URLField(verify_exists=False, max_length=1024) + #class Video(GalleryItem): # ... diff --git a/itf/mediagallery/urls.py b/itf/mediagallery/urls.py index 8a3b7a6..a794864 100644 --- a/itf/mediagallery/urls.py +++ b/itf/mediagallery/urls.py @@ -9,4 +9,8 @@ urlpatterns = patterns('mediagallery.views', (r'^upload/', 'upload'), (r'^(?P\d+)/chunk', 'chunk'), (r'^add_youtube/(?P\d+)', 'add_youtube'), + (r'^delete_youtube/(?P\d+)', 'delete_youtube'), + (r'^add_link/(?P\d+)', 'add_link'), + (r'^delete_link/(?P\d+)', 'delete_link'), ) + diff --git a/itf/mediagallery/views.py b/itf/mediagallery/views.py index d807109..022d9f9 100644 --- a/itf/mediagallery/views.py +++ b/itf/mediagallery/views.py @@ -27,9 +27,11 @@ def add(request, ctype_id, object_id): def edit(request, id): gallery = get_object_or_404(GalleryAlbum, pk=id) photos = Photo.objects.filter(album=gallery) + youtube_videos = YoutubeVideo.objects.filter(album=gallery) context = RequestContext(request, { 'gallery': gallery, - 'photos': photos + 'photos': photos, + 'youtube_videos': youtube_videos }) return render_to_response("mediagallery/upload.html", context) @@ -81,6 +83,34 @@ def add_youtube(request, id): }) +def delete_youtube(request, id): + video = get_object_or_404(YoutubeVideo, pk=id) + video.delete() + return render_to_json_response({'success': 'true'}) + + +def add_link(request, id): + gallery = get_object_or_404(GalleryAlbum, pk=id) + url = request.GET.get("url", None) + title = request.GET.get("title", url) + if not url: + return render_to_json_response({'error': 'No URL supplied'}) + link = GalleryLink(album=gallery) + link.url = url + link.title = title + link.save() + return render_to_json_response({ + 'id': link.id, + 'title': title, + 'url': url + }) + +def delete_link(request, id): + link = get_object_or_404(GalleryLink, pk=id) + link.delete() + return render_to_json_response({'success': 'true'}) + + @csrf_exempt def upload(request): if request.method == 'POST': diff --git a/itf/templates/comments/form.html b/itf/templates/comments/form.html index 2a9ad55..6624446 100644 --- a/itf/templates/comments/form.html +++ b/itf/templates/comments/form.html @@ -1,17 +1,41 @@ {% load comments i18n %}
{% csrf_token %} + {% comment %} {% if next %}
{% endif %} + {% endcomment %} + +
{% for field in form %} {% if field.is_hidden %}
{{ field }}
{% else %} {% if field.errors %}{{ field.errors }}{% endif %} -

{{ field.label_tag }} {{ field }}

+ {% endifequal %} + + {% ifequal field.name "honeypot" %} +

+ {{ field.label_tag }} {{ field }} +

+ {% endifequal %} {% endif %} + {% endfor %}

diff --git a/itf/templates/comments/list.html b/itf/templates/comments/list.html index 3d4ec1e..9aef0f4 100644 --- a/itf/templates/comments/list.html +++ b/itf/templates/comments/list.html @@ -1,3 +1,13 @@ + +{% for comment in comment_list %} +

+
{{ comment.comment }}
+
-Posted by {{ comment.user.username }} on {{ comment.submit_date }}
+

+
+{% endfor %} + +{% comment %}
{% for comment in comment_list %}
@@ -8,3 +18,4 @@ {% endfor %}
+{% endcomment %} diff --git a/itf/templates/mediagallery/upload.html b/itf/templates/mediagallery/upload.html index 2f9a727..05f59c3 100644 --- a/itf/templates/mediagallery/upload.html +++ b/itf/templates/mediagallery/upload.html @@ -1,8 +1,9 @@ -{% extends 'noel/base.html' %} +{% extends 'noel/staticpage.html' %} {% load thumbnail %} {% block extra_head %} + {{ block.super }}