-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add load river command * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * fix command * lint * add load river command * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use pg triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * use internal triggers * fix command * lint * Add custom contribution types (#244) * Configure custom contribution type in admin * hotfix pillow * improve data perfs * improve data perfs * improve data perfs * add custom contrib type description * add station endpoint * add station endpoint * add station endpoint * handle 500 * handle 500 * handle 500 * handle 500 * fix station endpoint * fix station endpoint * fix station endpoint * fix station endpoint * fix station endpoint * fix station endpoint * fix station endpoint * fix station endpoint * fix station endpoint * revert default json * fix and explicit default json in api responses * fix and explicit default json in api responses * fix and explicit default json in api responses * fix and add contribution endpoint * improve load_river command * fix contributions * fix contributions * pep8 * pep8 * fix migration * fix tests * fix tests and station layer migration * fix migration * add shared contribution_at field * add shared contribution_at field * add station json / geojson urls * add contributions by station endpoint * add contributions by station endpoint * add contributions by station endpoint * add contributions by station endpoint * add internal field * add internal field * fix translations * add password management and allow send files * fix password check * Improve contribution API by station * fix test * add custom contributions endpoint and layer * fix serializer * add serializer for attachments * add attachments in admin * add attachments in admin * add attachments in admin * add attachments in admin * fix signal * fix river trigger * fix test * allow deploy develop branch * set changelog
- Loading branch information
Showing
84 changed files
with
3,181 additions
and
1,274 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
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" |
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
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 [] |
Oops, something went wrong.