Skip to content

Commit 9a2bf0b

Browse files
committed
AppealHistory savepoint via an Admin checkbox
1 parent 83278ba commit 9a2bf0b

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

api/admin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from lang.admin import TranslationAdmin, TranslationInlineModelAdmin
2424
from notifications.models import RecordType, SubscriptionType
2525

26-
from .forms import ActionForm
26+
from .forms import ActionForm, AppealForm
2727

2828
# from reversion.models import Revision
2929

@@ -422,6 +422,13 @@ class GeneralDocumentInline(admin.TabularInline, TranslationInlineModelAdmin):
422422

423423

424424
class AppealAdmin(CompareVersionAdmin, RegionRestrictedAdmin, TranslationAdmin):
425+
426+
@admin.display(description="Force history save")
427+
def force_history_save(self, obj):
428+
return obj._force_history_save
429+
430+
form = AppealForm
431+
force_history_save.boolean = False
425432
country_in = "country__pk__in"
426433
region_in = "region__pk__in"
427434
inlines = [AppealDocumentInline]
@@ -490,6 +497,7 @@ def confirm_events(self, request, queryset):
490497
def save_model(self, request, obj, form, change):
491498
if obj.country:
492499
obj.region = obj.country.region
500+
obj._force_history_save = form.cleaned_data.get("force_history_save", False)
493501
super().save_model(request, obj, form, change)
494502

495503

api/forms.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.utils.translation import gettext_lazy as _
66

77
from .logger import logger
8-
from .models import Action, ActionOrg, ActionType
8+
from .models import Action, ActionOrg, ActionType, Appeal
99

1010

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

1919

20+
class AppealForm(forms.ModelForm):
21+
force_history_save = forms.BooleanField(
22+
label="Save changes to history",
23+
required=False,
24+
initial=False,
25+
help_text="Check if changes should be saved to AppealHistory, regardless of the values of the fields.",
26+
)
27+
28+
class Meta:
29+
model = Appeal
30+
fields = "__all__"
31+
32+
2033
class LoginForm(forms.Form):
2134
email = forms.CharField(label=_("email"), required=True)
2235
password = forms.CharField(

api/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,15 @@ class Appeal(models.Model):
11791179
default=0.00,
11801180
editable=False,
11811181
)
1182+
_force_history_save = None
1183+
1184+
@property
1185+
def force_history_save(self):
1186+
return self._force_history_save
1187+
1188+
@force_history_save.setter
1189+
def force_history_save(self, value):
1190+
self._force_history_save = value
11821191

11831192
class Meta:
11841193
ordering = (

api/receivers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def add_update_appeal_history(sender, instance, created, **kwargs):
214214
if field.name not in ["id", "appeal", "valid_from", "valid_to", "aid", "amount_funded"]
215215
]
216216
now = timezone.now()
217-
changed = False
217+
changed = getattr(instance, 'force_history_save', False)
218218

219219
if created: # Appeal Insert
220220
AppealHistory.objects.create(

0 commit comments

Comments
 (0)