book = get_object_or_404(models.Book, slug=book)
shelf = get_object_or_404(models.Tag, slug=shelf, category='set', user=request.user)
- models.Tag.objects.remove_tag(book, shelf)
-
- shelf.book_count -= 1
- shelf.save()
-
- return HttpResponse('Usunieto')
+ if shelf in book.tags:
+ models.Tag.objects.remove_tag(book, shelf)
+
+ shelf.book_count -= 1
+ shelf.save()
+
+ return HttpResponse('Usunięto')
+ else:
+ return HttpResponse('Książki nie ma na półce')
def collect_books(books):
--- /dev/null
+#!/srv/library/wolnelektury/pythonenv/bin/python
+from __future__ import with_statement
+
+import shutil
+import os
+import sys
+
+from string import Template
+
+def render_template(source, dest, context={}):
+ print "Rendering template:",
+ with open(source, 'rb') as source_file:
+ t = Template(source_file.read())
+ with open(dest, 'wb') as dest_file:
+ dest_file.write(t.safe_substitute(context))
+ print "done."
+
+def restart_wsgi():
+ print "Restarting wsgi application:",
+ os.system("touch %s" % WSGI_TARGET)
+ print "done."
+
+def update_application():
+ print "Updating repository.",
+ os.system("cd %s; git pull" % PROJECT_ROOT)
+
+ print "Installing requirements"
+ os.system("%s install -r %s" % (PIP, os.path.join(PROJECT_ROOT, 'requirements.txt')))
+
+ print "Installing local requirements"
+ os.system("%s install -r %s" % (PIP, os.path.join(ROOT, 'etc', 'requirements.txt')))
+ print "done."
+
+ROOT = os.path.dirname(os.path.abspath(__file__))
+
+PYTHON = os.path.join(ROOT, 'pythonenv', 'bin', 'python')
+PIP = os.path.join(ROOT, 'pythonenv', 'bin', 'pip')
+PYTHON_SITE = os.path.join(ROOT, 'pythonenv', 'lib', 'python2.6', 'site-packages')
+
+PROJECT_NAME = 'wolnelektury'
+PROJECT_ROOT = os.path.join(ROOT, 'application')
+
+MEDIA_ROOT = os.path.join(ROOT, 'www', 'media')
+
+ADMIN_EMAIL = 'lrekucki@gmail.com'
+
+WSGI_TARGET = os.path.join(ROOT, 'www', 'wsgi', PROJECT_NAME + '.wsgi')
+WSGI_DIR = os.path.dirname(WSGI_TARGET)
+
+WSGI_USER = PROJECT_NAME
+WSGI_PROCESSES = 5
+WSGI_THREADS = 1
+
+DOMAIN = 'lektury.staging.nowoczesnapolska.org.pl'
+
+#
+# Load local configuration
+#
+sys.path = [ os.path.join(ROOT, 'etc') ] + sys.path
+
+from local_deployment import *
+
+if __name__ == '__main__':
+ update_application()
+ render_template(os.path.join(PROJECT_ROOT, PROJECT_NAME + '.wsgi.tmpl'), WSGI_TARGET, context=globals())
+ render_template(os.path.join(PROJECT_ROOT, PROJECT_NAME + '.vhost.tmpl'), os.path.join(ROOT, 'etc', PROJECT_NAME + '.vhost'), context=globals())
+ restart_wsgi()
--- /dev/null
+<VirtualHost *:80>
+ ServerName $DOMAIN
+ ServerAlias $DOMAIN_ALIASES
+ ServerAdmin $ADMIN_EMAIL
+
+ WSGIDaemonProcess $PROJECT_NAME user=$WSGI_USER group=$WSGI_USER processes=$WSGI_PROCESSES threads=$WSGI_THREADS display-name=%{GROUP}
+ WSGIProcessGroup $PROJECT_NAME
+
+ WSGIScriptAlias / $WSGI_TARGET
+ <Directory $WSGI_DIR>
+ Order allow,deny
+ allow from all
+ </Directory>
+
+ Alias /media $MEDIA_ROOT
+ <Directory $MEDIA_ROOT >
+ Options Indexes, FollowLinks
+ Order allow,deny
+ Allow from all
+ </Directory>
+
+ LogLevel warn
+ ErrorLog /var/log/apache2/$PROJECT_NAME/error.log
+ CustomLog /var/log/apache2/$PROJECT_NAME/access.log combined
+</VirtualHost>