Skip to content

Commit c3921d5

Browse files
committed
Merge branch 'master' into stage
2 parents 527ce45 + 4d190bf commit c3921d5

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed

django/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GEMEINDESCAN_WEBUI_DJANGO=0.3.2
1+
GEMEINDESCAN_WEBUI_DJANGO=0.3.3
22
DOCKER_EXEC=$(shell command -v docker > /dev/null && echo "docker-compose exec django")
33

44
.PHONY: all

django/docker/django/requirements/02.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ curtsies==0.3.1
1111
Django==3.0.3
1212
django-cors-headers==3.2.1
1313
django-filter==2.2.0
14+
django-json-widget==1.0.0
1415
django-sortedm2m==3.0.0
1516
-e git+https://github.com/svleeuwen/sortedm2m-filter-horizontal-widget.git@4ce03f6b7e6022014838afb4a8aa4691fceb9e94#egg=django_sortedm2m_filter_horizontal_widget
17+
future==0.18.2
1618
graphene==2.1.8
1719
graphene-django==2.8.1
1820
graphql-core==2.2.1

django/gsmap/admin.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from django.contrib.gis import admin
2+
from django.contrib.postgres import fields
23
from django.utils.translation import gettext as _
4+
from django_json_widget.widgets import JSONEditorWidget
35
from sortedm2m_filter_horizontal_widget.forms import SortedFilteredSelectMultiple
46
from gsmap.models import Municipality, Snapshot, Workspace
57

@@ -9,11 +11,12 @@ class MunicipalityAdmin(admin.OSMGeoAdmin):
911

1012

1113
class SnapshotAdmin(admin.OSMGeoAdmin):
12-
readonly_fields = ('id', 'created', 'modified')
14+
readonly_fields = ('id', 'created', 'modified', 'get_absolute_link')
1315
fieldsets = (
1416
(_('Meta'), {
1517
'fields': (
16-
'id', 'created', 'modified', 'is_showcase', 'archived', 'deleted', 'permission'
18+
'id', 'get_absolute_link', 'created', 'modified',
19+
'is_showcase', 'archived', 'deleted', 'permission'
1720
)
1821
}),
1922
(_('Main'), {
@@ -29,23 +32,30 @@ class SnapshotAdmin(admin.OSMGeoAdmin):
2932
# ('perimeter',),
3033
# }),
3134
)
35+
36+
formfield_overrides = {
37+
fields.JSONField: {
38+
'widget': JSONEditorWidget
39+
},
40+
}
41+
3242
list_display = ('id', 'title', 'municipality', 'permission', 'is_showcase',
3343
'created', 'modified')
3444
list_filter = ('is_showcase', 'permission')
3545
search_fields = ['title', 'municipality__name', 'municipality__canton']
3646

3747

3848
class WorkspaceAdmin(admin.OSMGeoAdmin):
39-
readonly_fields = ('id', 'created', 'modified')
49+
readonly_fields = ('id', 'created', 'modified', 'get_absolute_link')
4050
fieldsets = (
4151
(_('Meta'), {
4252
'fields': (
43-
'id', 'created', 'modified'
53+
'id', 'get_absolute_link',
54+
'created', 'modified'
4455
)
4556
}),
4657
(_('Main'), {
47-
'fields':
48-
('title', 'description', 'snapshots'),
58+
'fields': ('title', 'description', 'snapshots'),
4959
}),
5060
)
5161
list_display = ('id', 'title', 'created', 'modified')

django/gsmap/models.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from enum import IntFlag
44
from django.contrib.gis.db import models
55
from django.contrib.postgres import fields as pg_fields
6+
from django.contrib.sites.models import Site
7+
from django.utils.html import format_html
68
from sortedm2m.fields import SortedManyToManyField
79
from sorl.thumbnail import ImageField
810
from gsuser.models import User
@@ -102,10 +104,21 @@ class Meta:
102104
)
103105
user = models.ForeignKey(User, on_delete=models.CASCADE)
104106

107+
def get_absolute_link(self):
108+
domain = Site.objects.get_current().domain
109+
return format_html(
110+
f'<a href="//{domain}/{self.get_absolute_url()}" target="_blank">'
111+
f'{domain}{self.get_absolute_url()}</a>'
112+
)
113+
get_absolute_link.short_description = "Snapshot Url"
114+
115+
def get_absolute_url(self):
116+
return f'/{self.id}/'
117+
105118
def save(self, *args, **kwargs):
106119
def test_exists(pk):
107120
if self.__class__.objects.filter(pk=pk):
108-
new_id = create_slug_hash()
121+
new_id = create_slug_hash_6()
109122
test_exists(new_id)
110123
else:
111124
return pk
@@ -115,7 +128,8 @@ def test_exists(pk):
115128
super().save(*args, **kwargs)
116129

117130
def __str__(self):
118-
return f'{self.id}, {self.title}, {self.get_permission_display()}'
131+
return f'{self.municipality.fullname}, {self.title}, ' \
132+
f'{self.id} ({self.get_permission_display()})'
119133

120134

121135
class Workspace(models.Model):
@@ -134,11 +148,23 @@ class Meta:
134148

135149
snapshots = SortedManyToManyField(Snapshot)
136150

151+
def get_absolute_link(self):
152+
domain = Site.objects.get_current().domain
153+
return format_html(
154+
f'<a href="//{domain}{self.get_absolute_url()}" target="_blank">'
155+
f'{domain}{self.get_absolute_url()}</a>'
156+
)
157+
get_absolute_link.short_description = "Workspace Url"
158+
159+
def get_absolute_url(self):
160+
first_id = self.snapshots.all().first().id
161+
return f'/{self.id}/{first_id}/'
162+
137163

138164
def save(self, *args, **kwargs):
139165
def test_exists(pk):
140166
if self.__class__.objects.filter(pk=pk):
141-
new_id = create_slug_hash()
167+
new_id = create_slug_hash_5()
142168
test_exists(new_id)
143169
else:
144170
return pk

django/main/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'sorl.thumbnail',
3838
'sortedm2m',
3939
'sortedm2m_filter_horizontal_widget',
40+
'django_json_widget',
4041

4142
# own
4243
'gsuser',

docker-images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ services:
1010
hostname: vue
1111

1212
django:
13-
image: smartuse/gemeindescan-webui-django:0.3.2
13+
image: smartuse/gemeindescan-webui-django:0.3.3
1414
hostname: django

0 commit comments

Comments
 (0)