Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Update position field of eventsignups.
Browse files Browse the repository at this point in the history
- Add documentation for position field.
- Add position field to post response.

Fixes #405 
Fixes #410
  • Loading branch information
temparus authored and lioneltrebuchon committed Dec 1, 2019
1 parent 23cbd43 commit 1476ecb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions amivapi/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
add_email_to_signup_collection,
add_position_to_signup,
add_position_to_signup_collection,
add_position_to_signup_on_inserted,
add_signup_count_to_event,
add_signup_count_to_event_collection
)
Expand Down Expand Up @@ -49,6 +50,7 @@ def init_app(app):
# Show user's position in the signup list
app.on_fetched_resource_eventsignups += add_position_to_signup_collection
app.on_fetched_item_eventsignups += add_position_to_signup
app.on_inserted_eventsignups += add_position_to_signup_on_inserted

# Show signup count in events
app.on_fetched_resource_events += add_signup_count_to_event_collection
Expand Down
6 changes: 6 additions & 0 deletions amivapi/events/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@
'type': 'boolean',
'admin_only': True
},
'position': {
'description': "Position of the signup within all signups of "
"the event.",
'readonly': True,
'type': 'integer',
}
}
}
}
5 changes: 5 additions & 0 deletions amivapi/events/projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def add_position_to_signup_collection(response):
add_position_to_signup(item)


def add_position_to_signup_on_inserted(items):
for item in items:
add_position_to_signup(item)


def add_signup_count_to_event(item):
"""After an event is fetched from the database we add the current signup
count"""
Expand Down
6 changes: 4 additions & 2 deletions amivapi/tests/events/test_projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def test_signup_count_projected(self):
self.assertEqual(event['signup_count'], 100)
self.assertEqual(event['unaccepted_count'], 1)

def test_waitinglist_position_projection(self):
"""Test that waiting list position is correctly inserted into a
def test_signuplist_position_projection(self):
"""Test that signup list position is correctly inserted into a
signup information"""
with freeze_time("2016-01-01 00:00:00") as frozen_time:
# Create a new event
Expand Down Expand Up @@ -93,6 +93,8 @@ def test_waitinglist_position_projection(self):
'event': str(event['_id']),
'user': str(late_user['_id'])
}, status_code=201).json
# Check that position is part of the received entity
self.assertEqual(signup['position'], 4)

# GET the late user's signup to check his position
signup_info = self.api.get(
Expand Down

0 comments on commit 1476ecb

Please sign in to comment.