From f833109c026bea69bedee7b2b98809015106c81f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 25 Nov 2010 16:21:23 +0100 Subject: [PATCH] admin --- pandora/api/admin.py | 29 ----------------- pandora/app/admin.py | 2 +- pandora/item/admin.py | 26 ++++++++++++++++ pandora/item/models.py | 18 +++++++++-- pandora/item/views.py | 70 ++++++++++++++++++++++++++++++++++++------ pandora/settings.py | 1 + pandora/urls.py | 10 ++---- 7 files changed, 107 insertions(+), 49 deletions(-) delete mode 100644 pandora/api/admin.py create mode 100644 pandora/item/admin.py diff --git a/pandora/api/admin.py b/pandora/api/admin.py deleted file mode 100644 index 6dda3a088..000000000 --- a/pandora/api/admin.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# vi:si:et:sw=4:sts=4:ts=4 - -from django.contrib import admin - -#from forms import FileAdminForm, ItemAdminForm, ArchiveFileAdminForm -import models - - - -''' -#class ItemImdbAdmin(admin.ModelAdmin): -# search_fields = ['imdbId', 'title'] -#admin.site.register(models.ItemImdb, ItemImdbAdmin) -class ItemImdbInline(admin.StackedInline): - model = models.ItemImdb - -class ItemOxdbInline(admin.StackedInline): - model = models.ItemOxdb -''' - -class ItemAdmin(admin.ModelAdmin): - search_fields = ['itemId', 'imdb__title', 'oxdb__title'] - #form = ItemAdminForm - #inlines = [ItemImdbInline, ItemOxdbInline] - -admin.site.register(models.Item, ItemAdmin) - - diff --git a/pandora/app/admin.py b/pandora/app/admin.py index 90cbd79f8..428d4a3db 100644 --- a/pandora/app/admin.py +++ b/pandora/app/admin.py @@ -5,7 +5,6 @@ from django.contrib import admin import models - class PageAdmin(admin.ModelAdmin): search_fields = ['name', 'body'] @@ -16,3 +15,4 @@ class SiteSettingsAdmin(admin.ModelAdmin): search_fields = ['key', 'value'] admin.site.register(models.SiteSettings, SiteSettingsAdmin) + diff --git a/pandora/item/admin.py b/pandora/item/admin.py new file mode 100644 index 000000000..bd8296b53 --- /dev/null +++ b/pandora/item/admin.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 + +from django.contrib import admin + +import models + + +class BinAdmin(admin.ModelAdmin): + search_fields = ['name', 'title'] +admin.site.register(models.Bin, BinAdmin) + +class PropertyAdmin(admin.ModelAdmin): + search_fields = ['name', 'title'] +admin.site.register(models.Property, PropertyAdmin) + + +class PlaceAdmin(admin.ModelAdmin): + search_fields = ['name'] +admin.site.register(models.Place, PlaceAdmin) + + +class EventAdmin(admin.ModelAdmin): + search_fields = ['name'] +admin.site.register(models.Event, EventAdmin) + diff --git a/pandora/item/models.py b/pandora/item/models.py index ab77755f4..27b9c0347 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -31,6 +31,9 @@ from archive import extract class Bin(models.Model): + class Meta: + ordering = ('position', ) + name = models.CharField(null=True, max_length=255, unique=True) title = models.CharField(null=True, max_length=255) #text, string, string from list(fixme), event, place, person @@ -246,7 +249,10 @@ def getItem(info): item.save() return item -class ItemProperty(models.Model): +class Property(models.Model): + class Meta: + ordering = ('position', ) + name = models.CharField(null=True, max_length=255, unique=True) title = models.CharField(null=True, max_length=255) #text, string, string from list(fixme), event, place, person @@ -260,6 +266,11 @@ class ItemProperty(models.Model): totals = models.BooleanField(default=False) admin = models.BooleanField(default=False) + def __unicode__(self): + if self.title: + return self.title + return self.name + def json(self): j = {} for key in ('type', 'sort', 'title', 'array', 'totals', 'admin'): @@ -1016,10 +1027,13 @@ class ReviewWhitelist(models.Model): url = models.CharField(max_length=255, unique=True) class List(models.Model): + class Meta: + unique_together = ("user", "name") + created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) user = models.ForeignKey(User) - name = models.CharField(max_length=255, unique=True) + name = models.CharField(max_length=255) public = models.BooleanField(default=False) items = models.ManyToManyField(Item, related_name='lists', through='ListItem') diff --git a/pandora/item/views.py b/pandora/item/views.py index 41877d90e..81bc44ab1 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -36,6 +36,7 @@ from user.models import getUserJSON from archive.models import File from archive import extract + def _order_query(qs, sort, prefix='sort__'): order_by = [] if len(sort) == 1: @@ -259,7 +260,7 @@ def api_removeItem(request): if item.editable(request.user): response = json_response(status=501, text='not implemented') else: - response = json_response(status=403, text='permissino denied') + response = json_response(status=403, text='permission denied') return render_to_json_response(response) @login_required_json @@ -311,33 +312,71 @@ def api_editLayer(request): def api_addListItem(request): ''' param data - {key: value} + {list: listId, + item: itemId, + quert: ... + } return {'status': {'code': int, 'text': string}, 'data': {}} ''' - response = json_response(status=501, text='not implemented') + data = json.loads(request.POST['data']) + list = get_object_or_404_json(models.List, pk=data['list']) + if 'item' in data: + item = get_object_or_404_json(models.Item, pk=data['item']) + if list.editable(request.user): + list.add(item) + response = json_response(status=200, text='item removed') + else: + response = json_response(status=403, text='not allowed') + elif 'query' in data: + response = json_response(status=501, text='not implemented') + + else: + response = json_response(status=501, text='not implemented') return render_to_json_response(response) @login_required_json def api_removeListItem(request): ''' param data - {key: value} + {list: listId, + item: itemId, + quert: ... + } return {'status': {'code': int, 'text': string}, 'data': {}} ''' - response = json_response(status=501, text='not implemented') + data = json.loads(request.POST['data']) + list = get_object_or_404_json(models.List, pk=data['list']) + if 'item' in data: + item = get_object_or_404_json(models.Item, pk=data['item']) + if list.editable(request.user): + list.remove(item) + response = json_response(status=200, text='item removed') + else: + response = json_response(status=403, text='not allowed') + elif 'query' in data: + response = json_response(status=501, text='not implemented') + + else: + response = json_response(status=501, text='not implemented') return render_to_json_response(response) @login_required_json def api_addList(request): ''' param data - {key: value} + {name: value} return {'status': {'code': int, 'text': string}, 'data': {}} ''' - response = json_response(status=501, text='not implemented') + data = json.loads(request.POST['data']) + if models.List.filter(name=data['name'], user=request.user).count() == 0: + list = models.List(name = data['name'], user=request.user) + list.save() + response = json_response(status=200, text='created') + else: + response = json_response(status=403, text='list name exists') return render_to_json_response(response) @login_required_json @@ -345,10 +384,18 @@ def api_editList(request): ''' param data {key: value} + keys: name, public return {'status': {'code': int, 'text': string}, 'data': {}} ''' - response = json_response(status=501, text='not implemented') + data = json.loads(request.POST['data']) + list = get_object_or_404_json(models.List, pk=data['list']) + if list.editable(request.user): + for key in data: + if key in ('name', 'public'): + setattr(list, key, data['key']) + else: + response = json_response(status=403, text='not allowed') return render_to_json_response(response) def api_removeList(request): @@ -358,7 +405,12 @@ def api_removeList(request): return {'status': {'code': int, 'text': string}, 'data': {}} ''' - response = json_response(status=501, text='not implemented') + data = json.loads(request.POST['data']) + list = get_object_or_404_json(models.List, pk=data['list']) + if list.editable(request.user): + list.delete() + else: + response = json_response(status=403, text='not allowed') return render_to_json_response(response) ''' diff --git a/pandora/settings.py b/pandora/settings.py index 0cfdda475..429772ed2 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -111,6 +111,7 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.humanize', + 'django_extensions', 'devserver', 'south', diff --git a/pandora/urls.py b/pandora/urls.py index 486c78409..09f978c1f 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -11,10 +11,12 @@ from django.conf import settings from django.contrib import admin admin.autodiscover() + def serve_static_file(path, location, content_type): return HttpFileResponse(location, content_type=content_type) urlpatterns = patterns('', + (r'^admin/', include(admin.site.urls)), (r'^ajax_filtered_fields/', include('ajax_filtered_fields.urls')), (r'^api/upload/$', 'archive.views.firefogg_upload'), (r'^site.json$', 'app.views.site_json'), @@ -26,13 +28,6 @@ urlpatterns = patterns('', (r'^r/(?P.*)$', 'user.views.recover'), (r'^api/$', include('api.urls')), (r'', include('item.urls')), - - # 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')), - - # Uncomment the next line to enable the admin: - (r'^admin/(.*)', include(admin.site.urls)), (r'^robots.txt$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), 'content_type': 'text/plain'}), (r'^favicon.ico$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'content_type': 'image/x-icon'}), ) @@ -47,4 +42,3 @@ if settings.DEBUG: {'document_root': settings.TESTS_ROOT}), ) -