예제 #1
0
def addassignment(request, aid=None):
    d = {}
    d["url"] = "/assignments/add"
    d["sub"] = "Add"
    if aid:
        a = Assignment.objects.filter(aid=aid).first()
        if not a:
            return HttpResponseRedirect("/assignments")
    else:
        a = None
    if request.method == "POST":
        form = AssignmentForm(request.POST, request.FILES, instance=a)
        if form.is_valid():
            a = form.save(commit=False)
            a.user = request.user
            a.sample_copy = form.cleaned_data["sample_copy"]
            a.save()
            return HttpResponseRedirect("/assignments")
        else:
            d["form"] = form
            d["text"] = form.errors
            print form.errors
            return render(request, "register.html", d)
    else:
        d["form"] = AssignmentForm(instance=a)
        return render(request, "register.html", d)
예제 #2
0
파일: views.py 프로젝트: aswinm/assigneval
def addassignment(request, aid=None):
    d = {}
    d["url"] = "/assignments/add"
    d["sub"] = "Add"
    if aid:
        a = Assignment.objects.filter(aid=aid).first()
        if not a:
            return HttpResponseRedirect("/assignments")
    else:
        a = None
    if request.method == "POST":
        form = AssignmentForm(request.POST, request.FILES, instance=a)
        if form.is_valid():
            a = form.save(commit=False)
            a.user = request.user
            a.sample_copy = form.cleaned_data["sample_copy"]
            a.save()
            return HttpResponseRedirect("/assignments")
        else:
            d["form"] = form
            d["text"] = form.errors
            print form.errors
            return render(request, "register.html", d)
    else:
        d["form"] = AssignmentForm(instance=a)
        return render(request, "register.html", d)
예제 #3
0
def edit(request, assignment_id=None):
    """
    View zum editieren und neuanlegen von Wahlen
    """
    if assignment_id is not None:
        assignment = Assignment.objects.get(id=assignment_id)
    else:
        assignment = None

    if request.method == 'POST':
        form = AssignmentForm(request.POST, instance=assignment)
        if form.is_valid():
            assignment = form.save()
            if assignment_id is None:
                messages.success(request, _('New election was successfully created.'))
            else:
                messages.success(request, _('Election was successfully modified.'))
            if not 'apply' in request.POST:
                return redirect(reverse("assignment_overview"))
            if assignment_id is None:
                return redirect(reverse('assignment_edit', args=[assignment.id]))
    else:
        form = AssignmentForm(instance=assignment)
    return {
        'form': form,
        'assignment': assignment,
    }
예제 #4
0
def create_assignment(request):
    if request.method == 'POST':
        form = AssignmentForm(request.POST or None)
        if form.is_valid():
            form.save()
            return redirect('assignment:assignment-detail', form.instance.id)
    else:
        form = AssignmentForm()
    context = {'form': form}
    return render(request, 'assignment/create-assignment.html', context)
예제 #5
0
def assignment(request):
    if request.method == "POST":
        form = AssignmentForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                form.save()
                return redirect('../../assignment/showa')
            except:
                pass
    faculty = Faculty.objects.all()
    return render(request, "assignment.html", {'faculty': faculty})
def assignmentCreate(request):
    if request.method == 'POST':
        form = AssignmentForm(request.POST)
        if form.is_valid():
            assignment = form.save(commit=False)
            assignment.user = request.user
            assignment.save()
            return redirect(reverse('assignment:my_assignment_page'))
    else:
        form = AssignmentForm
    return render(request, 'assignment/assignment_form.html', {'form': form})
예제 #7
0
def updatea(request, id):
    assignment = Assignment.objects.get(id=id)
    form = AssignmentForm(request.POST, request.FILES, instance=assignment)
    if form.is_valid():
        form.save()
        return redirect('../showa')
    else:
        print(form.errors)
    x = {'assignment': assignment}
    y = {'form': form}
    z = {**x, **y}

    return render(request, "edita.html", z)
예제 #8
0
def signup(request, game_id):
    if request.method == "POST":    
        form = AssignmentForm(request.POST)
        if form.is_valid():
            if request.user.is_authenticated():
                position = form.cleaned_data['position']
                username = request.user.get_username()
                a = Assignment.objects.get(pk=game_id)
                if (a.AR_1 != username) and (a.AR_2 != username) and (a.center != username):
                    if position == u'1':
                        a.center = username
                    elif position == u'2':
                        if a.AR_1:
                            a.AR_2 = username
                        else:
                            a.AR_1 = username
                    a.save()    
                    return HttpResponseRedirect('assigment/%s/results' % game_id)
                else:
                    return HttpResponse("You were not able to sign up for this game")
            else:
                return HttpResponseRedirect('/assignment/')
        else:
            form = AssignmentForm() # An unbound form