From 82e75e0fc379879337cd46a037c18150ab9b6c66 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 3 Jan 2013 00:35:26 +0530 Subject: [PATCH] display videos on front-end + fix sort bug --- itf/app/models.py | 9 ++++ itf/mediagallery/models.py | 48 +++++++++++++++++++ itf/static/css/noel/inner.css | 4 ++ itf/static/js/innertabs.js | 13 ++++- itf/static/js/render_object.js | 28 ++++++----- .../modules/itfprofiles/production.html | 20 +++++++- itf/templates/modules/scriptbank/script.html | 36 +++++++------- 7 files changed, 123 insertions(+), 35 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index eb8ee73..f615bcc 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -94,6 +94,15 @@ class ItfModel(models.Model): return d + def get_videos(self): + from mediagallery.models import YoutubeVideo + + if self.galleries: + qset = Youtube.objects.filter(album__in=self.galleries.all()) + if qset.count() == 0: + return False + return qset[0:9] + #Returns the title for this object, used as title of page, title of object, and by default, title in left hand display. By default, is a field called 'title', but subclasses can over-ride either title field or the get_title method and return anything. def get_title(self): try: diff --git a/itf/mediagallery/models.py b/itf/mediagallery/models.py index 4ee8664..a4c9571 100644 --- a/itf/mediagallery/models.py +++ b/itf/mediagallery/models.py @@ -4,6 +4,7 @@ from ox.django.fields import DictField from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django.core.files.base import ContentFile +from sorl.thumbnail import get_thumbnail class GalleryAlbum(ItfModel): ''' @@ -21,6 +22,25 @@ class GalleryAlbum(ItfModel): def get_edit_url(self): return '/mediagallery/edit/%d' % self.id + def thumbnail(self): + if Photo.objects.filter(album=self).count() == 0: + return None + return Photo.objects.filter(album=self)[0].image + + def get_dict(self): + return { + 'photos': Photo.objects.filter(album=self), + 'videos': YoutubeVideo.objects.filter(album=self), + 'links': GalleryLink.objects.filter(album=self) + } + + def get_json(self): + return { + 'photos': [p.get_dict() for p in Photo.objects.filter(album=self)], + 'videos': [y.get_dict() for y in YoutubeVideo.objects.filter(album=self)], + 'links': [l.get_dict() for l in GalleryLink.objects.filter(album=self)] + } + class GalleryItem(models.Model): title = models.CharField(max_length=512, blank=True, null=True) @@ -48,6 +68,16 @@ class Photo(GalleryItem): return True return False + def get_thumbnail(self, size='100x100'): + return get_thumbnail(self.image, size).url + + def get_dict(self): + return { + 'id': self.id, + 'title': self.title, + 'thumb640': self.get_thumbnail(size='640') + } + class YoutubeVideo(GalleryItem): youtube_id = models.CharField(max_length=64) @@ -58,10 +88,28 @@ class YoutubeVideo(GalleryItem): def thumbnail(self): return "http://i.ytimg.com/vi/%s/default.jpg" % self.youtube_id + def iframe(self): + return '' % self.youtube_id + + def get_dict(self): + return { + 'id': self.id, + 'youtube_id': self.youtube_id, + 'thumbnail': self.thumbnail(), + 'iframe': self.iframe() + } + class GalleryLink(GalleryItem): url = models.URLField(verify_exists=False, max_length=1024) + def get_dict(self): + return { + 'id': self.id, + 'title': self.title, + 'url': self.url + } + #class Video(GalleryItem): # ... diff --git a/itf/static/css/noel/inner.css b/itf/static/css/noel/inner.css index c166d58..20e76a8 100755 --- a/itf/static/css/noel/inner.css +++ b/itf/static/css/noel/inner.css @@ -115,6 +115,10 @@ padding-right:10px; float:left; /*border-bottom:1px solid #f0dfdf;*/} +.tab_content { + display:none; +} + #selection {padding-left:6px; /*border-top:1px solid #f0dfdf;*/ diff --git a/itf/static/js/innertabs.js b/itf/static/js/innertabs.js index bcd25a7..b4e4a68 100644 --- a/itf/static/js/innertabs.js +++ b/itf/static/js/innertabs.js @@ -7,9 +7,18 @@ $(".tab_content").hide(); //Hide all tab content var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content $(activeTab).fadeIn(); //Fade in the active ID content + location.hash = activeTab.replace("#", ""); return false; // var queryData = {}; }); + //$(".tab_content").hide(); //Hide all content + + if (location.hash != '') { + $('a[href=' + location.hash + ']').closest('li').click(); + //console.log('a[href=#' + location.hash + ']'); + } else { + $("ul.tabsInnerRight li:first").click(); + } /* if (queryData.hasOwnProperty("innertab")) { @@ -23,7 +32,7 @@ } */ //When page loads... - $(".tab_content").hide(); //Hide all content - $("ul.tabsInnerRight li:first").click() //addClass("active").show(); //Activate first tab + + //addClass("active").show(); //Activate first tab }); diff --git a/itf/static/js/render_object.js b/itf/static/js/render_object.js index 25bf374..5b05537 100755 --- a/itf/static/js/render_object.js +++ b/itf/static/js/render_object.js @@ -241,18 +241,18 @@ $(function() { $('#listForm').submit(function(e) { return true; // e.preventDefault(); - doListLoading(); - var urlString = "?tab_id=" + $('.innerSelected').attr("data-id") + "&sort=" + sortString + "&search=" + searchTerm; - var formData = getSearchFormJSON(); -// delete(formData.object_id); - var urlString = JSONtoQueryString(formData); -// console.log(urlString); - History.pushState(formData, "", urlString); - $.getJSON("/m/get_list", formData, function(data) { - stopListLoading(data); - displayList(data.items); - $('#object_id').val(''); - }); +// doListLoading(); +// var urlString = "?tab_id=" + $('.innerSelected').attr("data-id") + "&sort=" + sortString + "&search=" + searchTerm; +// var formData = getSearchFormJSON(); +//// delete(formData.object_id); +// var urlString = JSONtoQueryString(formData); +//// console.log(urlString); +// History.pushState(formData, "", urlString); +// $.getJSON("/m/get_list", formData, function(data) { +// stopListLoading(data); +// displayList(data.items); +// $('#object_id').val(''); +// }); }); @@ -270,6 +270,10 @@ $(function() { $('#listForm').submit(); }); + $('#orderBySelect').change(function() { + $('#listForm').submit(); + }); + // var State = History.getState(); // console.log(State); diff --git a/itf/templates/modules/itfprofiles/production.html b/itf/templates/modules/itfprofiles/production.html index 9f2c713..b369534 100644 --- a/itf/templates/modules/itfprofiles/production.html +++ b/itf/templates/modules/itfprofiles/production.html @@ -156,7 +156,22 @@ $(function() { {% if user.is_authenticated %}

Your comments

- {% render_comment_form for obj %} + +
+ {% get_comment_form for obj as form %} +
+ {% csrf_token %} + + {{ form.as_p }} +

+ +

+ +
+ +
{% else %}
@@ -185,7 +200,8 @@ $(function() { - +
diff --git a/itf/templates/modules/scriptbank/script.html b/itf/templates/modules/scriptbank/script.html index b3fe658..97a4327 100755 --- a/itf/templates/modules/scriptbank/script.html +++ b/itf/templates/modules/scriptbank/script.html @@ -15,7 +15,7 @@ $(function() {
  • Productions
  • People
  • Notes
  • -
  • Gallery
  • + {% if obj.galleries.count %}
  • Gallery
  • {% endif %} {% if resources %}
  • Resources
  • {% endif %} @@ -273,29 +273,27 @@ $(function() {

    Photos

    - - - - - - - + {% for g in obj.galleries.all %} + {% thumbnail g.thumbnail "160x120" crop="center" as thumb %} + {{ g.title }} + {% endthumbnail %} + {% endfor %} - More» +

    -
    -

    Videos

    - - - - - - - - More» + {% if obj.get_videos %} +
    +

    Videos

    + {% for v in obj.get_videos %} + + + + {% endfor %} + {% endif %} +