Skip to content

Commit

Permalink
[style] Format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed Nov 24, 2023
1 parent 9840019 commit 3ae3acc
Show file tree
Hide file tree
Showing 38 changed files with 446 additions and 252 deletions.
5 changes: 1 addition & 4 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"umap.settings"
)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "umap.settings")

from django.core.management import execute_from_command_line

Expand Down
10 changes: 7 additions & 3 deletions umap/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from django.contrib.gis import admin
from .models import Map, DataLayer, Pictogram, TileLayer, Licence

from .models import DataLayer, Licence, Map, Pictogram, TileLayer


class TileLayerAdmin(admin.ModelAdmin):
list_display = ('name', 'rank', )
list_editable = ('rank', )
list_display = (
"name",
"rank",
)
list_editable = ("rank",)


class MapAdmin(admin.GISModelAdmin):
Expand Down
8 changes: 3 additions & 5 deletions umap/autocomplete.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from agnocomplete.core import AgnocompleteModel
from agnocomplete.register import register
from django.conf import settings
from django.contrib.auth import get_user_model


from agnocomplete.register import register
from agnocomplete.core import AgnocompleteModel


@register
class AutocompleteUser(AgnocompleteModel):
model = get_user_model()
fields = settings.USER_AUTOCOMPLETE_FIELDS

def item(self, current_item):
data = super().item(current_item)
data['url'] = current_item.get_url()
data["url"] = current_item.get_url()
return data
7 changes: 2 additions & 5 deletions umap/bin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@


def main():
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"umap.settings"
)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "umap.settings")
management.execute_from_command_line()


if __name__ == '__main__':
if __name__ == "__main__":
main()
9 changes: 4 additions & 5 deletions umap/decorators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from functools import wraps

from django.urls import reverse_lazy
from django.shortcuts import get_object_or_404
from django.http import HttpResponseForbidden
from django.conf import settings
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy

from .views import simple_json_response
from .models import Map

from .views import simple_json_response

LOGIN_URL = getattr(settings, "LOGIN_URL", "login")
LOGIN_URL = reverse_lazy(LOGIN_URL) if not LOGIN_URL.startswith("/") else LOGIN_URL
Expand Down
10 changes: 5 additions & 5 deletions umap/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django import forms
from django.contrib.gis.geos import Point
from django.contrib.auth import get_user_model
from django.utils.translation import gettext_lazy as _
from django.template.defaultfilters import slugify
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.gis.geos import Point
from django.forms.utils import ErrorList
from django.template.defaultfilters import slugify
from django.utils.translation import gettext_lazy as _

from .models import Map, DataLayer
from .models import DataLayer, Map

DEFAULT_LATITUDE = (
settings.LEAFLET_LATITUDE if hasattr(settings, "LEAFLET_LATITUDE") else 51
Expand Down
20 changes: 9 additions & 11 deletions umap/management/commands/generate_js_locale.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
from pathlib import Path

from django.core.management.base import BaseCommand
from django.conf import settings
from django.core.management.base import BaseCommand
from django.template.loader import render_to_string
from django.utils.translation import to_locale

ROOT = Path(settings.PROJECT_DIR) / 'static/umap/locale/'
ROOT = Path(settings.PROJECT_DIR) / "static/umap/locale/"


class Command(BaseCommand):

def handle(self, *args, **options):
self.verbosity = options['verbosity']
self.verbosity = options["verbosity"]
for code, name in settings.LANGUAGES:
code = to_locale(code)
if self.verbosity > 0:
print("Processing", name)
path = ROOT / '{code}.json'.format(code=code)
path = ROOT / "{code}.json".format(code=code)
if not path.exists():
print(path, 'does not exist.', 'Skipping')
print(path, "does not exist.", "Skipping")
else:
with path.open(encoding="utf-8") as f:
if self.verbosity > 1:
print("Found file", path)
self.render(code, f.read())

def render(self, code, json):
path = ROOT / '{code}.js'.format(code=code)
path = ROOT / "{code}.js".format(code=code)
with path.open("w", encoding="utf-8") as f:
content = render_to_string('umap/locale.js', {
"locale": json,
"locale_code": code
})
content = render_to_string(
"umap/locale.js", {"locale": json, "locale_code": code}
)
if self.verbosity > 1:
print("Exporting to", path)
f.write(content)
2 changes: 1 addition & 1 deletion umap/management/commands/import_pictograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def handle_directory(self, path):
else:
picto = Pictogram()
picto.name = name
if (path.name != self.path.name): # Subfolders only
if path.name != self.path.name: # Subfolders only
picto.category = path.name
picto.attribution = self.attribution
with (path / filename).open("rb") as f:
Expand Down
8 changes: 5 additions & 3 deletions umap/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


class PublicManager(Manager):

def get_queryset(self):
return super(PublicManager, self).get_queryset().filter(
share_status=self.model.PUBLIC)
return (
super(PublicManager, self)
.get_queryset()
.filter(share_status=self.model.PUBLIC)
)
5 changes: 2 additions & 3 deletions umap/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@


def readonly_middleware(get_response):

if not settings.UMAP_READONLY:
raise MiddlewareNotUsed

def middleware(request):
if request.method not in ['GET', 'OPTIONS']:
return HttpResponseForbidden(_('Site is readonly for maintenance'))
if request.method not in ["GET", "OPTIONS"]:
return HttpResponseForbidden(_("Site is readonly for maintenance"))

return get_response(request)

Expand Down
Loading

0 comments on commit 3ae3acc

Please sign in to comment.