Skip to content

Commit

Permalink
Merge pull request #656 from kartoza/develop
Browse files Browse the repository at this point in the history
Version 4.4.6 (#651)
  • Loading branch information
meomancer authored Feb 29, 2024
2 parents ace3908 + 91b01e3 commit b5c331f
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 51 deletions.
2 changes: 1 addition & 1 deletion deployment/.env
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ PYTHONPATH=/home/web/django_project:/geonode
USE_DEFAULT_GEOSERVER_STYLE=False
INITIAL_FIXTURES=True

VERSION=4.4.5
VERSION=4.4.6
ISTSOS_VERSION=2.4.1-2

# ------ GEOSERVER ------
Expand Down
10 changes: 1 addition & 9 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ services:

# Geoserver backend
geoserver:
# TODO:
# Using older geoserver
# image: kartoza/sadc_gip:geoserver-3.1.netcfd
image: kartoza/geoserver:2.23.0-geo-v2023.09.15
healthcheck:
test: "curl --fail --silent --write-out 'HTTP CODE : %{http_code}\n' --output /dev/null http://127.0.0.1:8080/geoserver/rest/workspaces/geonode.html"
Expand All @@ -71,11 +68,6 @@ services:
start_period: 60s
env_file:
- .env

# TODO:
# Uncomment this if using netcfd
# environment:
# - DATABASE_URL=postgres://geonode:geonode@db:5432/geonode
volumes:
- geodatadir:/spcgeonode-geodatadir/
ports:
Expand Down Expand Up @@ -105,7 +97,7 @@ services:
- POSTGRES_USER=${GEONODE_DATABASE_USER}
- POSTGRES_PASSWORD=${GEONODE_DATABASE_PASSWORD}
volumes:
- database:/var/lib/postgresql/16/
- ./volumes/database:/var/lib/postgresql/16/
- ./backups:/backups
restart: on-failure
ports:
Expand Down
2 changes: 1 addition & 1 deletion django_project/gwml2
Submodule gwml2 updated from e80241 to 40746e
24 changes: 24 additions & 0 deletions django_project/igrac/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from adminsortable.admin import SortableAdmin
from django.contrib import admin
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from preferences.admin import PreferencesAdmin
Expand All @@ -15,6 +16,7 @@
from igrac.models.groundwater_layer import GroundwaterLayer
from igrac.models.map_slug import MapSlugMapping
from igrac.models.profile import IgracProfile
from igrac.models.registration_page import RegistrationPage
from igrac.models.site_preference import SitePreference


Expand Down Expand Up @@ -118,3 +120,25 @@ def _organisations(self, obj: GroundwaterLayer):


admin.site.register(GroundwaterLayer, GroundwaterLayerAdmin)


class RegistrationPageAdmin(admin.ModelAdmin):
list_display = ('code', 'user', 'created_at', 'url')
readonly_fields = ('code', 'user', 'created_at', 'url')

def url(self, obj: RegistrationPage):
"""Return registration url."""
if obj.user:
return 'Link is not valid'
if obj.code:
url = reverse(
'account_signup_with_code',
kwargs={'code': obj.code}
)
return format_html(
f'<a href="{url}" target="_blank">Registration URL</a>'
)
return '-'


admin.site.register(RegistrationPage, RegistrationPageAdmin)
55 changes: 34 additions & 21 deletions django_project/igrac/forms/groundwater_layer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import xml.etree.ElementTree as ET

import requests
Expand Down Expand Up @@ -81,14 +82,14 @@ def update_sql(self, tree):
elif well_type == GGMN:
mv = 'mv_well_ggmn'
sql = (
"select id, ggis_uid, original_id, name, feature_type,purpose, status, organisation, "
'number_of_measurements_level as "groundwater_level_data", '
'number_of_measurements_quality as "groundwater_quality_data", '
'number_of_measurements_yield as "abstraction_discharge", '
"country, year_of_drilling, aquifer_name, aquifer_type,manager, detail, location, created_at, created_by, last_edited_at, last_edited_by "
f"from {mv} where organisation_id IN (" +
f"{','.join(organisations)}" +
") order by created_at DESC"
"select id, ggis_uid, original_id, name, feature_type,purpose, status, organisation, "
'number_of_measurements_level as "groundwater_level_data", '
'number_of_measurements_quality as "groundwater_quality_data", '
'number_of_measurements_yield as "abstraction_discharge", '
"country, year_of_drilling, aquifer_name, aquifer_type,manager, detail, location, created_at, created_by, last_edited_at, last_edited_by "
f"from {mv} where organisation_id IN (" +
f"{','.join(organisations)}" +
") order by created_at DESC"
)
tree.find('metadata/entry/virtualTable/sql').text = sql

Expand All @@ -101,6 +102,7 @@ class CreateGroundwaterLayerForm(_BaseGroundwaterLayerForm):
help_text='The layer name that will be created.',
widget=forms.TextInput(attrs={'style': 'width:500px'})
)
loop = 1

def clean_well_type(self):
"""Well type."""
Expand Down Expand Up @@ -143,6 +145,29 @@ def clean_name(self):
)
return name

def get_dataset(
self, target_layer_name, workspace, store
):
"""Get dataset."""
if self.loop < 10:
call_command('updatelayers', filter=target_layer_name)
try:
dataset = Dataset.objects.get(
workspace=workspace, store=store, name=target_layer_name
)
if dataset and self.target_layer:
dataset.use_featureinfo_custom_template = self.target_layer.use_featureinfo_custom_template
dataset.featureinfo_custom_template = self.target_layer.featureinfo_custom_template
dataset.save()

return dataset
except Dataset.DoesNotExist:
time.sleep(2)
self.loop += 1
return self.get_dataset(target_layer_name, workspace, store)
else:
return None

def run(self):
"""Run it for duplication data."""
name = self.cleaned_data['name']
Expand Down Expand Up @@ -197,19 +222,7 @@ def run(self):
if style:
layer.default_style = style
gs_catalog.save(layer)
call_command('updatelayers', filter=target_layer_name)
try:
dataset = Dataset.objects.get(
workspace=workspace, store=store, name=target_layer_name
)
if dataset and self.target_layer:
dataset.use_featureinfo_custom_template = self.target_layer.use_featureinfo_custom_template
dataset.featureinfo_custom_template = self.target_layer.featureinfo_custom_template
dataset.save()

return dataset
except Dataset.DoesNotExist:
return None
return self.get_dataset(target_layer_name, workspace, store)
else:
raise Exception(r.content)

Expand Down
27 changes: 27 additions & 0 deletions django_project/igrac/migrations/0011_registrationpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.20 on 2024-02-23 06:10

import datetime
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('igrac', '0010_alter_groundwaterlayer_options'),
]

operations = [
migrations.CreateModel(
name='RegistrationPage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.TextField(max_length=16, unique=True)),
('created_at', models.DateTimeField(blank=True, default=datetime.datetime.now)),
('note', models.TextField(blank=True, null=True)),
('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
),
]
10 changes: 10 additions & 0 deletions django_project/igrac/models/groundwater_layer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.contrib.gis.db import models
from django.contrib.postgres.fields import ArrayField
from django.db.models.signals import post_delete
from django.dispatch import receiver

from geonode.layers.models import Dataset
from igrac.models.site_preference import SitePreference
Expand Down Expand Up @@ -29,3 +31,11 @@ def assign_template(self, target_layer=None):
layer.use_featureinfo_custom_template = target_layer.use_featureinfo_custom_template
layer.featureinfo_custom_template = target_layer.featureinfo_custom_template
layer.save()


@receiver(post_delete, sender=GroundwaterLayer)
def groundwater_layer_deleted(
sender, instance: GroundwaterLayer, using, **kwargs
):
if instance.layer:
instance.layer.delete()
48 changes: 48 additions & 0 deletions django_project/igrac/models/registration_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Registration page that needs to be used for register."""

import random
import string
from datetime import datetime

from django.contrib.auth import get_user_model
from django.db import models

User = get_user_model()


def id_generator(
size=36,
chars=string.ascii_letters + string.digits + '+_-'
):
"""ID Generator."""
return ''.join(random.choice(chars) for _ in range(size))


class RegistrationPage(models.Model):
"""Registration page that has random uuid.
User can just register through this model.
When user is created through this page, it will be invalid
and need to create new one.
"""

user = models.OneToOneField(
User, on_delete=models.SET_NULL,
blank=True, null=True
)
code = models.TextField(max_length=16, unique=True)
created_at = models.DateTimeField(
default=datetime.now, blank=True
)
note = models.TextField(
blank=True, null=True
)

def __str__(self):
return str(self.code)

def save(self, *args, **kwargs):
"""Save model."""
if not self.code:
self.code = id_generator()
return super().save(*args, **kwargs)
24 changes: 24 additions & 0 deletions django_project/igrac/templates/account/signup-not-found.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load bootstrap_tags %}
{% load igrac_bootstrap_tags %}

{% block page_title %}
<h1>Download Form.</h1>
{% endblock page_title %}

{% block extra_head %}
{% endblock %}

{% block body_outer %}
<div class="page-header">
<h1>Registration page is not found</h1>
</div>
<div class="row">
Registration is only for data providers. It is not required to access and download the resources available in the GGIS. If you are from a partner organization and you have data that could be shared in the GGIS, please reach out to the website administrator: <a href="mailto:ggis@un-igrac.org">ggis@un-igrac.org</a>
</div>
{% endblock %}

{% block extra_script %}
{% endblock %}
24 changes: 24 additions & 0 deletions django_project/igrac/templates/account/signup-not-valid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load bootstrap_tags %}
{% load igrac_bootstrap_tags %}

{% block page_title %}
<h1>Download Form.</h1>
{% endblock page_title %}

{% block extra_head %}
{% endblock %}

{% block body_outer %}
<div class="page-header">
<h1>Registration page is not valid</h1>
</div>
<div class="row">
Please request a valid registration link to the website administrator: <a href="mailto:ggis@un-igrac.org">ggis@un-igrac.org</a>.
</div>
{% endblock %}

{% block extra_script %}
{% endblock %}
1 change: 0 additions & 1 deletion django_project/igrac/templates/account/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ <h1>{% trans "Sign up" %}</h1>
<div class="row">
<form id="signup_form"
method="post"
action="{% url "account_signup" %}"
autocapitalize="off"
{% if form.is_multipart %}
enctype="multipart/form-data"
Expand Down
2 changes: 1 addition & 1 deletion django_project/igrac/templatetags/manual_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_igrac_base_left_topbar_menu(context):
} if is_logged_in else None,
{
"type": "link",
"href": "/groundwater/record/download-request",
"href": "/groundwater/record/download",
"label": "Download Well and Monitoring Data",
},
]
Expand Down
30 changes: 23 additions & 7 deletions django_project/igrac/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@

from django.conf.urls import url
from django.urls import include
from .views import HomeView, map_view_with_slug

from django.views.generic import TemplateView
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
from igrac.views import (
MapSlugMetadataDetail, MapMetadataDetail, CustomSignupView

from igrac.api_views.featured import (
FeaturedMaps
)
from igrac.g3p import (
G3PTimeseriesData,
G3PTimeseriesData,
G3PTimeseriesChart,
G3PTimeseriesChartIframe
)
from igrac.api_views.featured import (
FeaturedMaps
from igrac.views import (
MapSlugMetadataDetail, MapMetadataDetail, CustomSignupView
)
from .views import map_view_with_slug

urlpatterns = [
url(r'^view/(?P<id>[^/]+)/metadata_detail/article$',
Expand All @@ -40,6 +41,21 @@
url(r'^cms/', include(wagtailadmin_urls)),
url(r'^wagtail/documents/', include(wagtaildocs_urls)),
url(r'^about/', include(wagtail_urls)),
url(
r'^account/signup/not-found',
TemplateView.as_view(template_name='account/signup-not-found.html'),
name='account_signup_not_found'
),
url(
r'^account/signup/not-valid',
TemplateView.as_view(template_name='account/signup-not-valid.html'),
name='account_signup_not_valid'
),
url(
r'^account/signup/(?P<code>[^/]+)/',
CustomSignupView.as_view(),
name='account_signup_with_code'
),
url(
r'^account/signup/',
CustomSignupView.as_view(),
Expand Down
Loading

0 comments on commit b5c331f

Please sign in to comment.