Пример #1
0
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.forms.formsets import formset_factory
from ridings.models import Riding, Poll, Riding_Add_Form, Riding_Modify_Form, Poll_Add_Form, Poll_Modify_Form, ChooseRidingForm
from ballots.models import Ballot
from politicians.models import Politician
from keywords.models import RidingKeywordValue, RidingKeywordList, PoliticianKeywordValue, addRidingKeywordValueForm
from django.contrib.auth.decorators import user_passes_test
from election.models import define_view_permissions, permissions_or, permissions_and, permission_always
from django.contrib import messages

# TODO Add decorators limiting access

# Riding Information
@user_passes_test(permissions_or(define_view_permissions(['EO'],['BEF','DUR','AFT']), define_view_permissions(['REP'],['DUR'])))
def view_all_ridings(request):
    #""" View list of all the ridings. """
    # exlude deleted ridings from list
    ridings = Riding.objects.filter(delete=False)
    # render page
    return render(request, 'ridings/ridings.html',{
        'ridings': ridings,
        'type': str('ridings')
        })

@user_passes_test(permissions_or(define_view_permissions(['EO'],['BEF','DUR','AFT']), define_view_permissions(['REP'],['DUR'])))
def view_riding(request, r_id):
    #""" View all the details about a riding on one page. """
    # store all necessary information for a riding into variables to be added to the dictionary
    riding = Riding.objects.get(id=r_id)
Пример #2
0
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.db.models import Count
from ridings.models import Riding, Poll
from ballots.models import Ballot, BallotForm, ChoosePollForm, ChooseRidingToVerifyForm, AcceptBallotForm, LockedBallotForm
from politicians.models import Politician
from election.models import define_view_permissions, permissions_or, permissions_and, permission_always
from django.contrib.auth.decorators import user_passes_test
from django.db import IntegrityError
from django.contrib import messages

# Entering Ballots
@user_passes_test(define_view_permissions(['RO'],['DUR']))
def choose_poll(request):
    """ Enter the poll number to enter ballots for."""
    if request.method == 'POST':
        form = ChoosePollForm(request.POST)
        if form.is_valid():
            poll = form.cleaned_data['poll']
            return HttpResponseRedirect(reverse(input_ballot, args=(poll.id,)))
    else:
        form = ChoosePollForm()

    return render(request, 'ballots/choose_poll.html',
        {'form': form,
        })
    
@user_passes_test(define_view_permissions(['RO'],['DUR']))
def compare_ballot(request, b_id):
    ballot = Ballot.objects.get(id=b_id)
Пример #3
0
from django.shortcuts import redirect, render
from django.contrib.auth.models import User, Group
from django.contrib.auth.decorators import user_passes_test
from users.models import CreateUserForm, ModifyUserForm
from election.models import define_view_permissions, permission_always

# User Management
# TODO Add decorators limiting access


@user_passes_test(define_view_permissions(set(["ADMIN"]), set(["BEF", "DUR", "AFT"])))
def index(request):
    """ View summary information about all users. """
    users = User.objects.filter(is_staff=False, is_active=True).order_by("username")
    return render(request, "users/view_all_users.html", {"users": users})


@user_passes_test(define_view_permissions(set(["ADMIN"]), set(["BEF", "DUR", "AFT"])))
def view_user(request, user_id):
    """ View detailed information about one user. """
    return render(request, "users/view_user.html", {})


@user_passes_test(define_view_permissions(["ADMIN"], ["BEF", "DUR", "AFT"]))
def add_user(request):
    """ Create a new user. """
    if request.method == "POST":
        form = CreateUserForm(request.POST)
        if form.is_valid():
            new_user = User.objects.create_user(
                form.cleaned_data["username"], "*****@*****.**", form.cleaned_data["password1"]
Пример #4
0
#System
from politicians.models import Politician
from ridings.models import Riding
from keywords.models import RidingKeywordList, RidingKeywordValue, \
    addRidingKeywordListForm, editRidingKeywordListForm, addhRidingKeywordValueForm, editRidingKeywordValueForm, addaRidingKeywordValueForm
from keywords.models import PoliticianKeywordList, PoliticianKeywordValue, \
    addPoliticianKeywordListForm, editPoliticianKeywordListForm, addhPoliticianKeywordValueForm, editPoliticianKeywordValueForm, addaPoliticianKeywordValueForm
from election.models import define_view_permissions, permissions_or, permissions_and, permission_always
from politicians.views import view_politician


# TODO Add decorators limiting access

# Keyword Management

@user_passes_test(define_view_permissions(['EO'],['BEF']))
def index(request):
    riding_keyword_values = RidingKeywordValue.objects.all()
    politician_keyword_values = PoliticianKeywordValue.objects.all()
    riding_keywords = RidingKeywordList.objects.filter(delete=False)
    politician_keywords = PoliticianKeywordList.objects.filter(delete=False)
    return render(request, 'keywords/view.html',
        {'riding_keyword_values': riding_keyword_values,
         'politician_keyword_values': politician_keyword_values,
         'riding_keywords': riding_keywords,
         'politician_keywords': politician_keywords
         })

@user_passes_test(define_view_permissions(['EO'],['BEF']))
def new_riding_keyword(request):
    if request.method == 'POST':