This commit is contained in:
j 2010-11-25 16:21:23 +01:00
parent c1cd54023a
commit f833109c02
7 changed files with 107 additions and 49 deletions

View file

@ -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)

View file

@ -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)

26
pandora/item/admin.py Normal file
View file

@ -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)

View file

@ -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')

View file

@ -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,10 +312,26 @@ def api_editLayer(request):
def api_addListItem(request):
'''
param data
{key: value}
{list: listId,
item: itemId,
quert: ...
}
return {'status': {'code': int, 'text': string},
'data': {}}
'''
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)
@ -322,10 +339,26 @@ def api_addListItem(request):
def api_removeListItem(request):
'''
param data
{key: value}
{list: listId,
item: itemId,
quert: ...
}
return {'status': {'code': int, 'text': string},
'data': {}}
'''
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)
@ -333,11 +366,17 @@ def api_removeListItem(request):
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)
'''

View file

@ -111,6 +111,7 @@ INSTALLED_APPS = (
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.humanize',
'django_extensions',
'devserver',
'south',

View file

@ -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<key>.*)$', '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}),
)