option to edit items, install django_lsd from git, no secrets in git

This commit is contained in:
j 2013-11-03 15:02:46 +01:00
parent b95ad580d2
commit 6013154708
3 changed files with 29 additions and 7 deletions

View file

@ -86,9 +86,6 @@ STATICFILES_FINDERS = (
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'h1^#f29tf+lol+%k=m&*)gmc$p#!(cse(w$#$xkdr4j9por&gz'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
@ -160,3 +157,16 @@ LOGGING = {
},
}
}
# Make this unique, creates random key first at first time.
SECRET_FILE = join(PROJECT_ROOT, 'secret.txt')
try:
SECRET_KEY = open(SECRET_FILE).read().strip()
except IOError:
try:
from random import choice
SECRET_KEY = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
with open(SECRET_FILE, 'w') as secret:
secret.write(SECRET_KEY)
except IOError:
Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)

View file

@ -8,7 +8,7 @@ from django.contrib.auth.models import User
import ox
from ox.django.api import actions
from ox.django.decorators import login_required_json
from ox.django.shortcuts import json_response, render_to_json_response
from ox.django.shortcuts import json_response, render_to_json_response, get_object_or_404_json
from django_lsd.models import Item
@ -122,6 +122,7 @@ def find(request):
response['data']['items'] = []
for i in Item.objects.all():
j = {}
j.update(i.data)
j['id'] = i.sha1
j['sha1'] = i.sha1
j['info_hash'] = i.info_hash
@ -130,7 +131,19 @@ def find(request):
else:
state = ''
j['state'] = state
j.update(i.data)
response['data']['items'].append(j)
return render_to_json_response(response)
actions.register(find, cache=True)
@login_required_json
def edit(request):
response = json_response()
data = json.loads(request.POST['data'])
sha1 = data.pop('id')
item = get_object_or_404_json(Item, sha1=sha1)
for key in data:
if key not in ('id', 'sha1', 'info_hash'):
item.data[key] = data[key]
item.save()
return render_to_json_response(response)
actions.register(find, cache=True)

View file

@ -1,3 +1,2 @@
Django
ox
django_lsd
git+https://git.0x2620.org/django_lsd.git#egg=django_lsd