Skip to content

Commit

Permalink
Use rsvp_state in project settings and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Nov 20, 2023
1 parent 7f3a2d6 commit 360b9c9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
6 changes: 4 additions & 2 deletions funnel/forms/sync_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from baseframe import __, forms

from ..models import (
RSVP_STATE,
PROJECT_RSVP_STATE,
Account,
AccountEmail,
Project,
Expand Down Expand Up @@ -70,7 +70,9 @@ class ProjectBoxofficeForm(forms.Form):
filters=[forms.filters.strip()],
)
rsvp_state = forms.RadioField(
__("Registrations"), choices=RSVP_STATE.items(), default=RSVP_STATE.NONE
__("Registrations"),
choices=PROJECT_RSVP_STATE.items(),
default=PROJECT_RSVP_STATE.NONE,
)
is_subscription = forms.BooleanField(
__("Paid tickets are for a subscription"),
Expand Down
10 changes: 5 additions & 5 deletions funnel/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
visual_field_delimiter,
)

__all__ = ['RSVP_STATE', 'Project', 'ProjectLocation', 'ProjectRedirect']
__all__ = ['PROJECT_RSVP_STATE', 'Project', 'ProjectLocation', 'ProjectRedirect']


# --- Constants ---------------------------------------------------------------
Expand All @@ -67,7 +67,7 @@ class CFP_STATE(LabeledEnum): # noqa: N801
ANY = {NONE, PUBLIC, CLOSED}


class RSVP_STATE(LabeledEnum): # noqa: N801
class PROJECT_RSVP_STATE(LabeledEnum): # noqa: N801
NONE = (1, __("Not accepting registrations"))
ALL = (2, __("Anyone can register"))
MEMBERS = (3, __("Only members can register"))
Expand Down Expand Up @@ -171,8 +171,8 @@ class Project(UuidMixin, BaseScopedNameMixin, Model):
rsvp_state: Mapped[int] = with_roles(
sa.orm.mapped_column(
sa.SmallInteger,
StateManager.check_constraint('rsvp_state', RSVP_STATE),
default=RSVP_STATE.NONE,
StateManager.check_constraint('rsvp_state', PROJECT_RSVP_STATE),
default=PROJECT_RSVP_STATE.NONE,
nullable=False,
),
read={'all'},
Expand Down Expand Up @@ -737,7 +737,7 @@ def end_at_localized(self):
@hybrid_property
def allow_rsvp(self) -> bool:
"""RSVP state as a boolean value (allowed for all or not)."""
return self.rsvp_state == RSVP_STATE.ALL
return self.rsvp_state == PROJECT_RSVP_STATE.ALL

def update_schedule_timestamps(self) -> None:
"""Update cached timestamps from sessions."""
Expand Down
9 changes: 8 additions & 1 deletion funnel/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ProjectTransitionForm,
)
from ..models import (
PROJECT_RSVP_STATE,
RSVP_STATUS,
Account,
Project,
Expand Down Expand Up @@ -171,7 +172,13 @@ def get_registration_text(
def feature_project_rsvp(obj: Project) -> bool:
return bool(
obj.state.PUBLISHED
and obj.allow_rsvp is True
and (
obj.rsvp_state == PROJECT_RSVP_STATE.ALL
or (
obj.rsvp_state == PROJECT_RSVP_STATE.MEMBERS
and 'member' in obj.current_roles
)
)
and (obj.start_at is None or not obj.state.PAST)
)

Expand Down
1 change: 1 addition & 0 deletions tests/e2e/account/register_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
def published_project(db_session, new_project: models.Project) -> models.Project:
"""Published project fixture."""
new_project.publish()
new_project.rsvp_state = models.PROJECT_RSVP_STATE.ALL
db_session.commit()
return new_project

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/views/rsvp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_valid_registration_form_schema(
{
'org': '',
'item_collection_id': '',
'allow_rsvp': True,
'rsvp_state': models.PROJECT_RSVP_STATE.ALL,
'is_subscription': False,
'register_button_txt': 'Follow',
'register_form_schema': app.json.dumps(valid_schema),
Expand Down

0 comments on commit 360b9c9

Please sign in to comment.