From 6013154708c59c137bb9459009f0893cb46f5491 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 3 Nov 2013 15:02:46 +0100 Subject: [PATCH] option to edit items, install django_lsd from git, no secrets in git --- lsd_simpleshare/settings.py | 16 +++++++++++++--- lsd_simpleshare/views.py | 17 +++++++++++++++-- requirements.txt | 3 +-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lsd_simpleshare/settings.py b/lsd_simpleshare/settings.py index 1459eaa..dffbe65 100644 --- a/lsd_simpleshare/settings.py +++ b/lsd_simpleshare/settings.py @@ -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) diff --git a/lsd_simpleshare/views.py b/lsd_simpleshare/views.py index 0055c39..c283204 100644 --- a/lsd_simpleshare/views.py +++ b/lsd_simpleshare/views.py @@ -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) diff --git a/requirements.txt b/requirements.txt index 851bf68..dfc76aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ Django -ox -django_lsd +git+https://git.0x2620.org/django_lsd.git#egg=django_lsd