-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into flatgeobuf-renderer
- Loading branch information
Showing
24 changed files
with
597 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Point_2056_10fields | ||
|
||
admin.site.register(Point_2056_10fields) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class TestsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "tests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for django oapif project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") | ||
|
||
application = get_asgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import math | ||
import random | ||
import string | ||
|
||
from django.core.management import call_command | ||
from django.core.management.base import BaseCommand | ||
from django.db import transaction | ||
|
||
from tests.models import Line_2056_10fields, NoGeom_10fields, Point_2056_10fields | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Populate db with testdata" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("-s", "--size", type=int, default=10000) | ||
|
||
@transaction.atomic | ||
def handle(self, *args, **options): | ||
"""Populate db with testdata""" | ||
size = options["size"] | ||
x_start = 2508500 | ||
y_start = 1152000 | ||
step = 100 | ||
|
||
magnitude = math.ceil(math.sqrt(size)) | ||
|
||
points = [] | ||
lines = [] | ||
no_geoms = [] | ||
|
||
letters = string.ascii_lowercase | ||
|
||
for dx in range(magnitude): | ||
for dy in range(magnitude): | ||
x = x_start + dx * step | ||
y = y_start + dy * step | ||
geom_pt_wkt = f"Point({x:4f} {y:4f})" | ||
geom_line_wkt = f"LineString({x:4f} {y:4f}, {x+random.randint(10,50):4f} {y+random.randint(10,50):4f})" | ||
|
||
fields = {} | ||
for f in range(10): | ||
fields[f"field_{f}"] = "".join( | ||
random.choice(letters) for i in range(10) | ||
) | ||
|
||
no_geom = NoGeom_10fields(**fields) | ||
no_geoms.append(no_geom) | ||
|
||
fields["geom"] = geom_pt_wkt | ||
point = Point_2056_10fields(**fields) | ||
points.append(point) | ||
|
||
fields["geom"] = geom_line_wkt | ||
line = Line_2056_10fields(**fields) | ||
lines.append(line) | ||
|
||
# Create objects in batches | ||
Point_2056_10fields.objects.bulk_create(points) | ||
NoGeom_10fields.objects.bulk_create(no_geoms) | ||
Line_2056_10fields.objects.bulk_create(lines) | ||
|
||
# Call 'update_data' to update computed properties | ||
call_command("updatedata") | ||
print(f"🤖 testdata added!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from django.contrib.auth.models import Group, Permission, User | ||
from django.core.management.base import BaseCommand | ||
from django.db import transaction | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Populate db with groups, set permissions, add users" | ||
|
||
@transaction.atomic | ||
def handle(self, *args, **options): | ||
"""Populate db with groups, set permissions, add users""" | ||
adding = [] | ||
modifying = [] | ||
viewing = [] | ||
|
||
for model in ("point_2056_10fields", "nogeom_10fields", "line_2056_10fields"): | ||
adding.append(Permission.objects.get(codename=f"add_{model}")) | ||
modifying.append(Permission.objects.get(codename=f"change_{model}")) | ||
viewing.append(Permission.objects.get(codename=f"view_{model}")) | ||
|
||
editing = adding + modifying + viewing | ||
|
||
editors, _ = Group.objects.get_or_create(name="editors") | ||
viewers, _ = Group.objects.get_or_create(name="viewers") | ||
viewers_wo_lines, _ = Group.objects.get_or_create(name="viewers_without_lines") | ||
|
||
editors.save() | ||
viewers.save() | ||
|
||
editors.permissions.set(editing) | ||
viewers.permissions.set(viewing) | ||
|
||
viewer, _ = User.objects.get_or_create(username="demo_viewer") | ||
viewer_wo_lines, _ = User.objects.get_or_create( | ||
username="demo_viewer_without_lines" | ||
) | ||
editor, _ = User.objects.get_or_create(username="demo_editor") | ||
super_user = User.objects.create_superuser(username="admin", is_staff=True) | ||
|
||
for user in (viewer, viewer_wo_lines, editor, super_user): | ||
user.set_password("123") | ||
user.save() | ||
|
||
editor.groups.add(editors) | ||
viewer.groups.add(viewers) | ||
viewer_wo_lines.groups.add(viewers_wo_lines) | ||
|
||
print( | ||
f"👥 added users 'demo_editor' & 'demo_viewer' to group 'editors' and 'viewers' respectively. Permissions set accordingly." | ||
) |
Oops, something went wrong.