Skip to content

Commit

Permalink
Run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mojken committed Mar 31, 2022
1 parent 3c520bd commit 8561900
Show file tree
Hide file tree
Showing 77 changed files with 1,026 additions and 862 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -22,4 +22,4 @@ example/db.sqlite3
*~
\#*\#
.#*.*
*_flymake*
*_flymake*
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -28,11 +28,11 @@ Example settings for Django 2.0:

INSTALLED_APPS = (
# ...
'djedi',
"djedi",
)

MIDDLEWARE = [
'djedi.middleware.translation.DjediTranslationMiddleware',
"djedi.middleware.translation.DjediTranslationMiddleware",
# ...
]
```
Expand All @@ -49,7 +49,7 @@ $ django-admin.py migrate djedi
# urls.py

urlpatterns = [
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
]
```

Expand Down
2 changes: 1 addition & 1 deletion djedi-react/.npm-upgrade.json
Expand Up @@ -9,4 +9,4 @@
"reason": "Not compatible with newer versions"
}
}
}
}
4 changes: 2 additions & 2 deletions djedi-react/test/Node.test.js
Expand Up @@ -319,7 +319,7 @@ test("it handles nodes with null value in response", async () => {
<span
data-i18n="en-us@test"
>
</span>
`);
});
Expand Down Expand Up @@ -773,7 +773,7 @@ Network error",
<span
data-i18n="en-us@5"
>
</span>
</article>
</div>
Expand Down
57 changes: 34 additions & 23 deletions djedi/__init__.py
@@ -1,25 +1,25 @@
# coding=utf-8
VERSION = (1, 3, 3, 'final', 0)
VERSION = (1, 3, 3, "final", 0)


def get_version(version=None):
"""Derives a PEP386-compliant version number from VERSION."""
if version is None:
version = VERSION
assert len(version) == 5
assert version[3] in ('alpha', 'beta', 'rc', 'final')
assert version[3] in ("alpha", "beta", "rc", "final")

# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|c}N - for alpha, beta and rc releases

parts = 2 if version[2] == 0 else 3
main = '.'.join(str(x) for x in version[:parts])
main = ".".join(str(x) for x in version[:parts])

sub = ''
if version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
sub = ""
if version[3] != "final":
mapping = {"alpha": "a", "beta": "b", "rc": "c"}
sub = mapping[version[3]] + str(version[4])

return main + sub
Expand All @@ -30,33 +30,44 @@ def get_version(version=None):

def configure():
from django.conf import settings as django_settings

from cio.conf import settings

# Djedi default config
config = dict(
ENVIRONMENT={
'default': {
'i18n': django_settings.LANGUAGE_CODE,
'l10n': getattr(django_settings, 'ROOT_URLCONF', 'local').split('.', 1)[0],
'g11n': 'global'
config = {
"ENVIRONMENT": {
"default": {
"i18n": django_settings.LANGUAGE_CODE,
"l10n": getattr(django_settings, "ROOT_URLCONF", "local").split(".", 1)[
0
],
"g11n": "global",
}
},
CACHE='djedi.backends.django.cache.Backend',
STORAGE='djedi.backends.django.db.Backend',
PLUGINS=[
'cio.plugins.txt.TextPlugin',
'cio.plugins.md.MarkdownPlugin',
'djedi.plugins.img.ImagePlugin'
"CACHE": "djedi.backends.django.cache.Backend",
"STORAGE": "djedi.backends.django.db.Backend",
"PLUGINS": [
"cio.plugins.txt.TextPlugin",
"cio.plugins.md.MarkdownPlugin",
"djedi.plugins.img.ImagePlugin",
],
THEME='darth'
)
"THEME": "darth",
}

# Update config with global djedi django settings
config.update(getattr(django_settings, 'DJEDI', {}))
config.update(getattr(django_settings, "DJEDI", {}))

# Overwrite config with prefixed variables from django settings
for setting in ('ENVIRONMENT', 'CACHE', 'STORAGE', 'PIPELINE', 'PLUGINS', 'THEME', 'XSS_DOMAIN'):
conf = getattr(django_settings, 'DJEDI_%s' % setting, None)
for setting in (
"ENVIRONMENT",
"CACHE",
"STORAGE",
"PIPELINE",
"PLUGINS",
"THEME",
"XSS_DOMAIN",
):
conf = getattr(django_settings, "DJEDI_%s" % setting, None)
if conf is not None:
config[setting] = conf

Expand Down
31 changes: 20 additions & 11 deletions djedi/admin/__init__.py
@@ -1,23 +1,32 @@
from django.contrib import admin
from django.db.models import Model
from django.template.defaultfilters import pluralize

from djedi.admin import cms


def register(admin_class):
name = admin_class.verbose_name
name_plural = getattr(admin_class, 'verbose_name_plural', pluralize(name))
name_plural = getattr(admin_class, "verbose_name_plural", pluralize(name))

model = type(name, (Model,), {
'__module__': __name__,
'Meta': type('Meta', (object,), dict(
managed=False,
abstract=True,
app_label='djedi',
verbose_name=name,
verbose_name_plural=name_plural
))
})
model = type(
name,
(Model,),
{
"__module__": __name__,
"Meta": type(
"Meta",
(object,),
{
"managed": False,
"abstract": True,
"app_label": "djedi",
"verbose_name": name,
"verbose_name_plural": name_plural,
},
),
},
)

admin.site._registry[model] = admin_class(model, admin.site)

Expand Down
54 changes: 26 additions & 28 deletions djedi/admin/api.py
@@ -1,8 +1,7 @@
from collections import defaultdict
from djedi.plugins.base import DjediPlugin

from django.core.exceptions import PermissionDenied
from django.http import HttpResponse, Http404, HttpResponseBadRequest
from django.http import Http404, HttpResponse, HttpResponseBadRequest
from django.utils.http import urlunquote
from django.views.decorators.cache import never_cache
from django.views.decorators.clickjacking import xframe_options_exempt
Expand All @@ -13,15 +12,15 @@
from cio.plugins import plugins
from cio.plugins.exceptions import UnknownPlugin
from cio.utils.uri import URI
from djedi.plugins.base import DjediPlugin

from .exceptions import InvalidNodeData
from .mixins import JSONResponseMixin, DjediContextMixin
from ..compat import TemplateResponse
from .. import auth
from ..compat import TemplateResponse
from .exceptions import InvalidNodeData
from .mixins import DjediContextMixin, JSONResponseMixin


class APIView(View):

@csrf_exempt
def dispatch(self, request, *args, **kwargs):
if not auth.has_permission(request):
Expand Down Expand Up @@ -50,17 +49,19 @@ def get_post_data(self, request):
if isinstance(value, list) and len(value) <= 1:
value = value[0] if value else None

prefix, _, field = param.partition('[')
prefix, _, field = param.partition("[")
if field:
field = field[:-1]
try:
data[prefix][field] = value
except TypeError:
raise InvalidNodeData('Got both reserved parameter "data" and plugin specific parameters.')
raise InvalidNodeData(
'Got both reserved parameter "data" and plugin specific parameters.'
)
else:
data[prefix] = value

return data['data'], data['meta']
return data["data"], data["meta"]

def decode_uri(self, uri):
decoded = urlunquote(uri)
Expand All @@ -71,12 +72,11 @@ def decode_uri(self, uri):

return decoded

def render_to_response(self, content=u''):
def render_to_response(self, content=""):
return HttpResponse(content)


class NodeApi(JSONResponseMixin, APIView):

@never_cache
def get(self, request, uri):
"""
Expand All @@ -91,10 +91,7 @@ def get(self, request, uri):
if node.content is None:
raise Http404

return self.render_to_json({
'uri': node.uri,
'content': node.content
})
return self.render_to_json({"uri": node.uri, "content": node.content})

def post(self, request, uri):
"""
Expand All @@ -105,7 +102,7 @@ def post(self, request, uri):
"""
uri = self.decode_uri(uri)
data, meta = self.get_post_data(request)
meta['author'] = auth.get_username(request)
meta["author"] = auth.get_username(request)
node = cio.set(uri, data, publish=False, **meta)
return self.render_to_json(node)

Expand All @@ -123,7 +120,6 @@ def delete(self, request, uri):


class PublishApi(JSONResponseMixin, APIView):

def put(self, request, uri):
"""
Publish versioned uri.
Expand All @@ -141,7 +137,6 @@ def put(self, request, uri):


class RevisionsApi(JSONResponseMixin, APIView):

def get(self, request, uri):
"""
List uri revisions.
Expand All @@ -151,12 +146,13 @@ def get(self, request, uri):
"""
uri = self.decode_uri(uri)
revisions = cio.revisions(uri)
revisions = [list(revision) for revision in revisions] # Convert tuples to lists
revisions = [
list(revision) for revision in revisions
] # Convert tuples to lists
return self.render_to_json(revisions)


class LoadApi(JSONResponseMixin, APIView):

@never_cache
def get(self, request, uri):
"""
Expand All @@ -171,7 +167,6 @@ def get(self, request, uri):


class RenderApi(APIView):

def post(self, request, ext):
"""
Render data for plugin and return text response.
Expand All @@ -188,7 +183,6 @@ def post(self, request, ext):


class NodeEditor(JSONResponseMixin, DjediContextMixin, APIView):

@never_cache
@xframe_options_exempt
def get(self, request, uri):
Expand All @@ -210,19 +204,23 @@ def get(self, request, uri):
def post(self, request, uri):
uri = self.decode_uri(uri)
data, meta = self.get_post_data(request)
meta['author'] = auth.get_username(request)
meta["author"] = auth.get_username(request)
node = cio.set(uri, data, publish=False, **meta)

context = cio.load(node.uri)
context['content'] = node.content
context["content"] = node.content

if request.is_ajax():
return self.render_to_json(context)
else:
return self.render_plugin(request, context)

def render_plugin(self, request, context):
return TemplateResponse(request, [
'djedi/plugins/%s/editor.html' % context['uri'].ext,
'djedi/plugins/base/editor.html'
], self.get_context_data(**context))
return TemplateResponse(
request,
[
"djedi/plugins/%s/editor.html" % context["uri"].ext,
"djedi/plugins/base/editor.html",
],
self.get_context_data(**context),
)
11 changes: 6 additions & 5 deletions djedi/admin/cms.py
Expand Up @@ -10,13 +10,15 @@

class Admin(ModelAdmin):

verbose_name = 'CMS'
verbose_name = "CMS"
verbose_name_plural = verbose_name

def get_urls(self):
return patterns(
url(r'^', include('djedi.admin.urls', namespace='djedi')),
url(r'', lambda: None, name='djedi_cms_changelist') # Placeholder to show change link to CMS in admin
url(r"^", include("djedi.admin.urls", namespace="djedi")),
url(
r"", lambda: None, name="djedi_cms_changelist"
), # Placeholder to show change link to CMS in admin
)

def has_change_permission(self, request, obj=None):
Expand All @@ -35,10 +37,9 @@ def has_module_permission(self, request):


class DjediCMS(DjediContextMixin, View):

@xframe_options_exempt
def get(self, request):
if has_permission(request):
return render(request, 'djedi/cms/cms.html', self.get_context_data())
return render(request, "djedi/cms/cms.html", self.get_context_data())
else:
raise PermissionDenied

0 comments on commit 8561900

Please sign in to comment.