media gallery

This commit is contained in:
Sanj 2012-12-15 01:04:00 +05:30
parent 6bfa53f1dc
commit 38596ce829
10 changed files with 227 additions and 38 deletions

View File

@ -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]

View File

@ -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)

View File

@ -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):
# ...

View File

@ -9,4 +9,8 @@ urlpatterns = patterns('mediagallery.views',
(r'^upload/', 'upload'),
(r'^(?P<id>\d+)/chunk', 'chunk'),
(r'^add_youtube/(?P<id>\d+)', 'add_youtube'),
(r'^delete_youtube/(?P<id>\d+)', 'delete_youtube'),
(r'^add_link/(?P<id>\d+)', 'add_link'),
(r'^delete_link/(?P<id>\d+)', 'delete_link'),
)

View File

@ -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':

View File

@ -1,17 +1,41 @@
{% load comments i18n %}
<form action="{% comment_form_target %}" method="post">{% csrf_token %}
{% comment %}
{% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
{% endcomment %}
<div><input type="hidden" name="next" value="{{ obj.get_absolute_url }}" /></div>
{% for field in form %}
{% if field.is_hidden %}
<div>{{ field }}</div>
{% else %}
{% if field.errors %}{{ field.errors }}{% endif %}
<p
{% if field.errors %} class="error"{% endif %}
{% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
{% ifequal field.name "name" %}
<input type="hidden" name="{{ field.name }}" id="id_{{field.name}}" value="{{ request.user.username }}" />
{% endifequal %}
{% ifequal field.name "email" %}
<input type="hidden" name="{{ field.name }}" id="id_{{field.name}}" value="{% if request.user.email %}{{ request.user.email }} {% else %}anonymous@anonymous.com{% endif %}" />
{% endifequal %}
{% ifequal field.name "url" %}
<input type="hidden" name="{{ field.name }}" id="id_{{ field.name }}" value="{{ request.user.person_set.all.0.get_absolute_url }}" />
{% endifequal %}
{% ifequal field.name "comment" %}
<p>
{{ field.label_tag }} {{ field }}
</p>
{% endifequal %}
{% ifequal field.name "honeypot" %}
<p style="display:none;">
{{ field.label_tag }} {{ field }}
</p>
{% endifequal %}
{% endif %}
{% endfor %}
<p class="submit">
<input type="submit" name="post" class="submit-post" value="{% trans "Post" %}" />

View File

@ -1,3 +1,13 @@
{% for comment in comment_list %}
<div class="borderYellow" id="comment{{ comment.id }}">
<div>{{ comment.comment }}</div>
<div class="rightFloat">-Posted by <a href="{{ comment.user.person_set.only.0.get_absolute_url }}">{{ comment.user.username }}</a> on {{ comment.submit_date }}</div>
<br /><br />
</div>
{% endfor %}
{% comment %}
<dl id="comments">
{% for comment in comment_list %}
<dt id="c{{ comment.id }}">
@ -8,3 +18,4 @@
</dd>
{% endfor %}
</dl>
{% endcomment %}

View File

@ -1,8 +1,9 @@
{% extends 'noel/base.html' %}
{% extends 'noel/staticpage.html' %}
{% load thumbnail %}
{% block extra_head %}
{{ block.super }}
<script src="/static/js/upload/chunkupload.js"></script>
<script src="/static/js/upload/itfUpload.js"></script>
<script>
@ -26,6 +27,33 @@ $(function() {
$this.parents('.photoContainer').fadeOut();
});
$('#youtubeVideos').delegate(".deleteVideo", "click", function(e) {
if (!confirm("Are you sure you wish to delete this video?")) {
return false;
}
var $this = $(e.target);
var id = $this.closest('li').attr("data-id");
var url = "/mediagallery/delete_youtube/" + id;
$.get(url, {}, function(response) {
});
$this.closest('li').fadeOut();
});
$('#links').delegate(".deleteLink", "click", function(e) {
if (!confirm("Are you sure you wish to delete this link?")) {
return false;
}
var $this = $(e.target);
var id = $this.closest('li').attr("data-id");
var url = "/mediagallery/delete_link/" + id;
$.get(url, {}, function(response) {
});
$this.closest('li').fadeOut();
});
$('#uploadImages').delegate(".photoTitle", "blur", function(e) {
var $this = $(e.target);
//alert($this.val());
@ -52,10 +80,13 @@ $(function() {
alert("please enter a valid youtube share link");
return;
}
$(this).attr("disabled", "disabled");
$(this).text("Adding...");
var $this = $(this);
$this.attr("disabled", "disabled");
$this.text("Adding...");
var url = "/mediagallery/add_youtube/" + GALLERY_ID;
$.get(url, {'url': yt_url}, function(data) {
$this.removeAttr("disabled");
$this.text("Add");
var $ul = $('#youtubeVideos');
var $li = $('<li />')
.attr("data-id", data.id)
@ -67,9 +98,34 @@ $(function() {
.text("X")
.appendTo($li);
}, "json");
});
$('#addLink').click(function(e) {
e.preventDefault();
var url = $.trim($('#linkURL').val());
if (url === '') {
alert("please enter a link");
return;
}
var $this = $(this);
$this.attr("disabled", "disabled");
var title = prompt("Please enter a title for the link");
var url = "/mediagallery/add_link/" + GALLERY_ID;
$.get(url, {'url': url}, function(data) {
$this.removeAttr("disabled");
var $ul = $('#links');
var $li = $('<li />')
.attr("data-id", data.id)
.appendTo($ul);
var $title = $('<div />').addClass("linkTitle").text(data.title).appendTo($li);
var $url = $('<a />').attr("href", data.url).text(data.url).appendTo($li);
var $delete = $('<span />')
.addClass("deleteLink")
.text("X")
.appendTo($li);
}, "json");
});
});
@ -79,7 +135,6 @@ $(function() {
min-width: 400px;
min-height: 300px;
max-width: 50%;
background: #f00;
}
.progressBar {
@ -91,13 +146,24 @@ $(function() {
font-weight: bold;
cursor: pointer;
}
.section {
margin-bottom: 18px;
}
.section h3 {
font-size: 18px;
text-align: center;
font-weight: bold;
}
</style>
{% endblock %}
{% block content %}
<input class="galleryTitle" value="{{ gallery.title }}" />
{% block main_content %}
Gallery Title: <input class="galleryTitle" value="{{ gallery.title }}" />
<div id="uploadImages">
<div id="uploadImages" class="section">
<h3>Upload Images</h3>
<input type="file" id="uploadImageFiles" multiple />
<ul id="photosContainer">
@ -116,17 +182,36 @@ $(function() {
</ul>
</div>
<div id="addVideos">
<div id="addVideos" class="section">
<h3>Add Youtube Videos</h3>
<div id="addYoutubeVideos">
Youtube Share Link: <input type="text" id="youtubeURL" placeholder="eg. http://youtu.be/Wo_mFYW-jLU" />
<button id="addYoutubeVideo">Add</button>
<ul id="youtubeVideos">
{% for vid in youtube_videos %}
<li data-id="{{ vid.id }}">
<img src="{{ vid.thumbnail }}" />
<div class="videoTitle">{{ vid.title }}</div>
<span class="deleteVideo">X</span>
</li>
{% endfor %}
</ul>
</div>
</div>
<div id="addLinks" class="section">
<h3>Other Links to Online Media</h3>
Link: <input type="text" id="linkURL" placeholder="eg. http://flickr.com/xyz" />
<button id="addLink">Add</button>
<ul id="links">
</ul>
</div>
<a href="Javascript:close()">Done</a>
{% endblock %}

View File

@ -137,28 +137,55 @@ $(function() {
<br />
<a href="" class="rightFloat">More>></a>
<br />
{% load comments %}
<h3 class="orange">Comments</h3>
<div class="borderYellow">
<div>Comments Comments Comments Comments Comments Comments</div>
<div class="rightFloat">-Posted by date, time</div>
<br /><br />
</div>
<div class="borderYellow">
<br />
<div>Comments Comments Comments Comments Comments Comments</div>
<div class="rightFloat">-Posted by date, time</div>
<br /><br />
</div>
{% get_comment_count for obj as comment_count %}
{% if not comment_count %}
<div class="borderYellow">
<div>No comments added yet</div>
</div>
{% else %}
{% render_comment_list for obj %}
<div class="borderYellow">
<br />
<div>Comments Comments Comments Comments Comments Comments</div>
<div class="rightFloat">-Posted by date, time</div>
<br /><br />
{% endif %}
{% if user.is_authenticated %}
<div class="addComments">
<h4>Your comments</h4>
{% render_comment_form for obj %}
</div>
<br />
<a href="" class="rightFloat">More>></a>
{% else %}
<div class="addComments">
Please sign-in to add comments.
</div>
{% endif %}
<!-- <div class="borderYellow">-->
<!-- <div>Comments Comments Comments Comments Comments Comments</div>-->
<!-- <div class="rightFloat">-Posted by date, time</div>-->
<!-- <br /><br />-->
<!-- </div>-->
<!-- <div class="borderYellow">-->
<!-- <br />-->
<!-- <div>Comments Comments Comments Comments Comments Comments</div>-->
<!-- <div class="rightFloat">-Posted by date, time</div>-->
<!-- <br /><br />-->
<!-- </div>-->
<!-- <div class="borderYellow">-->
<!-- <br />-->
<!-- <div>Comments Comments Comments Comments Comments Comments</div>-->
<!-- <div class="rightFloat">-Posted by date, time</div>-->
<!-- <br /><br />-->
<!-- </div>-->
<!-- <br />-->
<!-- <a href="" class="rightFloat">More>></a> -->
</div> <!-- end buzz -->

View File

@ -80,7 +80,8 @@
<div id="shadow">
</div>
<div id="searchContainer">
<div id="searchContainer">
{% block main_content %}
<div id="searchContent">
<p class="staticTitle">{{ page.title }}</p>
{% if page.main_image %}
@ -89,6 +90,7 @@
<div class="markdownText">{{ page.text|markdown }}</div>
</div><!-- SEARCH CONTENT CLOSING -->
{% endblock %}
</div><!-- SEARCH CONTAINER CLOSING -->
</div><!-- CENTER INNER -->
{% endblock %}