summaryrefslogtreecommitdiff
path: root/app/blog/views.py
blob: 8c86839fc81e2a285724b3a67391a35979010774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import Http404
from django.conf import settings
# from django.views.generic import ListView

from blog.models import Entry
from locations.models import Region, Country
from photos.models import Photo


def home(request):
    context = {
        'object_list': Entry.objects.filter(status__exact=1).select_related()[:4]
    }
    return render_to_response('archives/homepage.html', context, context_instance=RequestContext(request))


def entry_detail(request, year, month, day, slug):
    obj = get_object_or_404(Entry, slug__exact=slug)
    photos = {}
    # if obj.photo_gallery:
    #    photos = Photo.objects.filter(set__exact=obj.get().photo_gallery.id)[:9]
    extra = {'photos': photos, }
    return render_to_response('details/entry.html', {'object': obj, 'photos': photos}, context_instance=RequestContext(request))

"""
List of all writing
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

"""


def entry_list(request, page):
    request.page_url = '/writing/%d/'
    request.page = int(page)
    try:
        extra_context = {
            'page': page,
            'MEDIA_URL': settings.BAKED_MEDIA_URL
        }
    except:
        extra_context = {'page': page}
    context = {
        'object_list': Entry.objects.filter(status__exact=1).order_by('-pub_date').select_related(),
    }
    return render_to_response("archives/writing.html", context, context_instance=RequestContext(request))


def entry_list_by_area(request, slug, page):
    """ Grabs entries by region or country"""
    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:
        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
    context = {
        'region': region,
        'object_list': qs,
    }
    return render_to_response("archives/writing.html", context, context_instance=RequestContext(request))