aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README32
-rw-r--r--piccast/feeds/__init__.py0
-rw-r--r--piccast/feeds/admin.py7
-rw-r--r--piccast/feeds/models.py54
-rw-r--r--piccast/feeds/tests.py23
-rw-r--r--piccast/feeds/views.py35
-rw-r--r--piccast/settings.py.example5
-rw-r--r--piccast/urls.py27
8 files changed, 172 insertions, 11 deletions
diff --git a/README b/README
index 66170c3..3197524 100644
--- a/README
+++ b/README
@@ -1,3 +1,31 @@
-Piccast README
---------------
+PicCast Repo README
+-------------------
+
+./www/
+ Static content to be served up over HTTP (eg, stylesheets)
+
+./piccast/
+ Django application base directory
+
+./doc/
+ Project documentation
+
+./scripts/
+ Misc scripts
+
+
+Requirements
+-------------
+The django application requires:
+ - django 1.1
+ - python-docutils
+ - python 2.6+ (I think? with pysqlite or whatevah?)
+
+JSON API
+--------
+/json/feeds/
+/json/sets_by_feed/<feed_id>/
+/json/sets_by_feed/<feed_shortname>/
+/json/pics_by_set/<set_id>/
+
diff --git a/piccast/feeds/__init__.py b/piccast/feeds/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/piccast/feeds/__init__.py
diff --git a/piccast/feeds/admin.py b/piccast/feeds/admin.py
new file mode 100644
index 0000000..b25f40d
--- /dev/null
+++ b/piccast/feeds/admin.py
@@ -0,0 +1,7 @@
+from django.contrib import admin
+from piccast.feeds.models import *
+
+admin.site.register(Category)
+admin.site.register(PicFeed)
+admin.site.register(PicSet)
+admin.site.register(Pic)
diff --git a/piccast/feeds/models.py b/piccast/feeds/models.py
new file mode 100644
index 0000000..925bc87
--- /dev/null
+++ b/piccast/feeds/models.py
@@ -0,0 +1,54 @@
+from django.db import models
+
+class Category(models.Model):
+ #id
+ name = models.CharField(max_length=50);
+
+ def __unicode__(self):
+ return self.name
+
+class PicFeed(models.Model):
+ #id
+ created = models.DateTimeField()
+ shortname = models.SlugField(blank=False)
+ source_url = models.URLField(blank=True)
+ rssfeed_url = models.URLField(blank=True)
+ title = models.CharField(max_length=80, blank=True)
+ description = models.TextField(blank=True)
+ image = models.ForeignKey('feeds.Pic', blank=True, null=True)
+
+ def __unicode__(self):
+ return self.shortname
+
+class PicSet(models.Model):
+ #id
+ created = models.DateTimeField(null=True,blank=True)
+ source_url = models.URLField(blank=True)
+ title = models.CharField(max_length=128, blank=False)
+ description = models.TextField(blank=True)
+ keywords = models.CharField(max_length=256, blank=True)
+ image = models.ForeignKey('feeds.Pic', null=True,blank=True)
+ feed = models.ForeignKey('feeds.PicFeed', null=True,blank=False)
+ category = models.ForeignKey('feeds.Category', null=True,blank=True)
+ is_nsfw = models.BooleanField(default=False, blank=False);
+
+ def __unicode__(self):
+ return self.title
+
+class Pic(models.Model):
+ #id
+ set = models.ForeignKey('feeds.PicSet', null=True,blank=True)
+ title = models.CharField(max_length=128, blank=False)
+ thumbnail_url = models.URLField(blank=True)
+ thumbnail_height = models.PositiveIntegerField(null=True,blank=True)
+ thumbnail_width = models.PositiveIntegerField(null=True,blank=True)
+ original_url = models.URLField(blank=False)
+ original_height = models.PositiveIntegerField(null=True,blank=True)
+ original_width = models.PositiveIntegerField(null=True,blank=True)
+ source_url = models.URLField(blank=True)
+ caption = models.TextField(blank=True)
+ is_nsfw = models.NullBooleanField(null=True, blank=True)
+
+ def __unicode__(self):
+ return self.title
+
diff --git a/piccast/feeds/tests.py b/piccast/feeds/tests.py
new file mode 100644
index 0000000..2247054
--- /dev/null
+++ b/piccast/feeds/tests.py
@@ -0,0 +1,23 @@
+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+
diff --git a/piccast/feeds/views.py b/piccast/feeds/views.py
new file mode 100644
index 0000000..4a80144
--- /dev/null
+++ b/piccast/feeds/views.py
@@ -0,0 +1,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")
+
diff --git a/piccast/settings.py.example b/piccast/settings.py.example
index 6d251a1..23118be 100644
--- a/piccast/settings.py.example
+++ b/piccast/settings.py.example
@@ -69,6 +69,7 @@ TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
+ './templates',
)
INSTALLED_APPS = (
@@ -76,4 +77,8 @@ INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
+ 'django.contrib.admin',
+ 'django.contrib.admindocs',
+ 'django.contrib.databrowse',
+ 'piccast.feeds',
)
diff --git a/piccast/urls.py b/piccast/urls.py
index 5dfdaa3..c1e9917 100644
--- a/piccast/urls.py
+++ b/piccast/urls.py
@@ -1,17 +1,26 @@
from django.conf.urls.defaults import *
+from django.contrib import databrowse
+from piccast.feeds.models import *
# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
+from django.contrib import admin
+admin.autodiscover()
+
+databrowse.site.register(PicFeed)
+databrowse.site.register(PicSet)
+#databrowse.site.register(Pic)
+#databrowse.site.register(Category)
urlpatterns = patterns('',
- # Example:
- # (r'^piccast/', include('piccast.foo.urls')),
+ (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+ (r'^admin/', include(admin.site.urls)),
+ (r'^browse/(.*)', databrowse.site.root),
- # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
- # to INSTALLED_APPS to enable admin documentation:
- # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+ # not using this subdirectory scheme; I like to have it all at the toplevel
+ # (r'^piccast/', include('piccast.foo.urls')),
- # Uncomment the next line to enable the admin:
- # (r'^admin/', include(admin.site.urls)),
+ (r'^json/feeds/', 'feeds.views.newest_feeds'),
+ (r'^json/pics_by_set/(\d+)/', 'feeds.views.pics_by_set'),
+ (r'^json/sets_by_feed/(\d+)/', 'feeds.views.sets_by_feed'),
+ (r'^json/sets_by_feed/([-\w]+)/', 'feeds.views.sets_by_feedslug'),
)