Skip to content

Commit

Permalink
Rename VotingPhase.registration_start and friends, explicit _model in…
Browse files Browse the repository at this point in the history
… cell

registration_start, registration_end, voting_start and voting_end are
of type datetime and I got confused by the naming.

Also, in some places in `VotingPhaseCell` they were accessed via the getattr magic of
Cell which should only be used in templates. Explicit `self._model` is
better (especially when we will have typed `_model` in the future).
  • Loading branch information
dpausp committed Jan 2, 2024
1 parent 905232c commit 51ab8f9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@
= _("could_not_vote_currently")

if show_registration
p.help-text.mb-2= _("registration_links_help_text", end=registration_end|datetimeformat)
p.help-text.mb-2= _("registration_links_help_text", end=registration_ends_at|datetimeformat)
for title, url in votings
p
a.btn.btn-primary.btn-sm(href=url,target='_blank')
i.fas.fa-sign-in-alt  
= _('register_now_with_voting_module', title=title)

if show_voting_without_url
p.help-text.mb-2= _("voting_info_text", end=voting_end|datetimeformat)
p.help-text.mb-2= _("voting_info_text", end=voting_ends_at|datetimeformat)

if show_voting_with_url
p.help-text.mb-2= _("voting_links_help_text", end=voting_end|datetimeformat)
p.help-text.mb-2= _("voting_links_help_text", end=voting_ends_at|datetimeformat)
for title, url in votings
p
a.btn.btn-primary.btn-sm(href=url,target='_blank')
Expand Down Expand Up @@ -93,13 +93,13 @@
dt
i.fas.fa-sign-in-alt  
= _('registration_from')
dd= _('start_end_duration', start=registration_start|datetimeformat, end=registration_end|datetimeformat)
dd= _('start_end_duration', start=registration_starts_at|datetimeformat, end=registration_ends_at|datetimeformat)

if show_voting_period
dt
i.fas.fa-person-booth  
= _('voting_from')
dd= _('start_end_duration', start=voting_start|datetimeformat, end=voting_end|datetimeformat)
dd= _('start_end_duration', start=voting_starts_at|datetimeformat, end=voting_ends_at|datetimeformat)
else
dt= _('voting_status')
dd= status|enum_value
Expand Down
48 changes: 25 additions & 23 deletions src/ekklesia_portal/concepts/voting_phase/voting_phase_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ def show_new_button(self):
@App.cell(VotingPhase)
class VotingPhaseCell(LayoutCell):

_model: VotingPhase

model_properties = [
'ballots',
'department',
'description',
'name',
'phase_type',
'registration_end',
'registration_start',
'registration_ends_at',
'registration_starts_at',
'secret',
'status',
'target',
'title',
'voting_end',
'voting_start',
'voting_ends_at',
'voting_starts_at',
]

def show_edit_button(self):
Expand All @@ -60,16 +62,16 @@ def show_voting_details(self):
return False

def show_registration_period(self):
if self.registration_end is None:
if self._model.registration_ends_at is None:
return

return datetime.now() < self.registration_end
return datetime.now() < self._model.registration_ends_at

def show_voting_period(self):
if self.voting_end is None:
if self._model.voting_ends_at is None:
return

return datetime.now() < self.voting_end
return datetime.now() < self._model.voting_ends_at

def can_participate_in_voting(self):
user = self._request.current_user
Expand All @@ -89,13 +91,13 @@ def show_registration(self):
if not self.can_participate_in_voting:
return

if self.registration_start is None:
if self._model.registration_starts_at is None:
return

if not self.votings:
return

return self.registration_start < datetime.now() < self.registration_end
return self.registration_start < datetime.now() < self._model.registration_ends_at

def show_will_be_able_to_vote(self):
if self._request.current_user is None:
Expand All @@ -104,10 +106,10 @@ def show_will_be_able_to_vote(self):
if self._model.status not in (VotingStatus.PREPARING, VotingStatus.VOTING):
return

if self.registration_start:
return datetime.now() < self.registration_start
elif self.voting_start:
return datetime.now() < self.voting_start
if self._model.registration_starts_at:
return datetime.now() < self._model.registration_starts_at
elif self._model.voting_starts_at:
return datetime.now() < self._model.voting_starts_at
else:
return True

Expand All @@ -122,13 +124,13 @@ def show_voting_without_url(self):
if not self.votings:
return

if self.registration_start is None:
if self._model.registration_starts_at is None:
return

if self.voting_start is None:
return

return self.voting_start < datetime.now() < self.voting_end
return self._model.voting_starts_at < datetime.now() < self._model.voting_ends_at

def show_voting_with_url(self):
"""Determines if voting info should be shown.
Expand All @@ -138,16 +140,16 @@ def show_voting_with_url(self):
if not self.can_participate_in_voting:
return

if self.registration_start is not None:
if self._model.registration_starts_at:
return

if not self.votings:
return

if self.voting_start is None:
if self._model.voting_starts_at is None:
return

return self.voting_start < datetime.now() < self.voting_end
return self._model.voting_starts_at < datetime.now() < self._model.voting_ends_at

def show_result_link(self):
"""
Expand All @@ -156,10 +158,10 @@ def show_result_link(self):
if not self.votings:
return

if self.voting_end is None:
if self._model.voting_ends_at is None:
return

return self.voting_end < datetime.now()
return self._model.voting_ends_at < datetime.now()

def ballot_count(self):
return len(self._model.ballots)
Expand Down Expand Up @@ -276,7 +278,7 @@ def retrieve_voting_action(self):
return self._request.link(self._model, "retrieve_voting")

def allow_retrieve_results(self):
if self._model.voting_end is None:
if self._model.voting_ends_at is None:
return False

return datetime.now() > self._model.voting_end
return datetime.now() > self._model.voting_ends_at
12 changes: 6 additions & 6 deletions src/ekklesia_portal/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def ballots_can_be_added(self):
return self.status == VotingStatus.PREPARING

@property
def registration_start(self):
def registration_starts_at(self):
if self.target is None:
return

Expand All @@ -397,7 +397,7 @@ def registration_start(self):
return self.target - timedelta(days=days)

@property
def registration_end(self):
def registration_ends_at(self):
"""Registration ends at `target - registration_end_days` or
at `target` if registration_end_days is not set"""
if self.target is None:
Expand All @@ -415,14 +415,14 @@ def registration_end(self):

@property
def voting_can_be_created(self):
return self.status == VotingStatus.PREPARING and self.voting_start is not None and self.voting_end is not None
return self.status == VotingStatus.PREPARING and self.voting_starts_at is not None and self.voting_ends_at is not None

@property
def voting_can_be_retrieved(self):
return self.status == VotingStatus.FINISHED and self.voting_start is not None and self.voting_end is not None
return self.status == VotingStatus.FINISHED and self.voting_starts_at is not None and self.voting_ends_at is not None

@property
def voting_start(self):
def voting_starts_at(self):
if self.target is None:
return

Expand All @@ -434,7 +434,7 @@ def voting_start(self):
return self.target - timedelta(days=days)

@property
def voting_end(self):
def voting_ends_at(self):
return self.target


Expand Down
16 changes: 8 additions & 8 deletions src/ekklesia_portal/lib/vvvote/election_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def voting_phase_to_vvvote_election_config(module_config, phase) -> vvvote_schem

phase_title = phase.title or phase.name or phase.phase_type.name
required_phase_attrs = [
"registration_start",
"registration_end",
"voting_start",
"voting_end",
"registration_starts_at",
"registration_ends_at",
"voting_starts_at",
"voting_ends_at",
]

missing_attrs = [attr for attr in required_phase_attrs if getattr(phase, attr) is None]
Expand All @@ -81,10 +81,10 @@ def voting_phase_to_vvvote_election_config(module_config, phase) -> vvvote_schem
verified=module_config["must_be_verified"],
nested_groups=[module_config["required_role"]],
serverId=module_config["auth_server_id"],
RegistrationStartDate=phase.registration_start,
RegistrationEndDate=phase.registration_end,
VotingStart=phase.voting_start,
VotingEnd=phase.voting_end,
RegistrationStartDate=phase.registration_starts_at,
RegistrationEndDate=phase.registration_ends_at,
VotingStart=phase.voting_starts_at,
VotingEnd=phase.voting_ends_at,
)
config = vvvote_schema.ElectionConfig(
electionId=str(uuid4()),
Expand Down

0 comments on commit 51ab8f9

Please sign in to comment.