Ejemplo n.º 1
0
 def get(self, request):
     context = Context.from_request(request)
     try:
         return TemplateResponse(
             request, 'first.html', {
                 'filters': {
                     'group': request.GET.get('group', None),
                 },
                 'users': {u.pk: u.json
                           for u in User.get_all(context)},
                 'challenges':
                 [c.json for c in Challenge.get_enabled(context)],
             })
     except Error as e:
         messages.error(request, e.message)
         return redirect('hub')
Ejemplo n.º 2
0
 def get(self, request):
     if request.user.is_authenticated:
         if Account.objects.filter(provider='ustc',
                                   user=request.user).exists():
             try:
                 request.user.ustceligible
             except UstcEligible.DoesNotExist:
                 return redirect('ustcprofile')
     context = Context.from_request(request)
     try:
         challenges = Challenge.get_enabled(context)
         challenges = {'value': [obj.json for obj in challenges]}
     except ProfileRequired as e:
         messages.info(request, e.message)
         return redirect('profile')
     except TermsRequired as e:
         messages.info(request, e.message)
         return redirect('terms')
     except Error as e:
         challenges = {'error': e.json}
     try:
         announcement = Announcement.get_latest(context).json
     except NotFound:
         announcement = None
     if request.user.is_authenticated:
         user = User.get(context, request.user.pk)
         if user.group == 'other':
             ranking = Submission.get_user_ranking(context, request.user.pk)
         else:
             ranking = Submission.get_user_ranking(context,
                                                   request.user.pk,
                                                   group=user.group)
     else:
         ranking = {}
     return TemplateResponse(
         request, 'hub.html', {
             'announcement': announcement,
             'challenges': challenges,
             'progress': Submission.get_user_progress(
                 context, request.user.pk),
             'ranking': ranking,
             'clear_count': Submission.get_clear_count(context),
         })