Simplify participant API

This commit is contained in:
Oleg Lavrovsky 2024-03-16 12:13:04 +01:00
parent 7e1a77bbb9
commit a57a225e63
No known key found for this signature in database
GPG Key ID: 31E523030632FF4B
6 changed files with 30 additions and 13 deletions

View File

@ -228,7 +228,7 @@ def ProjectsByProgress(progress=None, event=None):
def GetEventUsers(event):
"""Fetch all users that have a project in this event."""
"""Fetch all active users that have a project in this event."""
if not event.projects:
return None
users = []
@ -240,7 +240,7 @@ def GetEventUsers(event):
Activity.project_id.in_(projects)
)).all()
for a in activities:
if a.user and a.user_id not in userlist:
if a.user and a.user.active and a.user_id not in userlist:
userlist.append(a.user_id)
users.append(a.user)
return sorted(users, key=lambda x: x.username)

View File

@ -277,7 +277,9 @@ def project_info_json(project_id):
def event_participants_csv(event_id):
"""Download a CSV of event participants."""
event = Event.query.filter_by(id=event_id).first_or_404()
userlist = [u.data for u in GetEventUsers(event)]
userlist = []
for u in GetEventUsers(event):
u['teams'] = u.joined_projects(True, -1, event):
headers = {
'Content-Disposition': 'attachment; '
+ 'filename=user_list_%d.csv' % event.id

View File

@ -1068,6 +1068,7 @@ nav .nav-login {
.timeline-finish .timeline-card::after,
.timeline-progress .timeline-card::after { display: initial; }
.timeline-card .close { margin: 0.4em; color: black; }
.timeline-card.timeline-content { overflow: hidden; }
/* Other project timeline customizations */
.project-page .timeline-review .timeline-content { background: #f2fef2; border-top: none; }
.project-page .timeline-pencil .timeline-content { background: #ffc; border-top: none; }

View File

@ -118,9 +118,6 @@ class User(UserMixin, PkModel):
'id': self.id,
'name': self.name,
'email': self.email,
'sso_id': self.sso_id,
'active': self.active,
'is_admin': self.is_admin,
'username': self.username,
'fullname': self.fullname,
'webpage_url': self.webpage_url,
@ -176,7 +173,7 @@ class User(UserMixin, PkModel):
self.carddata = gravatar_url
self.save()
def joined_projects(self, with_challenges=True, limit=-1):
def joined_projects(self, with_challenges=True, limit=-1, event=None):
"""Retrieve all projects user has joined."""
activities = Activity.query.filter_by(
user_id=self.id, name='star'
@ -189,12 +186,13 @@ class User(UserMixin, PkModel):
project_ids = []
for a in activities:
if limit > 0 and len(projects) >= limit: break
if a.project_id not in project_ids and not a.project.is_hidden:
a_prog = a.project.progress
not_challenge = a_prog is not None and a_prog > 0
if with_challenges or not_challenge:
projects.append(a.project)
project_ids.append(a.project_id)
if a.project_id in project_ids or a.project.is_hidden:
continue
if event is not None and a.project.event != event:
continue
if with_challenges or not project.is_challenge:
projects.append(a.project)
project_ids.append(a.project_id)
return projects

View File

@ -3,6 +3,9 @@
VER=`git describe --tags --abbrev=0`
echo Getting latest tags
git pull upstream --tags
echo Pushing to $VER ...
docker login
docker build -t loleg/dribdat:$VER .

View File

@ -49,6 +49,19 @@ class TestApi:
res = testapp.get('/api/events.csv')
assert '"test"' in res
# Test participants
user1 = UserFactory()
user2 = UserFactory()
project = ProjectFactory()
project.user = user1
project.event = event
ProjectActivity(project, 'star', user1)
ProjectActivity(project, 'star', user2)
res = testapp.get('/api/event/%d/participants.csv' % event.id)
assert project in user1.joined_projects()
assert project not in user1.joined_projects(False) # no challenges
assert user1.username in res
assert user2.username in res
def test_get_platform_data(self):
"""More global data types."""