diff --git a/studygroups/models/device_allocation.py b/studygroups/models/device_allocation.py index ed7c88c1..b1163848 100644 --- a/studygroups/models/device_allocation.py +++ b/studygroups/models/device_allocation.py @@ -45,7 +45,7 @@ def check_user_device_allocation(user, date): # Find any learning circles in the device allocation time period study_groups = StudyGroup.objects.active().filter( - facilitator__user=user, + created_by=user, start_date__gte=device_allocation.start_date, start_date__lt=device_allocation.cutoff_date, ) diff --git a/studygroups/views/api.py b/studygroups/views/api.py index bba5ab43..7f0466ef 100644 --- a/studygroups/views/api.py +++ b/studygroups/views/api.py @@ -517,16 +517,22 @@ def get(self, request): courses = Course.objects.active().filter(archived=False) - # include_unlisted must be != false and the query must be scoped - # by user to avoid filtering out unlisted courses - if request.GET.get('include_unlisted', "false") == "false" or 'user' not in request.GET: - # return only courses that is not unlisted - # if the user is part of a team, include unlisted courses from the team + # unlisted courses are only included + if request.GET.get('include_unlisted') == True and 'user' in request.GET: + # if specifically requested and scoped by user - users can see their own unlisted courses + pass + elif 'course_id' in request.GET: + # if selected by id + # TODO maybe we want to check for more that just course_id in request to show unlisted courses? + pass + else: if request.user.is_authenticated: + # if the user is part of a team, include unlisted courses from the team team_query = TeamMembership.objects.active().filter(user=request.user).values('team') team_ids = TeamMembership.objects.active().filter(team__in=team_query).values('user') courses = courses.filter(Q(unlisted=False) | Q(unlisted=True, created_by__in=team_ids)) else: + # otherwise return only listed courses courses = courses.filter(unlisted=False) # TODO this doesn't exclude drafts @@ -868,7 +874,8 @@ def post(self, request, *args, **kwargs): # if part of digital detroit project if study_group.show_device_agreement(): - devices = check_user_device_allocation(request.user, study_group.start_date) + # TODO use creator as user + devices = check_user_device_allocation(study_group.created_by, study_group.start_date) max_limit = study_group.signup_limit + devices signup_limit = data.get('signup_limit', None) if signup_limit is None or signup_limit > max_limit: diff --git a/studygroups/views/facilitate.py b/studygroups/views/facilitate.py index c0b932bd..b0b2d9dd 100644 --- a/studygroups/views/facilitate.py +++ b/studygroups/views/facilitate.py @@ -351,7 +351,7 @@ def get_context_data(self, **kwargs): context['reminders_edited'] = True messages.warning(self.request, _('You have edited meeting reminders for meetings in the future. Update the learning circle description or venue information will cause the reminders to be regenerated and your updates to be lost')) if self.object.team and self.object.team.page_slug == 'digital-detroit': - context['max_signups'] = self.object.signup_limit + check_user_device_allocation(self.request.user, datetime.datetime.today()) + context['max_signups'] = self.object.signup_limit + check_user_device_allocation(self.object.created_by, datetime.datetime.today()) return context