summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/blog/urls.py14
-rw-r--r--app/blog/views.py64
-rw-r--r--app/guide/urls.py7
-rw-r--r--app/lib/pagination/templatetags/pagination_tags.py6
-rw-r--r--app/lib/pagination/tests.py2
-rw-r--r--app/locations/urls.py5
-rw-r--r--app/locations/views.py14
-rw-r--r--app/photos/urls.py12
-rw-r--r--app/photos/views.py22
-rw-r--r--app/projects/models/code.py2
-rw-r--r--app/projects/urls.py16
11 files changed, 71 insertions, 93 deletions
diff --git a/app/blog/urls.py b/app/blog/urls.py
index 57a3e7a..6bd6538 100644
--- a/app/blog/urls.py
+++ b/app/blog/urls.py
@@ -1,15 +1,13 @@
-from django.conf.urls.defaults import *
-from django.views.generic.list_detail import object_list
-from django.views.generic.simple import redirect_to
-
+from django.conf.urls import *
+from django.views.generic.base import RedirectView
from blog.models import Entry
-
+from blog.views import BlogEntryListView
urlpatterns = patterns('',
(r'(?P<slug>[-\w]+)/(?P<page>\d+)/$', 'blog.views.entry_list_by_area'),
- (r'(?P<page>\d+)/$', 'blog.views.entry_list'),
- (r'(?P<slug>[-\w]+)/$', redirect_to, {'url': '/writing/%(slug)s/1/'}),
- (r'', redirect_to, {'url': '/writing/1/'}),
+ (r'(?P<page>\d+)/$', BlogEntryListView.as_view()),
+ (r'(?P<slug>[-\w]+)/$', RedirectView.as_view(url="/writing/%(slug)s/1/")),
+ (r'', RedirectView.as_view(url="/writing/1/")),
)
diff --git a/app/blog/views.py b/app/blog/views.py
index e23acff..67b6f41 100644
--- a/app/blog/views.py
+++ b/app/blog/views.py
@@ -1,22 +1,16 @@
from django.shortcuts import render_to_response,get_object_or_404
from django.template import RequestContext
-from django.views.generic.date_based import object_detail
-from django.views.generic.list_detail import object_list
from django.http import Http404
from django.conf import settings
+from django.views.generic import ListView
-
-from blog.models import Entry, Topic
+from blog.models import Entry
from locations.models import Region, Country
from photos.models import Photo, PhotoGallery
-#from chunks.models import Chunk
def home(request):
- qs = Entry.objects.filter(status__exact=1).select_related()[:4]
- #gallery = PhotoGallery.objects.latest()
context = {
- 'object_list': qs,
- #'gallery': gallery
+ 'object_list': Entry.objects.filter(status__exact=1).select_related()[:4]
}
return render_to_response('archives/homepage.html', context, context_instance = RequestContext(request))
@@ -33,56 +27,40 @@ def entry_detail(request, year, month, day, slug):
"""
List of all writing
"""
-def entry_list(request,page):
- request.page_url = '/writing/%d/'
- request.page = int(page)
- try:
- is_build = request.POST['builder']
- extra_context={
- 'page':page,
- 'MEDIA_URL': settings.BAKED_MEDIA_URL
- }
- except KeyError:
- extra_context={'page':page}
- qs = Entry.objects.filter(status__exact=1).order_by('-pub_date').select_related()
- return object_list(request, queryset=qs, template_name='archives/writing.html',extra_context=extra_context)
+class BlogEntryListView(ListView):
+ template_name="archives/writing.html"
+ model = Entry
+ def get_context_data(self, **kwargs):
+ context = super(BlogEntryListView, self).get_context_data(**kwargs)
+ context.update({
+ 'page': self.kwargs['page']
+ })
+ self.request.page_url = '/writing/%d/'
+ self.request.page = self.kwargs['page']
+ return context
"""
-List of all writing
+Grabs entries by region or country
"""
-def topic_list(request,slug,page):
- request.page_url = '/topics/'+slug+'/%d/'
- request.page = int(page)
- topic = Topic.objects.get(slug=slug)
- qs = Entry.objects.filter(status__exact=1,topics=topic).order_by('-pub_date').select_related()
- return object_list(request, queryset=qs, template_name='archives/topics.html',extra_context={'page':page})
-"""
-Grabs entries by region or country
-"""
def entry_list_by_area(request,slug,page):
request.page_url = '/writing/'+slug+'/%d/'
request.page = int(page)
try:
region = Region.objects.get(slug__exact=slug)
qs = Entry.objects.filter(status__exact=1,region = region).order_by('-pub_date')
- except KeyError:
+ except:
region = Country.objects.get(slug__exact=slug)
qs = Entry.objects.filter(status__exact=1,location__state__country = region).order_by('-pub_date')
if not region:
raise Http404
- try:
- is_build = request.POST['builder']
- extra_context={
- 'region': region,
- 'MEDIA_URL': settings.BAKED_MEDIA_URL
- }
- except:
- extra_context={'region': region,}
- return object_list(request, queryset=qs, template_name='archives/writing.html',
- extra_context=extra_context)
+ context = {
+ 'region': region,
+ 'object_list': qs,
+ }
+ return render_to_response("archives/writing.html", context, context_instance=RequestContext(request))
"""
def about(request):
diff --git a/app/guide/urls.py b/app/guide/urls.py
index 75a24e5..52222fd 100644
--- a/app/guide/urls.py
+++ b/app/guide/urls.py
@@ -1,5 +1,6 @@
-from django.conf.urls.defaults import *
-from django.views.generic.simple import redirect_to
+from django.conf.urls import *
+from django.views.generic.base import RedirectView
+
urlpatterns = patterns('',
(r'location/(?P<location>[-\w]+)/(?P<slug>[-\w]+)/$', 'guide.views.guide_detail'),
@@ -7,5 +8,5 @@ urlpatterns = patterns('',
(r'location/$', 'guide.views.location_list'),
(r'(?P<page>\d+)/$', 'guide.views.guide_list'),
(r'(?P<slug>[-\w]+)/$', 'guide.views.guide_detail'),
- (r'', redirect_to, {'url': '/travel-guide/1/'}),
+ (r'', RedirectView.as_view(url="/travel-guide/1/")),
)
diff --git a/app/lib/pagination/templatetags/pagination_tags.py b/app/lib/pagination/templatetags/pagination_tags.py
index ef9bf5e..dd47009 100644
--- a/app/lib/pagination/templatetags/pagination_tags.py
+++ b/app/lib/pagination/templatetags/pagination_tags.py
@@ -218,8 +218,10 @@ def paginate(context, window=DEFAULT_WINDOW):
if 'use_page_path' in context:
to_return['request'] = context['request']
to_return['use_page_path'] = context['use_page_path']
- to_return['prev_page'] = page_obj.previous_page_number()
- to_return['next_page'] = page_obj.next_page_number()
+ if page_obj.has_previous():
+ to_return['prev_page'] = page_obj.previous_page_number()
+ if page_obj.has_next():
+ to_return['next_page'] = page_obj.next_page_number()
getvars = context['request'].GET.copy()
if 'page' in getvars:
diff --git a/app/lib/pagination/tests.py b/app/lib/pagination/tests.py
index 837e55c..ba55c03 100644
--- a/app/lib/pagination/tests.py
+++ b/app/lib/pagination/tests.py
@@ -49,4 +49,4 @@ u'\\n<div class="pagination">...
>>> t.render(Context({'var': range(21), 'request': RequestProxy()}))
u'\\n<div class="pagination">...
>>>
-""" \ No newline at end of file
+"""
diff --git a/app/locations/urls.py b/app/locations/urls.py
index c49e684..0a2a462 100644
--- a/app/locations/urls.py
+++ b/app/locations/urls.py
@@ -1,7 +1,8 @@
+
from django.conf.urls.defaults import *
-from django.views.generic.simple import redirect_to,direct_to_template
urlpatterns = patterns('',
(r'data/(?P<id>\d+)/$', 'locations.views.data_json'),
- (r'^$', direct_to_template, {'template': 'archives/map.html'}),
+ (r'^$', 'locations.views.map_list'),
)
+
diff --git a/app/locations/views.py b/app/locations/views.py
index f360429..234d867 100644
--- a/app/locations/views.py
+++ b/app/locations/views.py
@@ -4,13 +4,23 @@ from django.template import RequestContext
from blog.models import Entry
from locations.models import Location, Country, Region, Route
-def list_view(request):
+def map_list(request):
context = {
'object_list' : Entry.objects.filter(status__exact=1),
'country_list' : Country.objects.filter(visited=True).exclude(name='default'),
+ 'route_list' : Route.objects.all(),
'region_list' : Region.objects.all()
}
return render_to_response('archives/map.html', context, context_instance=RequestContext(request))
+
+def map_data(request):
+ context = {
+ 'object_list' : Entry.objects.filter(status__exact=1),
+ 'route_list' : Route.objects.all(),
+ 'country_list' : Country.objects.filter(visited=True).exclude(name='default'),
+ 'region_list' : Region.objects.all()
+ }
+ return render_to_response('archives/map_data.html', context, context_instance=RequestContext(request))
from projects.shortcuts import render_to_geojson
@@ -22,4 +32,4 @@ def data_json(request, id):
geom_attribute='geometry',
mimetype = 'application/json',
pretty_print=True
- ) \ No newline at end of file
+ )
diff --git a/app/photos/urls.py b/app/photos/urls.py
index d917d85..9ae065d 100644
--- a/app/photos/urls.py
+++ b/app/photos/urls.py
@@ -1,13 +1,11 @@
-from django.conf.urls.defaults import *
-from django.views.generic import list_detail
-from django.views.generic.simple import redirect_to
-
+from django.conf.urls import *
+from django.views.generic.base import RedirectView
urlpatterns = patterns('',
(r'data/(?P<slug>[-\w]+)/$', 'photos.views.photo_json'),
(r'galleries/(?P<slug>[-\w]+)/$', 'photos.views.gallery'),
(r'(?P<page>\d+)/$', 'photos.views.gallery_list'),
- (r'(?P<slug>[-\w]+)/$', redirect_to, {'url': '/photos/%(slug)s/1/'}),
- (r'', redirect_to, {'url': '/photos/1/'}),
-) \ No newline at end of file
+ (r'(?P<slug>[-\w]+)/$', RedirectView.as_view(url="/photos/%(slug)s/1/")),
+ (r'', RedirectView.as_view(url="/photos/1/")),
+)
diff --git a/app/photos/views.py b/app/photos/views.py
index 7d10841..0c413e0 100644
--- a/app/photos/views.py
+++ b/app/photos/views.py
@@ -1,9 +1,8 @@
from django.shortcuts import render_to_response,get_object_or_404
from django.template import RequestContext
-from django.views.generic.list_detail import object_list
from django.http import Http404,HttpResponse
from django.core import serializers
-from django.conf import settings
+
from photos.models import Photo,PhotoGallery
from locations.models import Country, Region
@@ -13,16 +12,11 @@ from locations.models import Country, Region
def gallery_list(request,page):
request.page_url = '/photos/%d/'
request.page = int(page)
- qs = PhotoGallery.objects.all()
- try:
- is_build = request.POST['builder']
- extra_context= {
- 'page':page,
- 'MEDIA_URL': settings.BAKED_MEDIA_URL
+ context = {
+ 'object_list': PhotoGallery.objects.all(),
+ 'page':page,
}
- except KeyError:
- extra_context={'page':page,}
- return object_list(request, queryset=qs, template_name='archives/photos.html',extra_context=extra_context)
+ return render_to_response("archives/photos.html", context, context_instance = RequestContext(request))
def gallery(request,slug):
context = {
@@ -49,10 +43,10 @@ def gallery_list_by_area(request,slug,page):
if not region:
raise Http404
context = {
- 'region': region,
+ 'object_list': qs,
'country_list': Country.objects.filter(visited=True),
'region_list': Region.objects.all(),
+ 'region': region,
'page': page
}
- return object_list(request, queryset=qs, template_name='archives/photos.html',
- extra_context=context)
+ return render_to_response("archives/photos.html", context, context_instance = RequestContext(request))
diff --git a/app/projects/models/code.py b/app/projects/models/code.py
index 62179dc..19de428 100644
--- a/app/projects/models/code.py
+++ b/app/projects/models/code.py
@@ -1,7 +1,7 @@
import datetime
from django.db import models
-from utils import markdown2 asfaccount.coms markdown
+from utils import markdown2 as markdown
PUB_STATUS = (
(0, 'Draft'),
(1, 'Published'),
diff --git a/app/projects/urls.py b/app/projects/urls.py
index f4d692c..bd7c13d 100644
--- a/app/projects/urls.py
+++ b/app/projects/urls.py
@@ -1,19 +1,15 @@
-from django.conf.urls.defaults import *
-from django.views.generic.list_detail import object_list
-from django.views.generic.simple import redirect_to,direct_to_template
-from django.views.generic import list_detail
-
+from django.conf.urls import *
+from django.views.generic import ListView
from projects.models.base import Project
-projects = {
- 'queryset': Project.objects.filter(status__exact=1).order_by('-pub_date'),
-}
urlpatterns = patterns('',
(r'data/(?P<id>\d+)/$', 'projects.views.data_json'),
(r'gifs/(?P<slug>[-\w]+)/$', 'projects.views.gif_detail'),
- (r'code/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'projects.views.code_entry_detail'),
(r'(?P<slug>[-\w]+)/$', 'projects.views.detail'),
- (r'^$',list_detail.object_list, dict(projects, template_name='archives/projects.html')),
+ (r'^$', ListView.as_view(
+ queryset=Project.objects.filter(status__exact=1).order_by('-pub_date'),
+ template_name = "archives/projects.html",
+ )),
)