Skip to content

Commit

Permalink
latest videos sidebar and rss feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Razzhivin committed Mar 10, 2012
1 parent 8fdfb11 commit d6e4387
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 5 deletions.
3 changes: 2 additions & 1 deletion videopages/conf/settings.py
Expand Up @@ -12,4 +12,5 @@
THUMBNAIL_WIDTH = getattr(settings, 'VIDEO_PAGES_THUMBNAIL_WIDTH', 160)
THUMBNAIL_HEIGHT = getattr(settings, 'VIDEO_PAGES_THUMBNAIL_HEIGHT', 80)
THUMBNAIL_CROP_TYPE = getattr(settings, 'VIDEO_PAGES_THUMBNAIL_CROP_TYPE', 'smart')
RANDOM_SLUG_LENGTH = getattr(settings, 'VIDEO_PAGES_RANDOM_SLUG_LENGTH', 10)
RANDOM_SLUG_LENGTH = getattr(settings, 'VIDEO_PAGES_RANDOM_SLUG_LENGTH', 10)
LATEST_VIDEOS_LIMIT = getattr(settings, 'VIDEO_PAGES_LATEST_VIDEOS_LIMIT', 15)
13 changes: 13 additions & 0 deletions videopages/context_processors.py
@@ -0,0 +1,13 @@
# -*- coding: UTF-8 -*-
from django.db.models.query_utils import Q
from conf.settings import LATEST_VIDEOS_LIMIT
from models import VideoPage


__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


def latest_users_videos(request):
result = VideoPage.not_removed_objects.latest_videos_filter()
return {'latest_users_videos': result}
5 changes: 5 additions & 0 deletions videopages/managers.py
@@ -1,5 +1,7 @@
# -*- coding: UTF-8 -*-
from django.db import models
from django.db.models.query_utils import Q
from videopages.conf.settings import LATEST_VIDEOS_LIMIT

__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'
Expand All @@ -10,3 +12,6 @@ class NotRemovedVideoPageManager(models.Manager):
def get_query_set(self):
return super(NotRemovedVideoPageManager, self).get_query_set().filter(removed=False)

def latest_videos_filter(self, *args, **kwargs):
return self.filter(**kwargs).exclude(Q(title__exact='')|Q(slug__exact='')).order_by('-created')[:LATEST_VIDEOS_LIMIT]

2 changes: 1 addition & 1 deletion videopages/models.py
Expand Up @@ -69,4 +69,4 @@ def __unicode__(self):
return u'{0} - {1}'.format(self.author.username, self.slug)

def get_absolute_url(self):
return reverse('videopages_page', args=[self.slug])
return reverse('videopages_page', args=[self.author.username, self.slug])
Binary file modified videopages/static/videopages/img/edit_video.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added videopages/static/videopages/img/rss.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion videopages/templates/videopages/edit_form.html
Expand Up @@ -8,7 +8,8 @@ <h3>{% trans "Edit video page" %}</h3>
<div>
{% get_videos_for videopage as "videos" %}
{% for video in videos %}
{% embed_video video 640x480 %}
<div><i class="icon-remove"></i>{% video_delete_link video %}</div>
<div>{% embed_video video 480x320 %}</div>
{% endfor %}
</div>
<form id="videopage-form" method="post" action="{% url videopages_edit videopage.author.username videopage.slug %}">
Expand Down
20 changes: 20 additions & 0 deletions videopages/templates/videopages/latest_users_videos_sidebar.html
@@ -0,0 +1,20 @@
{% load i18n %}

<script type="text/javascript">
$(document).ready(function() {
$("#latest-users-videos-rss-button").click(function(){
document.location.href='{% url videopages_latest_users_videos %}';
})
});
</script>
<ul class="nav nav-list">
<li class="nav-header">
{% trans 'Latest users videos' %}
<input id="latest-users-videos-rss-button" type="image" name="submit" id="submit" src="{{ STATIC_URL }}videopages/img/rss.png">
</li>
{% for video in latest_users_videos %}
<li>
<a href="{% url videopages_page video.author video.slug %}"><i class="icon-film"></i>{{ video.title }}</a>
</li>
{% endfor %}
</ul>
2 changes: 1 addition & 1 deletion videopages/templates/videopages/list_table.html
Expand Up @@ -14,12 +14,12 @@
</td>
<td>
<h4>
<a href="{% url videopages_user_list videopage.author.username %}"><i class="icon-user"></i>{{ videopage.author.username }} </a>
{% if videopage.title %}
<a href="{% url videopages_page videopage.author.username videopage.slug %}">{{ videopage.title }}</a>
{% else %}
<a href="{% url videopages_edit videopage.author.username videopage.slug %}">{% trans "Edit video title" %}: {{ videopage.slug }}</a>
{% endif %}
[ <a href="{% url videopages_user_list videopage.author.username %}">{{ videopage.author.username }} </a>]
{% if videopage.author == user %}
<a href="{% url videopages_edit videopage.author.username videopage.slug %}">
<img src="{{ STATIC_URL }}videopages/img/edit_video.png" alt="{% trans 'edit video' %}">
Expand Down
2 changes: 1 addition & 1 deletion videopages/templates/videopages/page_inc.html
@@ -1,7 +1,7 @@
{% load video_tags i18n %}

<div class="page-header">
<h2>{{ videopage.title }}
<h2><a href="{% url videopages_user_list videopage.author %}">{{ videopage.author }}</a>{{ videopage.title }}
{% if videopage.author == user %}
<a href="{% url videopages_edit videopage.author.username videopage.slug %}">
<img src="{{ STATIC_URL }}videopages/img/edit_video.png" alt="{% trans 'edit video' %}">
Expand Down
3 changes: 3 additions & 0 deletions videopages/urls.py
@@ -1,6 +1,7 @@
# -*- coding: UTF-8 -*-
from django.conf.urls.defaults import patterns, url
from django.contrib.auth.decorators import login_required, permission_required
from videopages.views.feeds import LatestUsersVideosFeed, LatestUserVideosFeed
from views.remove import remove_page
from views.create import create_page
from videopages.views.edit import EditVideoView
Expand All @@ -13,6 +14,8 @@

urlpatterns = patterns('',
url(r'^$', VideoPageListView.as_view(), name='videopages_list'),
url(r'^rss/$', LatestUsersVideosFeed(), name='videopages_latest_users_videos'),
url(r'^(?P<username>[\w]+)/rss/$', LatestUserVideosFeed(), name='videopages_latest_user_videos'),
url(r'^(?P<username>[\w]+)/edit/(?P<slug>[\w-]+)/$',
permission_required('djangovideos.add_video')(
permission_required('videopages.add_videopage')(login_required(EditVideoView.as_view()))
Expand Down
42 changes: 42 additions & 0 deletions videopages/views/feeds.py
@@ -0,0 +1,42 @@
# -*- coding: UTF-8 -*-
from django.contrib.auth.models import User
from django.contrib.syndication.views import Feed
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext as _
from videopages.models import VideoPage

__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


class LatestUsersVideosFeed(Feed):
title = _("Latest users videos")
link = "/rss/"
description = _("Updates on adding new videos by users")

def item_title(self, item):
return item.title

def item_description(self, item):
return item.description

def items(self):
return VideoPage.not_removed_objects.latest_videos_filter()


class LatestUserVideosFeed(Feed):

def get_object(self, request, username):
return get_object_or_404(User, username=username)

def title(self, obj):
return "%s %s" % (_("Latest published videos by"), obj.username)

def description(self, obj):
return "%s %s" % (_("Updates on adding new videos by"), obj.username)

def link(self, obj):
return obj.get_absolute_url()

def items(self, obj):
return VideoPage.not_removed_objects.latest_videos_filter(author=obj)

0 comments on commit d6e4387

Please sign in to comment.