From: Radek Czajka Date: Fri, 27 Mar 2015 09:13:09 +0000 (+0100) Subject: Just removing old cruft. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/6952a4c7812d1cbd2da8aa60ba3ff1ae183248e5?ds=sidebyside;hp=d1276c781518fc7b90c4b6bd3bd6364252ab3174 Just removing old cruft. --- diff --git a/apps/apiclient/__init__.py b/apps/apiclient/__init__.py index 33d20081..38ce26e4 100644 --- a/apps/apiclient/__init__.py +++ b/apps/apiclient/__init__.py @@ -1,9 +1,8 @@ import urllib -from django.utils import simplejson +import json import oauth2 -from apiclient.models import OAuthConnection from apiclient.settings import WL_CONSUMER_KEY, WL_CONSUMER_SECRET, WL_API_URL @@ -22,13 +21,14 @@ class NotAuthorizedError(BaseException): def api_call(user, path, data=None): + from .models import OAuthConnection conn = OAuthConnection.get(user) if not conn.access: raise NotAuthorizedError("No WL authorization for user %s." % user) token = oauth2.Token(conn.token, conn.token_secret) client = oauth2.Client(wl_consumer, token) if data is not None: - data = simplejson.dumps(data) + data = json.dumps(data) data = urllib.urlencode({"data": data}) resp, content = client.request( "%s%s" % (WL_API_URL, path), @@ -40,7 +40,7 @@ def api_call(user, path, data=None): status = resp['status'] if status == '200': - return simplejson.loads(content) + return json.loads(content) elif status.startswith('2'): return elif status == '401': diff --git a/apps/catalogue/ebook_utils.py b/apps/catalogue/ebook_utils.py index d9c99227..dae2e769 100644 --- a/apps/catalogue/ebook_utils.py +++ b/apps/catalogue/ebook_utils.py @@ -24,7 +24,7 @@ def serve_file(file_path, name, mime_type): yield chunk chunk = f.read(size) - response = HttpResponse(mimetype=mime_type) + response = HttpResponse(content_type=mime_type) response['Content-Disposition'] = 'attachment; filename=%s' % name with open(file_path) as f: for chunk in read_chunks(f): diff --git a/apps/catalogue/management/__init__.py b/apps/catalogue/management/__init__.py index f7731d72..bc3d6c02 100644 --- a/apps/catalogue/management/__init__.py +++ b/apps/catalogue/management/__init__.py @@ -100,9 +100,7 @@ class XmlUpdater(object): books = Book.objects.all() # Start transaction management. - transaction.commit_unless_managed() transaction.enter_transaction_management() - transaction.managed(True) for book in books: self.counters['All books'] += 1 diff --git a/apps/catalogue/management/commands/assign_from_redmine.py b/apps/catalogue/management/commands/assign_from_redmine.py index 31bdc149..491fd832 100644 --- a/apps/catalogue/management/commands/assign_from_redmine.py +++ b/apps/catalogue/management/commands/assign_from_redmine.py @@ -47,9 +47,7 @@ class Command(BaseCommand): redmine_csv = REDMINE_CSV # Start transaction management. - transaction.commit_unless_managed() transaction.enter_transaction_management() - transaction.managed(True) redakcja_link = re.compile(re.escape(redakcja) + r'([-_.:?&%/a-zA-Z0-9]*)') diff --git a/apps/catalogue/management/commands/import_wl.py b/apps/catalogue/management/commands/import_wl.py index 5f603883..7eee8977 100644 --- a/apps/catalogue/management/commands/import_wl.py +++ b/apps/catalogue/management/commands/import_wl.py @@ -31,9 +31,7 @@ class Command(BaseCommand): verbose = options.get('verbose') # Start transaction management. - transaction.commit_unless_managed() transaction.enter_transaction_management() - transaction.managed(True) if verbose: print 'Reading currently managed files (skipping hidden ones).' diff --git a/apps/catalogue/management/commands/merge_books.py b/apps/catalogue/management/commands/merge_books.py index 5499d3d4..82bd622d 100644 --- a/apps/catalogue/management/commands/merge_books.py +++ b/apps/catalogue/management/commands/merge_books.py @@ -126,9 +126,7 @@ class Command(BaseCommand): return # Start transaction management. - transaction.commit_unless_managed() transaction.enter_transaction_management() - transaction.managed(True) books = [Book.objects.get(slug=slug) for slug in slugs] common_slug = common_prefix(slugs) diff --git a/apps/catalogue/managers.py b/apps/catalogue/managers.py index 4f804b84..a131ce94 100644 --- a/apps/catalogue/managers.py +++ b/apps/catalogue/managers.py @@ -1,5 +1,5 @@ from django.db import models class VisibleManager(models.Manager): - def get_query_set(self): - return super(VisibleManager, self).get_query_set().exclude(_hidden=True) + def get_queryset(self): + return super(VisibleManager, self).get_queryset().exclude(_hidden=True) diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index e320af76..f1094740 100755 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -94,7 +94,7 @@ class Book(models.Model): return self.public or request.user.is_authenticated() @classmethod - @transaction.commit_on_success + @transaction.atomic def create(cls, creator, text, *args, **kwargs): b = cls.objects.create(*args, **kwargs) b.chunk_set.all().update(creator=creator) @@ -106,7 +106,7 @@ class Book(models.Model): return self.chunk_set.reverse()[0].split(*args, **kwargs) @classmethod - @transaction.commit_on_success + @transaction.atomic def import_xml_text(cls, text=u'', previous_book=None, commit_args=None, **kwargs): """Imports a book from XML, splitting it into chunks as necessary.""" @@ -153,7 +153,7 @@ class Book(models.Model): i += 1 return new_slug - @transaction.commit_on_success + @transaction.atomic def append(self, other, slugs=None, titles=None): """Add all chunks of another book to self.""" assert self != other @@ -213,7 +213,7 @@ class Book(models.Model): other.delete() - @transaction.commit_on_success + @transaction.atomic def prepend_history(self, other): """Prepend history from all the other book's chunks to own.""" assert self != other diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 8a96dc68..af2efe23 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -210,7 +210,7 @@ def book_xml(request, slug): return HttpResponseForbidden("Not authorized.") xml = book.materialize() - response = http.HttpResponse(xml, content_type='application/xml', mimetype='application/wl+xml') + response = http.HttpResponse(xml, content_type='application/xml') response['Content-Disposition'] = 'attachment; filename=%s.xml' % slug return response @@ -223,7 +223,7 @@ def book_txt(request, slug): doc = book.wldocument() text = doc.as_text().get_string() - response = http.HttpResponse(text, content_type='text/plain', mimetype='text/plain') + response = http.HttpResponse(text, content_type='text/plain') response['Content-Disposition'] = 'attachment; filename=%s.txt' % slug return response @@ -238,7 +238,7 @@ def book_html(request, slug): html = doc.as_html() html = html.get_string() if html is not None else '' - # response = http.HttpResponse(html, content_type='text/html', mimetype='text/html') + # response = http.HttpResponse(html, content_type='text/html') # return response # book_themes = {} # for fragment in book.fragments.all().iterator(): @@ -275,7 +275,7 @@ def book_epub(request, slug): doc = book.wldocument() # TODO: error handling epub = doc.as_epub().get_string() - response = HttpResponse(mimetype='application/epub+zip') + response = HttpResponse(content_type='application/epub+zip') response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.epub' response.write(epub) return response @@ -426,7 +426,7 @@ def chunk_edit(request, slug, chunk): }) -@transaction.commit_on_success +@transaction.atomic @login_required @require_POST def chunk_mass_edit(request): @@ -469,7 +469,7 @@ def chunk_mass_edit(request): return HttpResponse("", content_type="text/plain") -@transaction.commit_on_success +@transaction.atomic @login_required @require_POST def image_mass_edit(request): diff --git a/apps/cover/views.py b/apps/cover/views.py index 6b3344b4..4a6e575b 100644 --- a/apps/cover/views.py +++ b/apps/cover/views.py @@ -46,7 +46,7 @@ def preview(request, book, chunk=None, rev=None): except: return HttpResponseRedirect(os.path.join(settings.STATIC_URL, "img/sample_cover.png")) cover = DefaultEbookCover(info) - response = HttpResponse(mimetype=cover.mime_type()) + response = HttpResponse(content_type=cover.mime_type()) image = cover.image().resize(PREVIEW_SIZE, Image.ANTIALIAS) image.save(response, cover.format) return response diff --git a/apps/dvcs/models.py b/apps/dvcs/models.py index ec647946..e82ad193 100644 --- a/apps/dvcs/models.py +++ b/apps/dvcs/models.py @@ -329,7 +329,7 @@ class Document(models.Model): else: return None - @transaction.commit_on_success + @transaction.atomic def prepend_history(self, other): """Takes over the the other document's history and prepends to own.""" diff --git a/apps/toolbar/admin.py b/apps/toolbar/admin.py index 283ab782..654480ca 100644 --- a/apps/toolbar/admin.py +++ b/apps/toolbar/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from django.utils.translation import ugettext_lazy as _ from django import forms -from django.utils import simplejson as json +import json from toolbar import models @@ -9,6 +9,7 @@ from toolbar import models class ButtonAdminForm(forms.ModelForm): class Meta: model = models.Button + exclude = [] def clean_params(self): value = self.cleaned_data['params'] diff --git a/apps/toolbar/management/commands/fixbuttons.py b/apps/toolbar/management/commands/fixbuttons.py index ea797fcf..de48ceda 100644 --- a/apps/toolbar/management/commands/fixbuttons.py +++ b/apps/toolbar/management/commands/fixbuttons.py @@ -7,7 +7,7 @@ from django.core.management.base import NoArgsCommand from toolbar.models import Button, ButtonGroup -from django.utils import simplejson as json +import json import re diff --git a/apps/wiki/helpers.py b/apps/wiki/helpers.py index dace3d00..877a9d0e 100644 --- a/apps/wiki/helpers.py +++ b/apps/wiki/helpers.py @@ -2,7 +2,7 @@ from datetime import datetime from functools import wraps from django import http -from django.utils import simplejson as json +import json from django.utils.functional import Promise @@ -22,11 +22,11 @@ class ExtendedEncoder(json.JSONEncoder): class JSONResponse(http.HttpResponse): def __init__(self, data={}, **kwargs): - # get rid of mimetype - kwargs.pop('mimetype', None) + # get rid of content_type + kwargs.pop('content_type', None) data = json.dumps(data, cls=ExtendedEncoder) - super(JSONResponse, self).__init__(data, mimetype="application/json", **kwargs) + super(JSONResponse, self).__init__(data, content_type="application/json", **kwargs) # return errors @@ -45,7 +45,7 @@ def ajax_login_required(view): @wraps(view) def authenticated_view(request, *args, **kwargs): if not request.user.is_authenticated(): - return http.HttpResponse("Login required.", status=401, mimetype="text/plain") + return http.HttpResponse("Login required.", status=401, content_type="text/plain") return view(request, *args, **kwargs) return authenticated_view @@ -55,7 +55,7 @@ def ajax_require_permission(permission): @wraps(view) def authorized_view(request, *args, **kwargs): if not request.user.has_perm(permission): - return http.HttpResponse("Access Forbidden.", status=403, mimetype="text/plain") + return http.HttpResponse("Access Forbidden.", status=403, content_type="text/plain") return view(request, *args, **kwargs) return authorized_view return decorator diff --git a/apps/wiki/templates/admin/wiki/theme/change_list.html b/apps/wiki/templates/admin/wiki/theme/change_list.html index 919b0b96..3e5d2ea4 100755 --- a/apps/wiki/templates/admin/wiki/theme/change_list.html +++ b/apps/wiki/templates/admin/wiki/theme/change_list.html @@ -21,7 +21,7 @@ ↓ {% trans "Table for Redmine wiki" %} ↓ diff --git a/apps/wiki_img/views.py b/apps/wiki_img/views.py index 08a0a039..2b8dd67e 100644 --- a/apps/wiki_img/views.py +++ b/apps/wiki_img/views.py @@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse from wiki.helpers import (JSONResponse, JSONFormInvalid, JSONServerError, ajax_require_permission) -from django import http +from django.http import Http404, HttpResponse, HttpResponseForbidden from django.shortcuts import get_object_or_404, render from django.views.decorators.http import require_GET, require_POST from django.conf import settings @@ -188,7 +188,7 @@ def diff(request, object_id): docA = "" docB = doc.at_revision(revB).materialize() - return http.HttpResponse(nice_diff.html_diff_table(docA.splitlines(), + return HttpResponse(nice_diff.html_diff_table(docA.splitlines(), docB.splitlines(), context=3)) diff --git a/redakcja/settings/common.py b/redakcja/settings/common.py index 0c1a009f..5146dcda 100644 --- a/redakcja/settings/common.py +++ b/redakcja/settings/common.py @@ -79,7 +79,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django_cas.middleware.CASMiddleware', - 'django.middleware.doc.XViewMiddleware', + 'django.contrib.admindocs.middleware.XViewMiddleware', 'pagination.middleware.PaginationMiddleware', 'maintenancemode.middleware.MaintenanceModeMiddleware', )