Added attachment URL shortcuts
This commit is contained in:
parent
66e883c8e5
commit
e1d82b5634
|
@ -1,6 +1,9 @@
|
|||
from django.conf.urls import url
|
||||
|
||||
from .views import ListView, EntryView, EntryLiveEditView, SearchView, RSSView
|
||||
from .views import (
|
||||
ListView,
|
||||
EntryView, EntryAttachmentView, EntryLiveEditView,
|
||||
SearchView, RSSView)
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
@ -28,7 +31,12 @@ urlpatterns = [
|
|||
EntryLiveEditView.as_view(),
|
||||
name='item-liveedit'
|
||||
),
|
||||
|
||||
# Attachment
|
||||
url(
|
||||
r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[\w\-]+)/attachment/(?P<filename>.*)$',
|
||||
EntryAttachmentView.as_view(),
|
||||
name='item'
|
||||
),
|
||||
# RSS
|
||||
url(
|
||||
r'^rss\.xml$',
|
||||
|
|
|
@ -39,7 +39,7 @@ class EntryView(View):
|
|||
section = 'blog'
|
||||
template = 'blog/entry.jinja'
|
||||
|
||||
def get(self, request, year, month, day, slug):
|
||||
def get_object(self, year, month, day, slug):
|
||||
try:
|
||||
filters = {
|
||||
'slug': slug,
|
||||
|
@ -48,10 +48,12 @@ class EntryView(View):
|
|||
'date__day': int(day),
|
||||
}
|
||||
|
||||
item = Entry.objects.get(**filters)
|
||||
return Entry.objects.get(**filters)
|
||||
except Entry.DoesNotExist:
|
||||
raise Http404
|
||||
|
||||
def get(self, request, year, month, day, slug):
|
||||
item = self.get_object(year, month, day, slug)
|
||||
paginator, page = blog_utils.get_paginator(request, item=item)
|
||||
|
||||
self.data['page'] = page
|
||||
|
@ -61,6 +63,15 @@ class EntryView(View):
|
|||
return render(request, self.template, self.data)
|
||||
|
||||
|
||||
class EntryAttachmentView(EntryView):
|
||||
def get(self, request, year, month, day, slug, filename):
|
||||
item = self.get_object(year, month, day, slug)
|
||||
attachment = item.attachments.get(filename=filename)
|
||||
if attachment:
|
||||
return HttpResponseRedirect(attachment.url)
|
||||
raise Http404
|
||||
|
||||
|
||||
class EntryLiveEditView(View):
|
||||
@method_decorator(csrf_exempt)
|
||||
def dispatch(self, *args, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue