예제 #1
0
    def post(self, request, *args, **kwargs):
        action = request.POST.get('action', None)

        if action == 'set-nickname':
            nickname = request.POST.get('nickname', None)
            nickname = self.NICKNAME_CLEANUP_REGEX.sub('', nickname)
            nickname = nickname[:16]
            old_nickname = get_nickname(request)
            anonymous_nickname_prefix = _('#anonymous-startswith')
            if old_nickname.startswith(str(anonymous_nickname_prefix)):
                Attendance.objects.filter(submitter=old_nickname).update(
                    submitter=nickname)
            request.session['nickname'] = nickname
            return HttpResponse('OK')

        if action == 'set-attendance':
            nickname = get_nickname(request)
            raid = get_object_or_404(Raid, pk=request.POST.get('raid', None))
            choice = request.POST.get('choice', '')
            if choice == 'cancel':
                try:
                    attendance = Attendance.objects.get(raid=raid,
                                                        submitter=nickname)
                    attendance.start_time_choice = None
                    attendance_updated(attendance, raid)
                    attendance.delete()
                except Attendance.DoesNotExist:
                    return HttpResponse('fail')
                return HttpResponse('OK')
            try:
                choice = int(choice)
            except ValueError:
                return HttpResponse('fail')
            start_time_choices = raid.get_start_time_choices()
            if choice < 0 or choice >= len(start_time_choices):
                return HttpResponse('fail')
            attendance, created = Attendance.objects.get_or_create(
                raid=raid,
                submitter=nickname,
                defaults={'start_time_choice': choice})
            if not created:
                attendance.start_time_choice = choice
                attendance.save()
            attendance_updated(attendance, raid)
            return HttpResponse('OK')
        return self.get(request, *args, **kwargs)
예제 #2
0
파일: views.py 프로젝트: lamperi/raidikalu
 def get_context_data(self, **kwargs):
   context = super(RaidListView, self).get_context_data(**kwargs)
   context['editable_settings'] = EditableSettings.get_current_settings()
   context['raids'] = self.get_queryset()
   context['request_nickname'] = get_nickname(self.request)
   context['now'] = timezone.now()
   for raid in context['raids']:
     self.update_raid_context(raid)
   return context
예제 #3
0
 def get_context_data(self, **kwargs):
     context = super(RaidListView, self).get_context_data(**kwargs)
     context['infobox_content'] = InfoBox.get_infobox_content()
     context['raid_types'] = RaidType.objects.filter(is_active=True)
     context['raids'] = self.get_queryset()
     context['request_nickname'] = get_nickname(self.request)
     context['now'] = timezone.now()
     for raid in context['raids']:
         self.update_raid_context(raid)
     return context
예제 #4
0
파일: views.py 프로젝트: lamperi/raidikalu
 def update_raid_context(self, raid):
   nickname = get_nickname(self.request)
   setattr(raid, 'own_start_time_choice', None)
   start_times_with_attendances = []
   raid_attendances = raid.attendances.all()
   for choice_index, start_time_choice in enumerate(raid.get_start_time_choices()):
     attendances_at_time = []
     for attendance in raid_attendances:
       if attendance.start_time_choice == choice_index:
         attendances_at_time.append(attendance)
         if attendance.submitter == nickname:
           setattr(raid, 'own_start_time_choice', choice_index)
     start_times_with_attendances.append({
       'time': start_time_choice,
       'attendances': attendances_at_time,
     })
   setattr(raid, 'start_times_with_attendances', start_times_with_attendances)
   setattr(raid, 'attendance_count', len(raid_attendances))