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
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),
status = resp['status']
if status == '200':
- return simplejson.loads(content)
+ return json.loads(content)
elif status.startswith('2'):
return
elif status == '401':
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):
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
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]*)')
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).'
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)
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)
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)
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."""
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
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
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
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
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():
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
})
-@transaction.commit_on_success
+@transaction.atomic
@login_required
@require_POST
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):
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
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."""
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
class ButtonAdminForm(forms.ModelForm):
class Meta:
model = models.Button
+ exclude = []
def clean_params(self):
value = self.cleaned_data['params']
from django.core.management.base import NoArgsCommand
from toolbar.models import Button, ButtonGroup
-from django.utils import simplejson as json
+import json
import re
from functools import wraps
from django import http
-from django.utils import simplejson as json
+import json
from django.utils.functional import Promise
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
@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
@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
<a id="redmine-table-switch">↓ {% trans "Table for Redmine wiki" %} ↓</a>
<div id="redmine-table" style="display:none; padding:1em; border: 1px solid #aaa;">
- |{% for theme in cl.get_query_set %}[[{{ theme }}]]|{% if forloop.counter|divisibleby:7 %}<br/>
+ |{% for theme in cl.get_queryset %}[[{{ theme }}]]|{% if forloop.counter|divisibleby:7 %}<br/>
|{% endif %}{% endfor %}
</div>
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
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))
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_cas.middleware.CASMiddleware',
- 'django.middleware.doc.XViewMiddleware',
+ 'django.contrib.admindocs.middleware.XViewMiddleware',
'pagination.middleware.PaginationMiddleware',
'maintenancemode.middleware.MaintenanceModeMiddleware',
)