Update juries lines in Google Sheet after a pool update (not on every save)

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-03-31 13:23:58 +02:00
parent 29b01ebb13
commit 412ff4e067
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 11 additions and 5 deletions

View File

@ -1299,11 +1299,6 @@ class Pool(models.Model):
note.set_all(*note_line)
note.save()
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
if os.getenv('GOOGLE_PRIVATE_KEY_ID', None): # Google Sheets support is enabled
self.update_juries_lines_spreadsheet()
super().save(force_insert, force_update, using, update_fields)
def __str__(self):
return _("Pool of day {round} for tournament {tournament} with teams {teams}")\
.format(round=self.round,

View File

@ -880,6 +880,13 @@ class PoolUpdateView(VolunteerMixin, UpdateView):
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
def form_valid(self, form):
ret = super().form_valid(form)
# Update Google Sheets juries lines
if os.getenv('GOOGLE_PRIVATE_KEY_ID', None):
self.object.update_juries_lines_spreadsheet()
return ret
class PoolUpdateTeamsView(VolunteerMixin, UpdateView):
model = Pool
@ -1075,6 +1082,10 @@ class PoolJuryView(VolunteerMixin, FormView, DetailView):
self.object.juries.add(reg)
self.object.save()
# Update Google Sheets juries lines
if os.getenv('GOOGLE_PRIVATE_KEY_ID', None):
self.object.update_juries_lines_spreadsheet()
# Add notification
messages.success(self.request, _("The jury {name} has been successfully added!")
.format(name=f"{user.first_name} {user.last_name}"))