Compare commits
3 Commits
c72ff615ba
...
f58650effa
Author | SHA1 | Date | |
---|---|---|---|
|
f58650effa | ||
|
63b2d3ef66 | ||
|
d203046666 |
@ -26,9 +26,9 @@ def index_view(request: HttpRequest):
|
||||
A rendered view
|
||||
"""
|
||||
template = "generic_index.html"
|
||||
user = request.user
|
||||
compensations = Compensation.objects.filter(
|
||||
deleted=None,
|
||||
deleted=None, # only show those which are not deleted individually
|
||||
intervention__deleted=None, # and don't show the ones whose intervention has been deleted
|
||||
)
|
||||
table = CompensationTable(
|
||||
request=request,
|
||||
@ -42,12 +42,14 @@ def index_view(request: HttpRequest):
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def new_view(request: HttpRequest):
|
||||
# ToDo
|
||||
pass
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def edit_view(request: HttpRequest, id: str):
|
||||
# ToDo
|
||||
pass
|
||||
@ -106,12 +108,14 @@ def account_index_view(request: HttpRequest):
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def account_new_view(request: HttpRequest):
|
||||
# ToDo
|
||||
pass
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def account_edit_view(request: HttpRequest, id: str):
|
||||
# ToDo
|
||||
pass
|
||||
@ -130,6 +134,7 @@ def account_remove_view(request: HttpRequest, id: str):
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def new_payment_view(request: HttpRequest, intervention_id: str):
|
||||
""" Renders a modal view for adding new payments
|
||||
|
||||
@ -168,6 +173,7 @@ def new_payment_view(request: HttpRequest, intervention_id: str):
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def payment_remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a modal view for removing payments
|
||||
|
||||
@ -187,6 +193,7 @@ def payment_remove_view(request: HttpRequest, id: str):
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def withdraw_remove_view(request: HttpRequest, id: str, withdraw_id: str):
|
||||
""" Renders a modal view for removing withdraws
|
||||
|
||||
|
@ -18,7 +18,8 @@ from intervention.models import Intervention
|
||||
from konova.enums import UserActionLogEntryEnum
|
||||
from konova.forms import BaseForm, BaseModalForm
|
||||
from konova.models import Document
|
||||
from konova.settings import DEFAULT_LAT, DEFAULT_LON, DEFAULT_ZOOM
|
||||
from konova.settings import DEFAULT_LAT, DEFAULT_LON, DEFAULT_ZOOM, ZB_GROUP, ETS_GROUP
|
||||
from konova.utils.user_checks import in_group
|
||||
from organisation.models import Organisation
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
@ -293,6 +294,10 @@ class ShareInterventionForm(BaseModalForm):
|
||||
)
|
||||
|
||||
# Initialize users field
|
||||
# Remove field if user is not in registration or conservation group
|
||||
if not in_group(self.request.user, ZB_GROUP) and not in_group(self.request.user, ETS_GROUP):
|
||||
del self.fields["users"]
|
||||
else:
|
||||
users = self.instance.users.all()
|
||||
choices = []
|
||||
for n in users:
|
||||
|
@ -143,13 +143,9 @@ class Intervention(BaseObject):
|
||||
)
|
||||
for com in coms:
|
||||
com.deleted = action
|
||||
#com.deleted_on = _now
|
||||
#com.deleted_by = _user
|
||||
com.save()
|
||||
|
||||
self.deleted = action
|
||||
#self.deleted_on = _now
|
||||
#self.deleted_by = _user
|
||||
self.save()
|
||||
|
||||
@staticmethod
|
||||
@ -211,7 +207,7 @@ class Intervention(BaseObject):
|
||||
self.identifier = new_id
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def has_access(self, user: User):
|
||||
def is_shared_with(self, user: User):
|
||||
""" Access check
|
||||
|
||||
Checks whether a given user has access to this intervention
|
||||
|
@ -10,12 +10,14 @@
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex justify-content-end">
|
||||
{% if is_default_member and has_access %}
|
||||
<a href="{% url 'compensation:new' %}" title="{% trans 'Add new compensation' %}">
|
||||
<button class="btn btn-outline-default">
|
||||
{% fa5_icon 'plus' %}
|
||||
{% fa5_icon 'leaf' %}
|
||||
</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -45,9 +47,11 @@
|
||||
</td>
|
||||
<td class="align-middle">{{ comp.title }}</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:remove' comp.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove compensation' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -10,10 +10,12 @@
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex justify-content-end">
|
||||
{% if is_default_member and has_access %}
|
||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'intervention:new-doc' intervention.id %}" title="{% trans 'Add new document' %}">
|
||||
{% fa5_icon 'plus' %}
|
||||
{% fa5_icon 'file' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -43,9 +45,11 @@
|
||||
</td>
|
||||
<td class="align-middle">{{ doc.comment }}</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'doc-remove' doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove document' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -10,12 +10,14 @@
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex justify-content-end">
|
||||
{% if is_default_member and has_access %}
|
||||
<a href="{% url 'compensation:new' %}" title="{% trans 'Add new withdraw' %}">
|
||||
<button class="btn btn-outline-default">
|
||||
{% fa5_icon 'plus' %}
|
||||
{% fa5_icon 'tree' %}
|
||||
</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -45,9 +47,11 @@
|
||||
</td>
|
||||
<td class="align-middle">{{ withdraw.amount|floatformat:2 }} %</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:withdraw-remove' withdraw.account.id withdraw.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove Withdraw' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -10,10 +10,12 @@
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex justify-content-end">
|
||||
{% if is_default_member and has_access %}
|
||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:pay-new' intervention.id %}" title="{% trans 'Add new payment' %}">
|
||||
{% fa5_icon 'plus' %}
|
||||
{% fa5_icon 'money-bill-wave' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -47,9 +49,11 @@
|
||||
<td class="align-middle">{{ pay.due_on }}</td>
|
||||
<td class="align-middle">{{ pay.comment }}</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:pay-remove' pay.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove payment' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -27,26 +27,30 @@
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Share' %}" data-form-url="{% url 'intervention:share-create' intervention.id %}">
|
||||
{% fa5_icon 'share-alt' %}
|
||||
</button>
|
||||
{% if is_zb_member %}
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Run check' %}">
|
||||
{% fa5_icon 'star' %}
|
||||
</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if is_ets_member %}
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Record' %}">
|
||||
{% fa5_icon 'bookmark' %}
|
||||
</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if is_default_member %}
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Edit' %}">
|
||||
{% fa5_icon 'edit' %}
|
||||
</button>
|
||||
</a>
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Delete' %}">
|
||||
<button class="btn btn-default btn-modal" data-form-url="{% url 'intervention:remove' intervention.id %}" title="{% trans 'Delete' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@ -134,6 +138,14 @@
|
||||
{% endwith %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans 'Shared with' %}</th>
|
||||
<td class="align-middle">
|
||||
{% for user in intervention.users.all %}
|
||||
{% include 'user/includes/contact_modal_button.html' %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -9,8 +9,9 @@ from intervention.models import Intervention
|
||||
from intervention.tables import InterventionTable
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import *
|
||||
from konova.forms import RemoveForm, SimpleGeomForm, NewDocumentForm
|
||||
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm
|
||||
from konova.utils.message_templates import FORM_INVALID
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@login_required
|
||||
@ -45,6 +46,7 @@ def index_view(request: HttpRequest):
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def new_view(request: HttpRequest):
|
||||
"""
|
||||
Renders a view for a new intervention creation
|
||||
@ -130,7 +132,8 @@ def open_view(request: HttpRequest, id: str):
|
||||
compensations = intervention.compensations.filter(
|
||||
deleted=None,
|
||||
)
|
||||
has_access = intervention.has_access(user=request.user)
|
||||
_user = request.user
|
||||
is_data_shared = intervention.is_shared_with(user=_user)
|
||||
|
||||
geom_form = SimpleGeomForm(
|
||||
instance=intervention
|
||||
@ -139,11 +142,14 @@ def open_view(request: HttpRequest, id: str):
|
||||
context = {
|
||||
"intervention": intervention,
|
||||
"compensations": compensations,
|
||||
"has_access": has_access,
|
||||
"has_access": is_data_shared,
|
||||
"geom_form": geom_form,
|
||||
"is_default_member": in_group(_user, _(DEFAULT_GROUP)),
|
||||
"is_zb_member": in_group(_user, _(ZB_GROUP)),
|
||||
"is_ets_member": in_group(_user, _(ETS_GROUP)),
|
||||
}
|
||||
|
||||
if not has_access:
|
||||
if not is_data_shared:
|
||||
messages.info(request, _("Remember: This data has not been shared with you, yet. This means you can only read but can not edit or perform any actions like running a check or recording."))
|
||||
|
||||
context = BaseContext(request, context).context
|
||||
@ -180,6 +186,7 @@ def edit_view(request: HttpRequest, id: str):
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a remove view for this intervention
|
||||
|
||||
@ -190,21 +197,14 @@ def remove_view(request: HttpRequest, id: str):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
template = "konova/form.html"
|
||||
obj = Intervention.objects.get(id=id)
|
||||
|
||||
# ToDo
|
||||
|
||||
form = RemoveForm(
|
||||
object_to_remove=obj,
|
||||
remove_post_url=reverse("intervention:remove", args=(id,)),
|
||||
cancel_url=reverse("intervention:index"),
|
||||
identifier = obj.identifier
|
||||
form = RemoveModalForm(request.POST or None, instance=obj, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
_("{} removed").format(identifier),
|
||||
redirect_url=reverse("intervention:index")
|
||||
)
|
||||
context = {
|
||||
"form": form,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
@ -226,7 +226,7 @@ def share_view(request: HttpRequest, id: str, token: str):
|
||||
# Check tokens
|
||||
if intervention.access_token == token:
|
||||
# Send different messages in case user has already been added to list of sharing users
|
||||
if intervention.has_access(user):
|
||||
if intervention.is_shared_with(user):
|
||||
messages.info(
|
||||
request,
|
||||
_("{} has already been shared with you").format(intervention.identifier)
|
||||
@ -258,7 +258,6 @@ def create_share_view(request: HttpRequest, id: str):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
user = request.user
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = ShareInterventionForm(request.POST or None, instance=intervention, request=request)
|
||||
if request.method == "POST":
|
||||
|
@ -200,7 +200,7 @@ class RemoveModalForm(BaseModalForm):
|
||||
# If the class does not provide restorable delete functionality, we must delete the entry finally
|
||||
self.instance.delete()
|
||||
|
||||
def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID):
|
||||
def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID, redirect_url: str = None):
|
||||
""" Generic processing of request
|
||||
|
||||
Wraps the request processing logic, so we don't need the same code everywhere a RemoveModalForm is being used
|
||||
@ -213,6 +213,7 @@ class RemoveModalForm(BaseModalForm):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
redirect_url = redirect_url if redirect_url is not None else request.META.get("HTTP_REFERER", "home")
|
||||
template = self.template
|
||||
if request.method == "POST":
|
||||
if self.is_valid():
|
||||
@ -221,13 +222,13 @@ class RemoveModalForm(BaseModalForm):
|
||||
request,
|
||||
msg_success
|
||||
)
|
||||
return redirect(request.META.get("HTTP_REFERER", "home"))
|
||||
return redirect(redirect_url)
|
||||
else:
|
||||
messages.info(
|
||||
request,
|
||||
msg_error
|
||||
)
|
||||
return redirect(request.META.get("HTTP_REFERER", "home"))
|
||||
return redirect(redirect_url)
|
||||
elif request.method == "GET":
|
||||
context = {
|
||||
"form": self,
|
||||
|
@ -8,7 +8,6 @@ Created on: 17.11.20
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.gis.db.models import MultiPolygonField
|
||||
from django.db import models
|
||||
|
||||
@ -35,8 +34,6 @@ class BaseResource(UuidModel):
|
||||
A basic resource model, which defines attributes for every derived model
|
||||
"""
|
||||
created = models.ForeignKey(UserActionLogEntry, on_delete=models.SET_NULL, null=True, blank=True, related_name='+')
|
||||
#created_on = models.DateTimeField(auto_now_add=True, null=True)
|
||||
#created_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL, related_name="+")
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
@ -51,8 +48,6 @@ class BaseObject(BaseResource):
|
||||
identifier = models.CharField(max_length=1000, null=True, blank=True)
|
||||
title = models.CharField(max_length=1000, null=True, blank=True)
|
||||
deleted = models.ForeignKey(UserActionLogEntry, on_delete=models.SET_NULL, null=True, blank=True, related_name='+')
|
||||
#deleted_on = models.DateTimeField(null=True, blank=True)
|
||||
#deleted_by = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL, related_name="+")
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
|
@ -5,6 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 02.07.21
|
||||
|
||||
"""
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
@ -18,4 +19,6 @@ def in_group(user: User, group: str) -> bool:
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
return group in user.groups.values("name")
|
||||
return user.groups.filter(
|
||||
name=_(group)
|
||||
)
|
||||
|
Binary file not shown.
@ -324,7 +324,7 @@ msgstr "Ökokonto Abbuchungen"
|
||||
|
||||
#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:13
|
||||
msgid "Add new withdraw"
|
||||
msgstr ""
|
||||
msgstr "Neue Abbuchung hinzufügen"
|
||||
|
||||
#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:28
|
||||
msgid "Account Identifier"
|
||||
|
Loading…
Reference in New Issue
Block a user