Skip to content

Commit

Permalink
Add models (#6)
Browse files Browse the repository at this point in the history
* Add layer model

* Add import function

* Add vector tile url

* Add tests

* Add fields on Layer

* Add API

* Add api tests

* Add permission

* Add multi tenants

* Add installer

* Remove tenants

* Add layer type field

* Update models

* Fix tests

* Add style model

* Update layer fields

* Add upload layer

* Add style defaults

* Refactor code

* Add editor url

* Integrate maputnik

* Fix maputnik static url

* Add is default

* Update tests

* Test

* Change app name

* Update maputnik

* Update models

* Change term Field to Attribute

* Add extra metadata

* Fix flake error

* Fix flake error

* Clean code

* Fix init

* Fix flake

* Fix all tests not being called
  • Loading branch information
meomancer authored Jun 6, 2024
1 parent cecf4da commit 0849226
Show file tree
Hide file tree
Showing 92 changed files with 4,751 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Context Layer Management.
# Cloud Native GIS.
name: Tests

on:
Expand Down Expand Up @@ -33,7 +33,7 @@ jobs:
name: 'Django App'
runs-on: ubuntu-latest
env:
APP_IMAGE: kartoza/context_layer_management
APP_IMAGE: kartoza/cloud_native_gis
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "maputnik"]
path = maputnik
url = [email protected]:kartoza/maputnik.git
branch = cloud-native-gis
27 changes: 0 additions & 27 deletions .run/Run Server.run.xml

This file was deleted.

22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ serve:
@echo "------------------------------------------------------------------"
@cd django_project/frontend; npm install --verbose; npm run serve;

serve-maputnik:
@echo
@echo "------------------------------------------------------------------"
@echo "Execute webpack serve command"
@echo "------------------------------------------------------------------"
@cd maputnik; npm install --verbose; npm run start;

run-build-maputnik:
@echo
@echo "------------------------------------------------------------------"
@echo "Build maptunik"
@echo "------------------------------------------------------------------"
@cd maputnik; npm install --verbose; npm run build-django;

build-maputnik: run-build-maputnik
@echo
@echo "------------------------------------------------------------------"
@echo "Change html to django"
@echo "------------------------------------------------------------------"
@cd ../../;
@python3 maputnik_html_to_django.py

down:
@echo
@echo "------------------------------------------------------------------"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Kartoza Context Layer Management
# Kartoza Cloud Native GIS
4 changes: 2 additions & 2 deletions deployment/.template.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
COMPOSE_PROJECT_NAME=context_layer_management
DJANGO_SETTINGS_MODULE=core.settings.dev
COMPOSE_PROJECT_NAME=cloud_native_gis
DJANGO_SETTINGS_MODULE=core.settings.prod
DJANGO_TAG=0.0.1
HTTP_PORT=80

Expand Down
5 changes: 0 additions & 5 deletions deployment/docker-compose.override.devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ services:
db:
volumes:
- ./volumes/database:/opt/postgres/data
- ./volumes/backups:/backups

dbbackups:
volumes:
- ./volumes/backups:/backups

worker:
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}_dev
Expand Down
2 changes: 0 additions & 2 deletions deployment/docker-compose.override.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ services:
db:
volumes:
- ./volumes/database:/opt/postgres/data
- ./volumes/backups:/backups
ports:
- "${DATABASE_PORT:-6432}:5432"

Expand Down Expand Up @@ -52,7 +51,6 @@ services:
target: dev
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}_dev
volumes:
- ../django_project:/tmp/pycharm_project_258/django_project/
- ../django_project:/home/web/django_project
- ./volumes/static:/home/web/static
- ./volumes/media:/home/web/media
Expand Down
2 changes: 1 addition & 1 deletion deployment/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
- DATABASE_PASSWORD=docker
- DATABASE_HOST=db
- RABBITMQ_HOST=rabbitmq
- DJANGO_SETTINGS_MODULE=core.settings.dev
- DJANGO_SETTINGS_MODULE=core.settings.test
- SECRET_KEY=SECRET_KEY

# Redis config
Expand Down
1 change: 0 additions & 1 deletion deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ volumes:
conf-data:
database:
nginx-cache:
backups-data:
data-volume:

x-common-django:
Expand Down
8 changes: 6 additions & 2 deletions deployment/docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Django==4.2.7

# Web APIs for Django
djangorestframework==3.14.0
drf-nested-routers==0.93.5
django-cors-headers==4.3.1

# Geographic add-ons for Django Rest Framework
djangorestframework-gis==1.0
Expand All @@ -28,12 +30,14 @@ django-cleanup==7.0.0
django-celery-results==2.5.0

# psycopg2 - Python-PostgreSQL Database Adapter
# psycopg2-binary==2.9.3
psycopg2-binary==2.9.9

# This extension enables you to store the periodic task schedule in the database.
django-celery-beat==2.5.0

# Python client for Redis database and key-value store
redis==4.3.4

psycopg2-binary==2.9.9
# Library to handle geospatial functions
GeoAlchemy2==0.15.1
geopandas==0.13.2
2 changes: 1 addition & 1 deletion django_project/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Context Layer Management."""
"""Cloud Native GIS."""
1 change: 1 addition & 0 deletions django_project/cloud_native_gis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Cloud Native GIS."""
5 changes: 5 additions & 0 deletions django_project/cloud_native_gis/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Cloud Native GIS."""

from .general import *
from .layer import *
from .style import *
17 changes: 17 additions & 0 deletions django_project/cloud_native_gis/admin/general.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# coding=utf-8
"""Cloud Native GIS."""

from django.contrib import admin

from cloud_native_gis.models.general import License


class LicenseAdmin(admin.ModelAdmin):
"""License admin."""

list_display = (
'name', 'description'
)


admin.site.register(License, LicenseAdmin)
90 changes: 90 additions & 0 deletions django_project/cloud_native_gis/admin/layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# coding=utf-8
"""Cloud Native GIS."""

from django.contrib import admin
from django.utils.safestring import mark_safe

from cloud_native_gis.forms.layer import LayerForm, LayerUploadForm
from cloud_native_gis.models.layer import Layer, LayerAttributes
from cloud_native_gis.models.layer_upload import LayerUpload
from cloud_native_gis.tasks import import_data
from cloud_native_gis.utils.layer import layer_api_url, MAPUTNIK_URL


class LayerAttributeInline(admin.TabularInline):
"""LayerAttribute inline."""

model = LayerAttributes
extra = 0

def has_add_permission(self, request, obj):
"""Disable add permission."""
return False


@admin.action(description='Import data')
def start_upload_data(modeladmin, request, queryset):
"""Import data of layer."""
for layer in queryset:
import_data.delay(layer.pk)


class LayerAdmin(admin.ModelAdmin):
"""Layer admin."""

list_display = (
'unique_id', 'name', 'created_by', 'created_at', 'tile_url', 'editor'
)
form = LayerForm
inlines = [LayerAttributeInline]
filter_horizontal = ['styles']

def get_form(self, request, *args, **kwargs):
"""Return form."""
form = super(LayerAdmin, self).get_form(request, *args, **kwargs)
form.user = request.user
return form

def get_queryset(self, request):
"""Return queryset for current request."""
self.request = request
return super().get_queryset(request)

def tile_url(self, obj: Layer):
"""Return tile_url."""
return obj.absolute_tile_url(self.request)

def field_names(self, obj: Layer):
"""Return fields."""
return obj.field_names

def editor(self, obj: Layer):
"""Return fields."""
return mark_safe(
f"<a target='__blank__' href='{MAPUTNIK_URL}?"
f"api-url={layer_api_url(obj, self.request)}"
f"'>Editor</a>"
)

editor.allow_tags = True


class LayerUploadAdmin(admin.ModelAdmin):
"""Layer admin."""

list_display = (
'created_at', 'created_by', 'layer', 'status', 'progress', 'note'
)
list_filter = ['layer', 'status']
actions = [start_upload_data]
form = LayerUploadForm

def get_form(self, request, *args, **kwargs):
"""Return form."""
form = super(LayerUploadAdmin, self).get_form(request, *args, **kwargs)
form.user = request.user
return form


admin.site.register(Layer, LayerAdmin)
admin.site.register(LayerUpload, LayerUploadAdmin)
25 changes: 25 additions & 0 deletions django_project/cloud_native_gis/admin/style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# coding=utf-8
"""Cloud Native GIS."""

from django.contrib import admin

from cloud_native_gis.forms.style import StyleForm
from cloud_native_gis.models.style import Style


class StyleAdmin(admin.ModelAdmin):
"""Layer Style admin."""

form = StyleForm
list_display = (
'name', 'created_by', 'created_at'
)

def get_form(self, request, *args, **kwargs):
"""Return form."""
form = super(StyleAdmin, self).get_form(request, *args, **kwargs)
form.user = request.user
return form


admin.site.register(Style, StyleAdmin)
Empty file.
Loading

0 comments on commit 0849226

Please sign in to comment.