Exemplo n.º 1
0
def registered_voters(request):
    context = {}
    if is_admin(request):
        meeting = get_active_meeting()
        if meeting:
            context['registered_voters'] = meeting.get_attendee_list()
        return render(request, "genfors/registered_voters.html", context)
    else:
        messages.error(request, 'Du har ikke tilgang til dette')
        return redirect('genfors_admin')
Exemplo n.º 2
0
def admin(request):
    context = {}
    # Check if user is logged in as genfors admin
    if is_admin(request):
        meeting = get_next_meeting()
        if meeting:
            aq = meeting.get_active_question()
            a = anonymous_voter(request.COOKIES.get('anon_voter'),
                                request.user.username)
            r = RegisteredVoter.objects.filter(user=request.user,
                                               meeting=meeting).first()
            if aq:
                context['not_voted'] = None
                v = a if aq.anonymous else r
                context['already_voted'] = aq.already_voted(v)
                not_voted = []
                for person in meeting.get_can_vote():
                    if not aq.already_voted(person):
                        not_voted.append(person)
                context['not_voted'] = not_voted

            context['meeting'] = meeting
            context['question'] = aq
            context['questions'] = meeting.get_locked_questions()
            context['pin_code'] = meeting.get_pin_code()
        elif request.method == 'POST':
            form = MeetingForm(request.POST)
            context['form'] = form
            if form.is_valid():
                meeting = Meeting(title=form.cleaned_data['title'],
                                  start_date=form.cleaned_data['start_date'])
                meeting.save()
                meeting.generate_pin_code()
                messages.success(request, _('Generalforsamling lagt til'))
                return redirect('genfors_admin')
        else:
            # Create meeting view
            form = MeetingForm()
            context['form'] = form
        context['meetings'] = Meeting.objects.filter(ended=True).order_by(
            '-start_date', '-id')
        return render(request, "genfors/admin.html", context)
    else:
        if request.method == 'POST':
            form = LoginForm(request.POST)
            context['form'] = form
            if form.is_valid():
                request.session['genfors_admin'] = True
                return redirect('genfors_admin')
        else:
            context['form'] = LoginForm()
    return render(request, "genfors/admin_login.html", context)
Exemplo n.º 3
0
def question_validate(request, question_id):
    """
    Returns a HttpResponse if not passing validation
    """
    if is_admin(request):
        try:
            Question.objects.get(id=question_id)
        except Question.DoesNotExist:
            messages.error(request, 'Spørsmålet finnes ikke')
            return redirect('genfors_admin')
        # Return None when passing
        return None
    else:
        messages.error(request, 'Du har ikke tilgang til dette')
    return redirect('genfors_admin')
Exemplo n.º 4
0
def genfors_lock_registration(request):
    if is_admin(request):
        meeting = get_active_meeting()
        if meeting:
            if request.method == 'POST':
                meeting.registration_locked = True
                meeting.save()
            else:
                question = 'Er du sikker på at du vil stenge registrering for nye brukere?'
                return render(request, 'genfors/confirm.html',
                              {'question': question})
        else:
            messages.error(request, 'Ingen aktiv generalforsamling')
    else:
        messages.error(request, 'Du har ikke tilgang til dette')
    return redirect('genfors_admin')
Exemplo n.º 5
0
def genfors_end(request):
    if is_admin(request):
        meeting = get_next_meeting()
        if meeting:
            if request.method == 'POST':
                meeting.ended = True
                meeting.save()
                messages.success(request, 'Generalforsamlingen ble avsluttet')
            else:
                question = 'Er du sikker på at du vil avslutte generalforsamlingen?'
                return render(request, 'genfors/confirm.html',
                              {'question': question})
        else:
            messages.error(request, 'Ingen aktiv generalforsamling')
    else:
        messages.error(request, 'Du har ikke tilgang til dette')
    return redirect('genfors_admin')
Exemplo n.º 6
0
def user_can_vote(request):
    if is_admin(request):
        json_response = {'success': False}
        m = get_active_meeting()
        if m:
            user_id = request.POST.get('user-id')
            try:
                user_id = int(user_id)
                user = RegisteredVoter.objects.get(meeting=m, id=user_id)
                # Changing can_vote
                user.can_vote = not user.can_vote
                user.save()
                json_response['can_vote'] = user.can_vote
                json_response['success'] = True
            except ValueError:
                json_response['error'] = 'Brukerid ikke gyldig'
            except RegisteredVoter.DoesNotExist:
                json_response['error'] = 'Bruker ikke funnet'
        else:
            json_response['error'] = 'Det er ingen aktiv generalforsamling'
        return HttpResponse(json.dumps(json_response))
    return HttpResponse(status_code=403, reason_phrase='Forbidden')
Exemplo n.º 7
0
def question_admin(request, question_id=None):
    context = {}
    meeting = get_active_meeting()
    if is_admin(request):
        if not meeting:
            return _handle_inactive_meeting(request)

        if question_id is None and meeting.get_active_question():
            messages.error(
                request,
                _('Kan ikke legge til et nytt spørsmål når det allerede er et aktivt et'
                  ))
            return redirect('genfors_admin')

        if request.method == 'POST':
            return handle_question_admin_update(request, context, question_id)
        else:
            return handle_question_admin_detail(request, context, question_id)

    else:
        messages.error(request, 'Du har ikke tilgang til dette')
    return redirect('genfors_admin')
Exemplo n.º 8
0
def genfors_open_registration(request):
    if is_admin(request):
        meeting = get_active_meeting()
        if meeting:
            if request.method == 'POST':
                meeting.registration_locked = False
                meeting.save()
                meeting.generate_pin_code()
            else:
                question = 'Er du sikker på at du vil åpne registrering for nye brukere?'
                description = """
Vær oppmerksom på at når man åpner registrering vil pinkoden for registrering av oppmøte forandre seg.
Du vil se den oppdaterte koden i administrasjonspanelet.
"""

                return render(request, 'genfors/confirm.html', {
                    'question': question,
                    'description': description
                })
        else:
            messages.error(request, 'Ingen aktiv generalforsamling')
    else:
        messages.error(request, 'Du har ikke tilgang til dette')
    return redirect('genfors_admin')
Exemplo n.º 9
0
def admin_logout(request):
    if is_admin(request):
        del request.session['genfors_admin']
    return redirect('genfors_index')