Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contributions custom #248

Merged
merged 116 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
0d1186f
add load river command
submarcos Dec 14, 2023
1bdaec9
use pg triggers
submarcos Dec 19, 2023
d32ed92
use pg triggers
submarcos Dec 19, 2023
fa5fcce
use pg triggers
submarcos Dec 19, 2023
e80aabe
use pg triggers
submarcos Dec 19, 2023
29fb3b7
use pg triggers
submarcos Dec 19, 2023
cafa103
use pg triggers
submarcos Dec 19, 2023
0e8dd4b
use pg triggers
submarcos Dec 19, 2023
c06dcc2
use pg triggers
submarcos Dec 19, 2023
5f5628a
use pg triggers
submarcos Dec 19, 2023
555aaae
use internal triggers
submarcos Dec 20, 2023
dbd71b0
use internal triggers
submarcos Dec 20, 2023
7099bbf
use internal triggers
submarcos Dec 20, 2023
1b400a2
use internal triggers
submarcos Dec 20, 2023
99ff1b3
use internal triggers
submarcos Dec 20, 2023
973d134
use internal triggers
submarcos Dec 20, 2023
f02e638
use internal triggers
submarcos Dec 20, 2023
fb86bd7
use internal triggers
submarcos Dec 20, 2023
190dd0a
use internal triggers
submarcos Dec 20, 2023
111e06d
use internal triggers
submarcos Dec 20, 2023
e50be9d
use internal triggers
submarcos Dec 20, 2023
d90e775
use internal triggers
submarcos Jan 3, 2024
93bf9ba
use internal triggers
submarcos Feb 28, 2024
7f8d61c
use internal triggers
submarcos Feb 28, 2024
1861791
fix command
submarcos Apr 11, 2024
d4b75ca
lint
submarcos Apr 11, 2024
2304208
add load river command
submarcos Dec 14, 2023
1efd2bb
use pg triggers
submarcos Dec 19, 2023
4d0eae7
use pg triggers
submarcos Dec 19, 2023
4e91e6f
use pg triggers
submarcos Dec 19, 2023
28e4cb1
use pg triggers
submarcos Dec 19, 2023
68361ca
use pg triggers
submarcos Dec 19, 2023
44e04fb
use pg triggers
submarcos Dec 19, 2023
9a9c382
use pg triggers
submarcos Dec 19, 2023
61420ae
use pg triggers
submarcos Dec 19, 2023
935ebbf
use pg triggers
submarcos Dec 19, 2023
89ea540
use internal triggers
submarcos Dec 20, 2023
9ddd1b6
use internal triggers
submarcos Dec 20, 2023
6a19153
use internal triggers
submarcos Dec 20, 2023
7aacca3
use internal triggers
submarcos Dec 20, 2023
ad335b3
use internal triggers
submarcos Dec 20, 2023
dc75d4f
use internal triggers
submarcos Dec 20, 2023
74dbf82
use internal triggers
submarcos Dec 20, 2023
61e08dd
use internal triggers
submarcos Dec 20, 2023
11c071d
use internal triggers
submarcos Dec 20, 2023
02ca87e
use internal triggers
submarcos Dec 20, 2023
a501ede
use internal triggers
submarcos Dec 20, 2023
94474b1
use internal triggers
submarcos Jan 3, 2024
344aef8
use internal triggers
submarcos Feb 28, 2024
753d89f
use internal triggers
submarcos Feb 28, 2024
e1c9749
fix command
submarcos Apr 11, 2024
4ecde58
lint
submarcos Apr 11, 2024
480f98e
Add custom contribution types (#244)
submarcos Apr 13, 2024
a22c7a9
hotfix pillow
submarcos Apr 23, 2024
e594723
improve data perfs
submarcos Apr 23, 2024
7509c0a
improve data perfs
submarcos Apr 23, 2024
815c8b4
improve data perfs
submarcos Apr 23, 2024
b757b8a
add custom contrib type description
submarcos Apr 23, 2024
8549591
add station endpoint
submarcos Apr 23, 2024
ba2d0f1
add station endpoint
submarcos Apr 23, 2024
caef99d
add station endpoint
submarcos Apr 23, 2024
6fa15a8
handle 500
submarcos Apr 23, 2024
43cebd2
handle 500
submarcos Apr 23, 2024
2eb0b43
handle 500
submarcos Apr 23, 2024
ed5f0b1
handle 500
submarcos Apr 23, 2024
8e401fd
fix station endpoint
submarcos Apr 23, 2024
4ed1f17
fix station endpoint
submarcos Apr 23, 2024
aa8640b
fix station endpoint
submarcos Apr 23, 2024
ebf2452
fix station endpoint
submarcos Apr 23, 2024
17e4d9b
fix station endpoint
submarcos Apr 23, 2024
6c610f0
fix station endpoint
submarcos Apr 23, 2024
9bab6e9
fix station endpoint
submarcos Apr 23, 2024
a43f584
fix station endpoint
submarcos Apr 23, 2024
444c125
fix station endpoint
submarcos Apr 23, 2024
0a9ad86
revert default json
submarcos Apr 24, 2024
59bc763
fix and explicit default json in api responses
submarcos Apr 24, 2024
b0c0cf2
fix and explicit default json in api responses
submarcos Apr 24, 2024
c39dba4
fix and explicit default json in api responses
submarcos Apr 24, 2024
33ce6d3
fix and add contribution endpoint
submarcos Apr 24, 2024
fd2a3fe
improve load_river command
submarcos Apr 24, 2024
e1fa406
fix contributions
submarcos Apr 24, 2024
80a7a21
fix contributions
submarcos Apr 24, 2024
5088e03
pep8
submarcos Apr 24, 2024
fb6d015
pep8
submarcos Apr 24, 2024
884771b
fix migration
submarcos Apr 24, 2024
856f3a0
fix tests
submarcos Apr 25, 2024
a68359c
fix tests and station layer migration
submarcos Apr 25, 2024
dfdf435
fix migration
submarcos Apr 25, 2024
02376f8
add shared contribution_at field
submarcos Apr 25, 2024
3ffddad
add shared contribution_at field
submarcos Apr 25, 2024
8e6260a
add station json / geojson urls
submarcos Apr 25, 2024
8948299
add contributions by station endpoint
submarcos Apr 25, 2024
f1668ab
add contributions by station endpoint
submarcos Apr 25, 2024
4ca4f60
add contributions by station endpoint
submarcos Apr 25, 2024
0d49878
add contributions by station endpoint
submarcos Apr 26, 2024
143001e
add internal field
submarcos Apr 26, 2024
18d1136
add internal field
submarcos Apr 26, 2024
9f98804
fix translations
submarcos Apr 26, 2024
39532e1
add password management and allow send files
submarcos Apr 29, 2024
b2c25a0
fix password check
submarcos Apr 29, 2024
3efdf3b
Improve contribution API by station
submarcos Apr 29, 2024
88794b4
fix test
submarcos Apr 29, 2024
34ac7d2
add custom contributions endpoint and layer
submarcos Apr 29, 2024
18a78fe
fix serializer
submarcos Apr 29, 2024
08c75d2
add serializer for attachments
submarcos Apr 29, 2024
8a00a64
add attachments in admin
submarcos Apr 29, 2024
dae3655
add attachments in admin
submarcos Apr 29, 2024
f746b80
add attachments in admin
submarcos Apr 29, 2024
902561c
add attachments in admin
submarcos Apr 29, 2024
7990b76
Merge branch 'add_load_river_command' into new_contributions
submarcos Apr 29, 2024
95cb9e9
fix signal
submarcos Apr 29, 2024
f375b80
fix river trigger
submarcos Apr 29, 2024
5c19ac5
fix test
submarcos Apr 29, 2024
7033b0b
allow deploy develop branch
submarcos Apr 29, 2024
08e89d5
set changelog
submarcos Apr 29, 2024
293a190
Merge branch 'develop' into new_contributions
submarcos Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 7 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- master
- develop

release:
types:
- created
Expand All @@ -27,11 +29,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install dependencies
run: |
echo "${{ github.event_name }}! ${{ github.event.action }}"
python -m pip install --upgrade pip
python -m pip install flake8
python -m pip install flake8 -c dev-requirements.txt

- name: Lint with flake8
run: |
flake8 georiviere
Expand Down Expand Up @@ -90,40 +93,6 @@ jobs:
verbose: true
fail_ci_if_error: true # optional (default = false)

build-and-push-dev-image:
runs-on: ubuntu-latest
permissions:
packages: write # required to publish docker image
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
if: ${{(github.base_ref == 'develop')}}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


build-and-push-image:
runs-on: ubuntu-latest
needs: [flake8, doc_build, unittests]
Expand All @@ -132,7 +101,7 @@ jobs:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
if: ${{ (github.event_name == 'release' && github.event.action == 'created') || (github.ref == 'refs/heads/master' && github.event_name != 'pull_request')}}
if: ${{ (github.event_name == 'release' && github.event.action == 'created') || github.event_name != 'pull_request'}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -163,7 +132,7 @@ jobs:
needs: [ build-and-push-image ]
permissions:
contents: write # required to attach zip to release
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
if: ${{ (github.event_name == 'release' && github.event.action == 'created' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RUN apt-get update -qq && apt-get install -y -qq \
USER django

RUN python3.9 -m venv /opt/venv
RUN /opt/venv/bin/pip install --no-cache-dir pip setuptools wheel -U
RUN /opt/venv/bin/pip install --no-cache-dir pip setuptools wheel -U
# geotrek setup fix : it required django before being installed... TODO: fix it in geotrek setup.py
RUN /opt/venv/bin/pip install --no-cache-dir django==2.2.*

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deps:
docker compose run --rm web bash -c "pip-compile -q && pip-compile -q dev-requirements.in"
2 changes: 1 addition & 1 deletion dev-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ coverage
django-debug-toolbar
django-extensions
factory-boy
flake8 # WARNING : CI always use last flake8 published version
flake8

# doc
sphinx
Expand Down
29 changes: 12 additions & 17 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#
# pip-compile dev-requirements.in
#
alabaster==0.7.13
alabaster==0.7.16
# via sphinx
asgiref==3.3.1
# via
# -c requirements.txt
# django
babel==2.14.0
# via sphinx
build==1.0.3
build==1.2.1
# via pip-tools
certifi==2020.12.5
# via
Expand Down Expand Up @@ -56,7 +56,7 @@ faker==9.7.1
# via
# -c requirements.txt
# factory-boy
flake8==6.1.0
flake8==7.0.0
# via -r dev-requirements.in
freezegun==1.1.0
# via
Expand All @@ -68,7 +68,7 @@ idna==2.10
# requests
imagesize==1.4.1
# via sphinx
importlib-metadata==7.0.0
importlib-metadata==7.1.0
# via
# build
# sphinx
Expand All @@ -91,7 +91,7 @@ pip-tools==6.10.0
# via -r dev-requirements.in
pycodestyle==2.11.1
# via flake8
pyflakes==3.1.0
pyflakes==3.2.0
# via flake8
pygments==2.17.2
# via sphinx
Expand Down Expand Up @@ -126,27 +126,22 @@ sphinx==5.1.1
# via
# -r dev-requirements.in
# sphinx-rtd-theme
# sphinxcontrib-applehelp
# sphinxcontrib-devhelp
# sphinxcontrib-htmlhelp
# sphinxcontrib-jquery
# sphinxcontrib-qthelp
# sphinxcontrib-serializinghtml
sphinx-rtd-theme==2.0.0
# via -r dev-requirements.in
sphinxcontrib-applehelp==1.0.7
sphinxcontrib-applehelp==1.0.8
# via sphinx
sphinxcontrib-devhelp==1.0.5
sphinxcontrib-devhelp==1.0.6
# via sphinx
sphinxcontrib-htmlhelp==2.0.4
sphinxcontrib-htmlhelp==2.0.5
# via sphinx
sphinxcontrib-jquery==4.1
# via sphinx-rtd-theme
sphinxcontrib-jsmath==1.0.1
# via sphinx
sphinxcontrib-qthelp==1.0.6
sphinxcontrib-qthelp==1.0.7
# via sphinx
sphinxcontrib-serializinghtml==1.1.9
sphinxcontrib-serializinghtml==1.1.10
# via sphinx
sqlparse==0.4.1
# via
Expand All @@ -167,9 +162,9 @@ urllib3==1.26.3
# via
# -c requirements.txt
# requests
wheel==0.42.0
wheel==0.43.0
# via pip-tools
zipp==3.17.0
zipp==3.18.1
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
Expand Down
3 changes: 2 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CHANGELOG

**New features**

- add load_rivers command
- Add load_rivers command
- Create custom contribution types from the admin with specific field schema

**Bug fix**

Expand Down
146 changes: 129 additions & 17 deletions georiviere/contribution/admin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,131 @@
from admin_ordering.admin import OrderableAdmin
from django.contrib import admin
from django.contrib.admin.widgets import AdminFileWidget
from django.contrib.contenttypes.admin import GenericTabularInline
from django.db.models import FileField
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from leaflet.admin import LeafletGeoAdmin

from georiviere.contribution.models import (
SeverityType, LandingType, JamType, DiseaseType, DeadSpecies, InvasiveSpecies, HeritageSpecies, HeritageObservation,
FishSpecies, NaturePollution, TypePollution, ContributionStatus
)

admin.site.register(ContributionStatus, admin.ModelAdmin)
admin.site.register(SeverityType, admin.ModelAdmin)
admin.site.register(LandingType, admin.ModelAdmin)
admin.site.register(JamType, admin.ModelAdmin)
admin.site.register(DiseaseType, admin.ModelAdmin)
admin.site.register(DeadSpecies, admin.ModelAdmin)
admin.site.register(InvasiveSpecies, admin.ModelAdmin)
admin.site.register(HeritageSpecies, admin.ModelAdmin)
admin.site.register(HeritageObservation, admin.ModelAdmin)
admin.site.register(FishSpecies, admin.ModelAdmin)
admin.site.register(NaturePollution, admin.ModelAdmin)
admin.site.register(TypePollution, admin.ModelAdmin)
from . import models, forms
from ..main.models import Attachment

admin.site.register(models.ContributionStatus, admin.ModelAdmin)
admin.site.register(models.SeverityType, admin.ModelAdmin)
admin.site.register(models.LandingType, admin.ModelAdmin)
admin.site.register(models.JamType, admin.ModelAdmin)
admin.site.register(models.DiseaseType, admin.ModelAdmin)
admin.site.register(models.DeadSpecies, admin.ModelAdmin)
admin.site.register(models.InvasiveSpecies, admin.ModelAdmin)
admin.site.register(models.HeritageSpecies, admin.ModelAdmin)
admin.site.register(models.HeritageObservation, admin.ModelAdmin)
admin.site.register(models.FishSpecies, admin.ModelAdmin)
admin.site.register(models.NaturePollution, admin.ModelAdmin)
admin.site.register(models.TypePollution, admin.ModelAdmin)


class CustomFieldInline(OrderableAdmin, admin.TabularInline):
verbose_name = _("Field")
verbose_name_plural = _("Fields")
model = models.CustomContributionTypeField
ordering_field = "order"
ordering = ("order", "label")
form = forms.CustomContributionFieldInlineForm
fields = (
"label",
"internal_identifier",
"value_type",
"required",
"help_text",
"order",
)
extra = 0
show_change_link = True
popup_link = "change"


@admin.register(models.CustomContributionType)
class CustomContributionTypeAdmin(admin.ModelAdmin):
list_display = ("label",)
search_fields = ("label",)
filter_horizontal = ("stations",)
inlines = [
CustomFieldInline,
]


@admin.register(models.CustomContributionTypeField)
class CustomContributionTypeFieldAdmin(admin.ModelAdmin):
list_display = ("label", "key", "value_type", "required", "custom_type")
list_filter = ("custom_type", "value_type", "required")
search_fields = ("label", "key", "custom_type__label")
form = forms.CustomContributionFieldForm
fieldsets = (
(
None,
{
"fields": (
"custom_type",
"label",
"internal_identifier",
"key",
"value_type",
"required",
"help_text",
)
},
),
(
_("Customization"),
{
"fields": ("customization", "options"),
},
),
)

def get_readonly_fields(self, request, obj=None):
if obj and obj.pk:
return ["custom_type", "key", "options"]
return []

def has_add_permission(self, request):
"""Disable addition in list view"""
return False

def has_delete_permission(self, request, obj=None):
"""Disable deletion in list view"""
return False


class AdminImageWidget(AdminFileWidget):
def render(self, name, value, attrs=None, renderer=None):
output = []
if value and getattr(value, "url", None):
image_url = value.url
file_name = str(value)
output.append(
' <a href="%s" target="_blank"><img src="%s" alt="%s" style="max-height: 60px; max-width: 60px;"/></a> %s '
% (image_url, image_url, file_name, _(""))
)
output.append(super().render(name, value, attrs))
return mark_safe("".join(output))


class CustomContribAttachmentInline(GenericTabularInline):
model = Attachment
extra = 0
exclude = ("attachment_video", "attachment_link", "creator", "legend", "starred")
formfield_overrides = {FileField: {"widget": AdminImageWidget}}


@admin.register(models.CustomContribution)
class CustomContributionAdmin(LeafletGeoAdmin, admin.ModelAdmin):
list_display = ("custom_type", "portal", "validated", "date_insert", "date_update")
list_filter = ("custom_type", "portal", "validated")
form = forms.CustomContributionForm
inlines = [CustomContribAttachmentInline]

def get_readonly_fields(self, request, obj=None):
if not obj or not obj.pk:
return ("data",)
return []
Loading