Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from lang.admin import TranslationAdmin, TranslationInlineModelAdmin
from notifications.models import RecordType, SubscriptionType

from .forms import ActionForm
from .forms import ActionForm, AppealForm

# from reversion.models import Revision

Expand Down Expand Up @@ -445,6 +445,13 @@ class GeneralDocumentInline(admin.TabularInline, TranslationInlineModelAdmin):


class AppealAdmin(CompareVersionAdmin, RegionRestrictedAdmin, TranslationAdmin):

@admin.display(description="Force history save")
def force_history_save(self, obj):
return obj._force_history_save

form = AppealForm
force_history_save.boolean = False
country_in = "country__pk__in"
region_in = "region__pk__in"
inlines = [AppealDocumentInline]
Expand Down Expand Up @@ -513,6 +520,7 @@ def confirm_events(self, request, queryset):
def save_model(self, request, obj, form, change):
if obj.country:
obj.region = obj.country.region
obj._force_history_save = form.cleaned_data.get("force_history_save", False)
super().save_model(request, obj, form, change)


Expand Down
15 changes: 14 additions & 1 deletion api/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.translation import gettext_lazy as _

from .logger import logger
from .models import Action, ActionOrg, ActionType
from .models import Action, ActionOrg, ActionType, Appeal


class ActionForm(forms.ModelForm):
Expand All @@ -17,6 +17,19 @@ class Meta:
fields = "__all__"


class AppealForm(forms.ModelForm):
force_history_save = forms.BooleanField(
label="Save changes to history",
required=False,
initial=False,
help_text="Check if changes should be saved to AppealHistory, regardless of the values of the fields.",
)

class Meta:
model = Appeal
fields = "__all__"


class LoginForm(forms.Form):
email = forms.CharField(label=_("email"), required=True)
password = forms.CharField(
Expand Down
9 changes: 9 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,15 @@ class Appeal(models.Model):
default=0.00,
editable=False,
)
_force_history_save = None

@property
def force_history_save(self):
return self._force_history_save

@force_history_save.setter
def force_history_save(self, value):
self._force_history_save = value

class Meta:
ordering = (
Expand Down
2 changes: 1 addition & 1 deletion api/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def add_update_appeal_history(sender, instance, created, **kwargs):
if field.name not in ["id", "appeal", "valid_from", "valid_to", "aid", "amount_funded"]
]
now = timezone.now()
changed = False
changed = getattr(instance, "force_history_save", False)

if created: # Appeal Insert
AppealHistory.objects.create(
Expand Down
Loading