Source

pentasubmitter / src / submitter / urls.py

# -*- coding: utf-8 -*-

"""
url config for submitter application
"""

from django.conf.urls.defaults import patterns, url
from django.http import Http404
from django.views.generic import RedirectView
from django.utils.translation import ugettext_lazy as _
#from django.views.generic.simple import direct_to_template
from submitter.views import news_per_category, news_per_show, \
        news_entry_create_and_update, entry_category_create_and_update, \
        news_entry_as_json, news_entries_as_json, news_entries_per_show, \
        penta_shows_as_json, news_per_next_show, print_news_per_show, InShowView
from auth.generic import limited_delete_object
from tagging.views import tagged_object_list
from voting.views import vote_on_object
from pentasubmitter.template import set_template_params
from submitter.models import EntryCategory, NewsEntry
from submitter.feeds import LatestNewsEntries, CurrentShowNewsEntries, \
        LatestPentaShows, NewsEntriesPerShow
from submitter.views import get_next_shows

# get next show for redirect
def next_show_slug():
    next_shows = get_next_shows()
    if not next_shows:
        return ""
        raise Http404
    return next_shows[0].slug

urlpatterns = patterns(
    '',
    #('^$', redirect_to, {'url': 'last/'}),
    ('^$', RedirectView.as_view(url='news-per-show/' + next_show_slug(),
                                permanent=False)),
)

news_entry_info_dict = dict(
    queryset=NewsEntry.objects.all(),
    date_field='submit_date',
)

news_entry_info_dict_year = dict(
    news_entry_info_dict,
    make_object_list = True,
)

news_entry_info_dict_month = dict(
    news_entry_info_dict,
    month_format="%m",
)

urlpatterns += patterns(
    '',
    (r'^news-per-next-show/$', news_per_next_show,),
)

urlpatterns += patterns(
    'django.views.generic.date_based',
    (r'^last/$', 'archive_index', news_entry_info_dict, 'archive_index'),
    (r'^(?P<year>\d{4})/$', 'archive_year', news_entry_info_dict_year,
     'entry_archive_year'),
    (r'^(?P<year>\d{4})/(?P<month>\d{2})/$', 'archive_month',
     news_entry_info_dict_month, 'entry_archive_month'),
    (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', 'archive_day',
     news_entry_info_dict_month, 'archive_day'),
    url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/' \
        + '(?P<slug>[-\w]+)/$',
        'object_detail', news_entry_info_dict_month, name='news_entry_detail'),
)

urlpatterns += patterns(
    '',
    (r'^update/(?P<news_entry_id>\d+)$',
     news_entry_create_and_update,),
    (r'^create/(?P<form_type>(full|short))$', news_entry_create_and_update,),
)

urlpatterns += patterns(
    '',
    (r'^delete/(?P<object_id>\d+)$', limited_delete_object, {
        'model': NewsEntry,
        'post_delete_redirect':'/submit/',
        'template_name':'confirm_delete.html',
        'extra_context':set_template_params(
            None,
            'news_entry',
            title_main=_(u"Delete News Entry"),
            title_hints=_(u"Tips"),
        )
    }),
)

# NewsEntry() per NewsCategory()
urlpatterns += patterns(
    '',
    (r'^news_per_category/(?P<category_slug>[-\w]+)$', news_per_category),
)

# NewsEntry() per PentaShow()
urlpatterns += patterns(
    '',
    (r'^news-per-show/(?P<show_slug>[-\w]+)$', news_per_show),
)

# NewsEntry() per PentaShow()
urlpatterns += patterns(
    '',
    (r'^news-per-show/(?P<show_slug>[-\w]+)/print$', print_news_per_show),
)

urlpatterns += patterns(
    '',
    url(r'^in-show/(?P<show_slug>[-\w]+)/$', InShowView.as_view(),
        name="in_show_view"),
    )

# NewsCategory()
category_entry_info_dict = dict(
    queryset=EntryCategory.objects.all(),
)

urlpatterns += patterns(
    'django.views.generic.list_detail',
    url(r'^news-categories/$', 'object_list', category_entry_info_dict,
        name='news_categories'),
)

urlpatterns += patterns('',
    url(r'^news-category/(?P<slug>[-\w]+)/$',
        'object_detail', category_entry_info_dict,
        name='entry_category_detail'),
)

urlpatterns += patterns(
    '',
    (r'^news-category/update/(?P<entry_category_id>\d+)$',
     entry_category_create_and_update,),
    (r'^news-category/create/$', entry_category_create_and_update,),
)

urlpatterns += patterns(
    '',
    (r'^news-category/delete/(?P<object_id>\d+)$', limited_delete_object, {
        'model': EntryCategory,
        'post_delete_redirect':'/submit/news_categories/',
        'template_name':'confirm_delete.html',
        'extra_context':set_template_params(
            None,
            'entry_category',
            title_main=_(u"Delete News Category"),
            title_hints=_(u"Tips"),
        )
    }),
)


# JSON
urlpatterns += patterns(
    '',
    (r'^news-entries/news(?P<news_entry_id>\d+)/$', news_entries_as_json),
    (r'^news-entry/news(?P<news_entry_id>\d+)/$', news_entry_as_json),
    (r'^news-entries-per-show/(?P<penta_show_id>\d+)/$', news_entries_per_show),
    (r'^last-12-pentashows/$', penta_shows_as_json),
)

# Votes
vote_dict = {
    'model': NewsEntry,
    #'template_object_name': 'widget',
    'allow_xmlhttprequest': True,
}

urlpatterns += patterns(
    '',
    (r'^vote/(?P<object_id>\d+)/(?P<direction>up|down|clear)/?$',
     vote_on_object, vote_dict),
)

# Tags
urlpatterns += patterns(
    '',
    url(r'^tag/(?P<tag>[^/]+)/$', tagged_object_list,
        dict(queryset_or_model=NewsEntry, paginate_by=10, allow_empty=True)
       ),
)

# Syndication / RSS / Feeds
feeds = {
    'latest': LatestNewsEntries,
    'current_show': CurrentShowNewsEntries,
    'latest_shows': LatestPentaShows,
    'news_per_show': NewsEntriesPerShow,
}

urlpatterns += patterns(
    '',
    (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
     {'feed_dict': feeds}),
)

#urlpatterns = patterns('',
#   (r'^$', direct_to_template, {'template': 'index.html',
#                                'extra_context': index}),
#)

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8 :
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.