From: Radek Czajka
Date: Fri, 25 Mar 2011 11:33:20 +0000 (+0100)
Subject: Merge commit '645219bfa68384dad930269b94e2ddf8b4cd3488' into api
X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/5207c4d8ee23d6d5df532faa8103a34b1572e45f?hp=645219bfa68384dad930269b94e2ddf8b4cd3488
Merge commit '645219bfa68384dad930269b94e2ddf8b4cd3488' into api
---
diff --git a/apps/api/handlers.py b/apps/api/handlers.py
index 40121d6af..cca504f8f 100644
--- a/apps/api/handlers.py
+++ b/apps/api/handlers.py
@@ -1,17 +1,190 @@
# -*- coding: utf-8 -*-
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
-#
+
+from datetime import datetime
from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required, user_passes_test
+from django.utils import simplejson as json
from piston.handler import BaseHandler
from piston.utils import rc, validate
-from catalogue.models import Book
+
+from api.models import Deleted
+from api.helpers import timestamp
+from catalogue.models import Book, Tag
from catalogue.forms import BookImportForm
+from catalogue.views import tagged_object_list
+"""
+class TagHandler(BaseHandler):
+ allowed_methods = ('GET',)
+ model = Tag
+ def read(self, request, tags=''):
+ if tags == '':
+ return Tag.objects.all()
+ else:
+ return tagged_object_list(request, tags, api=True)
-staff_required = user_passes_test(lambda user: user.is_staff)
+class BookHandler(BaseHandler):
+ model = Book
+ #fields = ('slug', 'title')
+
+ def read(self, request, slug=None):
+ if slug:
+ return get_object_or_404(Book, slug=slug)
+ else:
+ return Book.objects.all()
+"""
+
+
+class WLHandler(BaseHandler):
+
+ @staticmethod
+ def fields(request, name):
+ fields_str = request.GET.get(name) if request is not None else None
+ return fields_str.split(',') if fields_str is not None else None
+
+ @staticmethod
+ def book_dict(book, fields=None, extra_fields=None):
+ obj = {}
+ for field in ('slug', 'title', 'description',
+ 'extra_info', 'gazeta_link', 'wiki_link'):
+ if getattr(book, field):
+ obj[field] = getattr(book, field)
+ for field in ('created_at', 'changed_at'):
+ obj[field] = timestamp(getattr(book, field))
+ for field in ('xml', 'epub', 'txt', 'pdf', 'html'):
+ f = getattr(book, field+'_file')
+ if f:
+ obj[field] = f.url
+ for media in book.medias.all():
+ obj.setdefault(media.type, []).append(media.file.url)
+ if book.parent:
+ obj['parent'] = book.parent.id
+ obj['parent_number'] = book.parent_number
+ if fields is not None:
+ for key in obj.keys():
+ if key not in fields:
+ del obj[key]
+
+ # if there's still extra_info, we can parse it
+ if 'extra_info' in obj:
+ extra = json.loads(obj['extra_info'])
+ if extra_fields is not None:
+ for key in extra.keys():
+ if key not in extra_fields:
+ del extra[key]
+ obj['extra_info'] = extra
+
+ obj['id'] = book.id
+ return obj
+
+ @classmethod
+ def book_changes(cls, since=0, request=None):
+ since = datetime.fromtimestamp(float(since))
+ book_fields = cls.fields(request, 'book_fields')
+ extra_fields = cls.fields(request, 'extra_fields')
+
+ added = []
+ changed = []
+ deleted = []
+
+ last_change = since
+ for book in Book.objects.filter(changed_at__gt=since):
+ if book.changed_at > last_change:
+ last_change = book.changed_at
+ book_d = cls.book_dict(book, book_fields, extra_fields)
+ if book.created_at > since:
+ added.append(book_d)
+ else:
+ changed.append(book_d)
+ for book in Deleted.objects.filter(type='Book', deleted_at__gt=since, created_at__lte=since):
+ if book.deleted_at > last_change:
+ last_change = book.deleted_at
+ deleted.append(book.id)
+ return {'added': added, 'changed': changed, 'deleted': deleted, 'last_change': timestamp(last_change)}
+
+ @staticmethod
+ def tag_dict(tag, fields=None):
+ obj = {}
+ for field in ('name', 'slug', 'sort_key', 'category', 'description', 'main_page', #'created_at', 'changed_at',
+ 'gazeta_link', 'wiki_link'):
+ if getattr(tag, field):
+ obj[field] = getattr(tag, field)
+ if fields is not None:
+ for key in obj.keys():
+ if key not in fields:
+ del obj[key]
+ obj['id'] = tag.id
+ return obj
+
+ @classmethod
+ def tag_changes(cls, since=0, request=None):
+ since = datetime.fromtimestamp(float(since))
+ tag_fields = cls.fields(request, 'tag_fields')
+
+ added = []
+ changed = []
+ deleted = []
+
+ last_change = since
+ for tag in Tag.objects.filter(changed_at__gt=since):
+ if tag.changed_at > last_change:
+ last_change = tag.changed_at
+ tag_d = cls.tag_dict(tag, tag_fields)
+ if tag.created_at > since:
+ added.append(tag_d)
+ else:
+ changed.append(tag_d)
+
+ for tag in Deleted.objects.filter(type='Tag', deleted_at__gt=since, created_at__lte=since):
+ if tag.deleted_at > last_change:
+ last_change = tag.deleted_at
+ deleted.append(tag.id)
+ return {'added': added, 'changed': changed, 'deleted': deleted, 'last_change': timestamp(last_change)}
+
+
+class BookChangesHandler(WLHandler):
+ allowed_methods = ('GET',)
+
+ def read(self, request, since):
+ return self.book_changes(since, request)
+
+
+class TagChangesHandler(WLHandler):
+ allowed_methods = ('GET',)
+
+ def read(self, request, since):
+ return self.tag_changes(since, request)
+
+
+class ChangesHandler(WLHandler):
+ allowed_methods = ('GET',)
+
+ def read(self, request, since):
+ changes = {
+ 'books': self.book_changes(since, request),
+ 'tags': self.tag_changes(since, request),
+ }
+
+ last_change = 0
+ changes_rev = {}
+ for model in changes:
+ for field in changes[model]:
+ if field == 'last_change':
+ if changes[model][field] > last_change:
+ last_change = changes[model][field]
+ else:
+ changes_rev.setdefault(field, {})[model] = changes[model][field]
+ changes_rev['last_change'] = last_change
+ return changes_rev
+
+
+
+# old
+"""
+staff_required = user_passes_test(lambda user: user.is_staff)
class BookHandler(BaseHandler):
model = Book
@@ -32,4 +205,4 @@ class BookHandler(BaseHandler):
return rc.CREATED
else:
return rc.BAD_REQUEST
-
+"""
diff --git a/apps/api/helpers.py b/apps/api/helpers.py
new file mode 100644
index 000000000..f01522aa7
--- /dev/null
+++ b/apps/api/helpers.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+from time import mktime
+
+def timestamp(dtime):
+ "converts a datetime.datetime object to a timestamp with fractional part"
+ return mktime(dtime.timetuple()) + dtime.microsecond / 1000000.0
+
diff --git a/apps/api/migrations/0001_initial.py b/apps/api/migrations/0001_initial.py
new file mode 100644
index 000000000..6ac0f5487
--- /dev/null
+++ b/apps/api/migrations/0001_initial.py
@@ -0,0 +1,45 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding model 'Deleted'
+ db.create_table('api_deleted', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('object_id', self.gf('django.db.models.fields.IntegerField')()),
+ ('type', self.gf('django.db.models.fields.CharField')(max_length='50')),
+ ('created_at', self.gf('django.db.models.fields.DateTimeField')()),
+ ('deleted_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+ ))
+ db.send_create_signal('api', ['Deleted'])
+
+ # Adding unique constraint on 'Deleted', fields ['type', 'object_id']
+ db.create_unique('api_deleted', ['type', 'object_id'])
+
+
+ def backwards(self, orm):
+
+ # Removing unique constraint on 'Deleted', fields ['type', 'object_id']
+ db.delete_unique('api_deleted', ['type', 'object_id'])
+
+ # Deleting model 'Deleted'
+ db.delete_table('api_deleted')
+
+
+ models = {
+ 'api.deleted': {
+ 'Meta': {'unique_together': "(('type', 'object_id'),)", 'object_name': 'Deleted'},
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {}),
+ 'deleted_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'object_id': ('django.db.models.fields.IntegerField', [], {}),
+ 'type': ('django.db.models.fields.CharField', [], {'max_length': "'50'"})
+ }
+ }
+
+ complete_apps = ['api']
diff --git a/apps/api/migrations/__init__.py b/apps/api/migrations/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/apps/api/models.py b/apps/api/models.py
new file mode 100644
index 000000000..8858162e6
--- /dev/null
+++ b/apps/api/models.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from django.db import models
+from django.db.models.signals import pre_delete
+
+from catalogue.models import Book, Tag
+
+
+class Deleted(models.Model):
+ object_id = models.IntegerField()
+ type = models.CharField(max_length="50", db_index=True)
+ created_at = models.DateTimeField(editable=False, db_index=True)
+ deleted_at = models.DateTimeField(auto_now_add=True, db_index=True)
+
+ class Meta:
+ unique_together = (('type', 'object_id'),)
+
+
+
+def _pre_delete_handler(sender, instance, **kwargs):
+ """ save deleted objects for change history purposes """
+
+ if sender in (Book, Tag):
+ Deleted.objects.create(type=sender.__name__, object_id=instance.id, created_at=instance.created_at)
+pre_delete.connect(_pre_delete_handler)
diff --git a/apps/api/tests.py b/apps/api/tests.py
new file mode 100644
index 000000000..e3dd71ad0
--- /dev/null
+++ b/apps/api/tests.py
@@ -0,0 +1,108 @@
+# -*- coding: utf-8 -*-
+
+from datetime import datetime
+
+from django.test import TestCase
+from django.utils import simplejson as json
+
+from api.helpers import timestamp
+from catalogue.models import Book, Tag
+
+
+class ChangesTests(TestCase):
+
+ def test_basic(self):
+ book = Book.objects.create(slug='a-book', title='A Book')
+ tag = Tag.objects.create(category='author', slug='author', name='Author')
+
+ print self.client.get('/api/changes/0.json?book_fields=slug&tag_fields=slug').content
+ changes = json.loads(self.client.get('/api/changes/0.json?book_fields=slug&tag_fields=slug').content)
+ self.assertEqual(changes['added']['books'],
+ [{'id': book.id, 'slug': book.slug}],
+ 'Invalid book format in changes')
+ self.assertEqual(changes['added']['tags'],
+ [{'id': tag.id, 'slug': tag.slug}],
+ 'Invalid tag format in changes')
+
+
+class BookChangesTests(TestCase):
+
+ def setUp(self):
+ self.book = Book.objects.create()
+
+ def test_basic(self):
+ # test book in book_changes.added
+ changes = json.loads(self.client.get('/api/book_changes/0.json').content)
+ self.assertEqual(len(changes['added']),
+ 1,
+ 'Added book not in book_changes.added')
+
+ # test changed book in changed
+ self.book.slug = 'a-book'
+ self.book.save()
+ changes = json.loads(self.client.get('/api/book_changes/%f.json' % timestamp(self.book.created_at)).content)
+ self.assertEqual(changes['added'],
+ [],
+ 'Changed book in book_changes.added instead of book_changes.changed.')
+ self.assertEqual(len(changes['changed']),
+ 1,
+ 'Changed book not in book_changes.changed.')
+
+ # test deleted book in deleted
+ Book.objects.all().delete()
+ changes = json.loads(self.client.get('/api/book_changes/%f.json' % timestamp(self.book.changed_at)).content)
+ self.assertEqual(changes['added'],
+ [],
+ 'Deleted book still in book_changes.added.')
+ self.assertEqual(changes['changed'],
+ [],
+ 'Deleted book still in book_changes.changed.')
+ self.assertEqual(len(changes['deleted']),
+ 1,
+ 'Deleted book not in book_changes.deleted.')
+
+ def test_shelf(self):
+ changed_at = self.book.changed_at
+ print changed_at
+
+ # putting on a shelf should not update changed_at
+ shelf = Tag.objects.create(category='set', slug='shelf')
+ self.book.tags = [shelf]
+ self.assertEqual(self.book.changed_at,
+ changed_at)
+
+class TagChangesTests(TestCase):
+
+ def setUp(self):
+ self.tag = Tag.objects.create()
+
+ def test_basic(self):
+ # test tag in tag_changes.added
+ changes = json.loads(self.client.get('/api/tag_changes/0.json').content)
+ self.assertEqual(len(changes['added']),
+ 1,
+ 'Added tag not in tag_changes.added')
+
+ # test changed tag in changed
+ self.tag.slug = 'a-tag'
+ self.tag.save()
+ changes = json.loads(self.client.get('/api/tag_changes/%f.json' % timestamp(self.tag.created_at)).content)
+ self.assertEqual(changes['added'],
+ [],
+ 'Changed tag in tag_changes.added instead of tag_changes.changed.')
+ self.assertEqual(len(changes['changed']),
+ 1,
+ 'Changed tag not in tag_changes.changed.')
+
+ # test deleted book in deleted
+ Tag.objects.all().delete()
+ changes = json.loads(self.client.get('/api/tag_changes/%f.json' % timestamp(self.tag.changed_at)).content)
+ self.assertEqual(changes['added'],
+ [],
+ 'Deleted tag still in tag_changes.added.')
+ self.assertEqual(changes['changed'],
+ [],
+ 'Deleted tag still in tag_changes.changed.')
+ self.assertEqual(len(changes['deleted']),
+ 1,
+ 'Deleted tag not in tag_changes.deleted.')
diff --git a/apps/api/urls.py b/apps/api/urls.py
index 8b1b9b0cb..77fe8cfce 100644
--- a/apps/api/urls.py
+++ b/apps/api/urls.py
@@ -1,17 +1,36 @@
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
from piston.resource import Resource
-from piston.authentication import HttpBasicAuthentication
+#from piston.authentication import HttpBasicAuthentication
-from api.handlers import BookHandler
+#from api.handlers import BookHandler, TagHandler
+from api import handlers
-auth = HttpBasicAuthentication(realm='My sample API')
-book_resource = Resource(handler=BookHandler, authentication=auth)
-
+#auth = OAuthAuthentication(realm='API')
+book_changes_resource = Resource(handler=handlers.BookChangesHandler)
+tag_changes_resource = Resource(handler=handlers.TagChangesHandler)#, authentication=auth)
+changes_resource = Resource(handler=handlers.ChangesHandler)
urlpatterns = patterns('',
- url(r'^books/(?P[^/]+)\.(?Pxml|json|yaml)$', book_resource),
- url(r'^books\.(?Pxml|json|yaml)$', book_resource),
+ url(r'^book_changes/(?P\d*(\.\d*)?)\.(?Pxml|json|yaml)$', book_changes_resource),
+ url(r'^tag_changes/(?P\d*(\.\d*)?)\.(?Pxml|json|yaml)$', tag_changes_resource),
+ url(r'^changes/(?P\d*(\.\d*)?)\.(?Pxml|json|yaml)$', changes_resource),
+
+ #url(r'^books/(?P[\d,]+)\.(?Pxml|json|yaml)$', book_resource),
+ #url(r'^books\.(?Pxml|json|yaml)$', book_resource),
+
+ #url(r'^tags/(?P[a-zA-Z0-9-/]*)\.(?Pxml|json|yaml)$', tag_resource),
+ #url(r'^lektura/(?P[a-zA-Z0-9-]+)\.(?Pxml|json|yaml)$', book_resource), #detail
+ #url(r'^lektura/(?P[a-zA-Z0-9-]+)/motyw/(?P[a-zA-Z0-9-]+)\.(?Pxml|json|yaml)$', book_resource), #fragments
+ #url(r'^oauth/callback/$','oauth_callback'),
)
+"""
+urlpatterns += patterns(
+'piston.authentication',
+ url(r'^oauth/request_token/$','oauth_request_token'),
+ url(r'^oauth/authorize/$','oauth_user_auth'),
+ url(r'^oauth/access_token/$','oauth_access_token'),
+)
+"""
\ No newline at end of file
diff --git a/apps/api/views.py b/apps/api/views.py
new file mode 100644
index 000000000..1c5e84834
--- /dev/null
+++ b/apps/api/views.py
@@ -0,0 +1,10 @@
+from django.http import HttpResponseRedirect
+
+def oauth_callback(request, data):
+ key = data.key
+ secret = data.secret
+ verifier = data.verifier
+ timestamp = data.timestamp
+ print data
+ return HttpResponseRedirect("wl://")
+ #return HttpResponseRedirect("wl://%s/%s/%s/%s/" % (key, secret, verifier, timestamp))
diff --git a/apps/catalogue/migrations/0007_auto__add_field_book_changed_at__add_field_tag_created_at__add_field_t.py b/apps/catalogue/migrations/0007_auto__add_field_book_changed_at__add_field_tag_created_at__add_field_t.py
new file mode 100644
index 000000000..b339c0586
--- /dev/null
+++ b/apps/catalogue/migrations/0007_auto__add_field_book_changed_at__add_field_tag_created_at__add_field_t.py
@@ -0,0 +1,166 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'Book.changed_at'
+ db.add_column('catalogue_book', 'changed_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, default=datetime.datetime(2011, 2, 25, 15, 19, 36, 525463), db_index=True, blank=True), keep_default=False)
+
+ # Adding index on 'Book', fields ['created_at']
+ db.create_index('catalogue_book', ['created_at'])
+
+ # Adding field 'Tag.created_at'
+ db.add_column('catalogue_tag', 'created_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, default=datetime.datetime(2011, 2, 25, 15, 19, 42, 921525), db_index=True, blank=True), keep_default=False)
+
+ # Adding field 'Tag.changed_at'
+ db.add_column('catalogue_tag', 'changed_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, default=datetime.datetime(2011, 2, 25, 15, 19, 45, 697471), db_index=True, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Removing index on 'Book', fields ['created_at']
+ db.delete_index('catalogue_book', ['created_at'])
+
+ # Deleting field 'Book.changed_at'
+ db.delete_column('catalogue_book', 'changed_at')
+
+ # Deleting field 'Tag.created_at'
+ db.delete_column('catalogue_tag', 'created_at')
+
+ # Deleting field 'Tag.changed_at'
+ db.delete_column('catalogue_tag', 'changed_at')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'unique': 'True'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'max_length': '30', 'unique': 'True'})
+ },
+ 'catalogue.book': {
+ 'Meta': {'ordering': "('title',)", 'object_name': 'Book'},
+ '_short_html': ('django.db.models.fields.TextField', [], {}),
+ '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_tag_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
+ '_theme_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
+ 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'epub_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
+ 'extra_info': ('catalogue.fields.JSONField', [], {}),
+ 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
+ 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'medias': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['catalogue.BookMedia']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'children'", 'blank': 'True', 'null': 'True', 'to': "orm['catalogue.Book']"}),
+ 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'pdf_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'unique': 'True', 'db_index': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+ 'txt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
+ 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
+ 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'})
+ },
+ 'catalogue.bookmedia': {
+ 'Meta': {'ordering': "('type', 'name')", 'object_name': 'BookMedia'},
+ 'extra_info': ('catalogue.fields.JSONField', [], {'default': "'{}'"}),
+ 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
+ 'type': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
+ 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
+ },
+ 'catalogue.filerecord': {
+ 'Meta': {'ordering': "('-time', '-slug', '-type')", 'object_name': 'FileRecord'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'sha1': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
+ 'time': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_index': 'True'})
+ },
+ 'catalogue.fragment': {
+ 'Meta': {'ordering': "('book', 'anchor')", 'object_name': 'Fragment'},
+ '_short_html': ('django.db.models.fields.TextField', [], {}),
+ '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+ 'anchor': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+ 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fragments'", 'to': "orm['catalogue.Book']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'short_text': ('django.db.models.fields.TextField', [], {}),
+ 'text': ('django.db.models.fields.TextField', [], {})
+ },
+ 'catalogue.tag': {
+ 'Meta': {'ordering': "('sort_key',)", 'unique_together': "(('slug', 'category'),)", 'object_name': 'Tag'},
+ 'book_count': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'main_page': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
+ 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'})
+ },
+ 'catalogue.tagrelation': {
+ 'Meta': {'unique_together': "(('tag', 'content_type', 'object_id'),)", 'object_name': 'TagRelation', 'db_table': "'catalogue_tag_relation'"},
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['catalogue.Tag']"})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ }
+ }
+
+ complete_apps = ['catalogue']
diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py
index 455296217..34c1d0b23 100644
--- a/apps/catalogue/models.py
+++ b/apps/catalogue/models.py
@@ -64,6 +64,9 @@ class Tag(TagBase):
gazeta_link = models.CharField(blank=True, max_length=240)
wiki_link = models.CharField(blank=True, max_length=240)
+ created_at = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True)
+ changed_at = models.DateTimeField(_('creation date'), auto_now=True, db_index=True)
+
categories_rev = {
'autor': 'author',
'epoka': 'epoch',
@@ -220,7 +223,8 @@ class Book(models.Model):
title = models.CharField(_('title'), max_length=120)
slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True)
description = models.TextField(_('description'), blank=True)
- created_at = models.DateTimeField(_('creation date'), auto_now_add=True)
+ created_at = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True)
+ changed_at = models.DateTimeField(_('creation date'), auto_now=True, db_index=True)
_short_html = models.TextField(_('short HTML'), editable=False)
parent_number = models.IntegerField(_('parent number'), default=0)
extra_info = JSONField(_('extra information'))
diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py
index 7f1de6d46..5de0e9dc2 100644
--- a/apps/catalogue/views.py
+++ b/apps/catalogue/views.py
@@ -141,7 +141,7 @@ def differentiate_tags(request, tags, ambiguous_slugs):
context_instance=RequestContext(request))
-def tagged_object_list(request, tags=''):
+def tagged_object_list(request, tags='', api=False):
try:
tags = models.Tag.get_tag_list(tags)
except models.Tag.DoesNotExist:
@@ -222,20 +222,23 @@ def tagged_object_list(request, tags=''):
only_author = len(tags) == 1 and tags[0].category == 'author'
objects = models.Book.objects.none()
- return object_list(
- request,
- objects,
- template_name='catalogue/tagged_object_list.html',
- extra_context={
- 'categories': categories,
- 'only_shelf': only_shelf,
- 'only_author': only_author,
- 'only_my_shelf': only_my_shelf,
- 'formats_form': forms.DownloadFormatsForm(),
-
- 'tags': tags,
- }
- )
+ if api:
+ print objects
+ return objects
+ else:
+ return object_list(
+ request,
+ objects,
+ template_name='catalogue/tagged_object_list.html',
+ extra_context={
+ 'categories': categories,
+ 'only_shelf': only_shelf,
+ 'only_author': only_author,
+ 'only_my_shelf': only_my_shelf,
+ 'formats_form': forms.DownloadFormatsForm(),
+ 'tags': tags,
+ }
+ )
def book_fragments(request, book_slug, theme_slug):
@@ -680,6 +683,27 @@ def delete_shelf(request, slug):
# ==================
# = Authentication =
# ==================
+
+@cache.never_cache
+def simple_login(request):
+ if request.method == "GET":
+ #next = request.REQUEST.get('next', '')
+ #if next == '':
+ form = AuthenticationForm(prefix='login')
+ return render_to_response('auth/login.html', locals(),
+ context_instance=RequestContext(request))
+ #else:
+ # return HttpResponseRedirect("/"+next)
+
+ elif request.method == "POST":
+ form = AuthenticationForm(data=request.POST, prefix='login')
+ if form.is_valid():
+ auth.login(request, form.get_user())
+ url = request.META['HTTP_REFERER'].split("next=")[1]
+ url = url.replace("%3F","?").replace("%3D","=")
+ return HttpResponseRedirect(url)
+
+
@require_POST
@cache.never_cache
def login(request):
diff --git a/apps/piston/templates/piston/authorize_token.html b/apps/piston/templates/piston/authorize_token.html
index 59c09e331..3507e55f8 100644
--- a/apps/piston/templates/piston/authorize_token.html
+++ b/apps/piston/templates/piston/authorize_token.html
@@ -1,15 +1,17 @@
+{% load i18n %}
- Authorize Token
+ {% trans "Authorize Token" %}
+
+
- Authorize Token
-
-
-
diff --git a/wolnelektury/static/css/mobile.css b/wolnelektury/static/css/mobile.css
new file mode 100644
index 000000000..2f04e6596
--- /dev/null
+++ b/wolnelektury/static/css/mobile.css
@@ -0,0 +1,7 @@
+ul li {
+ list-style-type: none;
+}
+
+h1 {
+ font-size: 1em;
+}
diff --git a/wolnelektury/templates/auth/login.html b/wolnelektury/templates/auth/login.html
index a168ff7f8..204cce641 100644
--- a/wolnelektury/templates/auth/login.html
+++ b/wolnelektury/templates/auth/login.html
@@ -1,25 +1,28 @@
-{% extends "base.html" %}
{% load i18n %}
+
+
+
+ {% trans "Authorize Token" %}
+
+
+
+
+ WolneLektury.pl - {% trans "Sign in" %} / {% trans "Register"%}
+
-{% block title %}{% trans "Sign in" %} / {% trans "Register on"%} WolneLektury.pl{% endblock %}
-
-{% block body %}
- {% trans "Sign in" %} / {% trans "Register"%}
-
-
-
-
-
-{% endblock %}
+
+
+
diff --git a/wolnelektury/urls.py b/wolnelektury/urls.py
index a99030f4d..932c440f6 100644
--- a/wolnelektury/urls.py
+++ b/wolnelektury/urls.py
@@ -37,6 +37,7 @@ urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
# Authentication
+ url(r'^users/simple_login/$', 'catalogue.views.simple_login', name='simple_login'),
url(r'^uzytkownicy/zaloguj/$', 'catalogue.views.login', name='login'),
url(r'^uzytkownicy/wyloguj/$', 'catalogue.views.logout_then_redirect', name='logout'),
url(r'^uzytkownicy/utworz/$', 'catalogue.views.register', name='register'),