aboutsummaryrefslogtreecommitdiffstats
path: root/piccast/feeds/views.py
blob: 4a80144198ac50be018ee89d41c7ff800eff7cb8 (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
from django.http import HttpResponse
from django.core import serializers
from models import *

JSONSerializer = serializers.get_serializer("json")

def newest_feeds(request):
    feeds = PicFeed.objects.order_by('-created')[:20]
    json_serializer = JSONSerializer()
    json_serializer.serialize(feeds)
    return HttpResponse(json_serializer.getvalue(), mimetype="application/json")

def sets_by_feed(request, req_feed):
    # TODO: validate req_feed
    sets = PicSet.objects.filter(feed=req_feed)
    json_serializer = JSONSerializer()
    json_serializer.serialize(sets)
    return HttpResponse(json_serializer.getvalue(), mimetype="application/json")

def sets_by_feedslug(request, req_feedslug):
    # TODO: validate req_feedslug
    feed = PicFeed.objects.filter(shortname=req_feedslug)
    sets = PicSet.objects.filter(feed=feed)
    json_serializer = JSONSerializer()
    json_serializer.serialize(sets)
    return HttpResponse(json_serializer.getvalue(), mimetype="application/json")


def pics_by_set(request, req_picset):
    # TODO: validate req_picset
    pics = Pic.objects.filter(set=req_picset)
    json_serializer = JSONSerializer()
    json_serializer.serialize(pics)
    return HttpResponse(json_serializer.getvalue(), mimetype="application/json")