Пример #1
0
def AddEntry(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = EntryForm(request.POST)
            if form.is_valid():
                parent = request.user.get_profile()
                entry = Entry(patient=parent,
                              entry=form.cleaned_data['entry'],
                              desc=form.cleaned_data['desc'])
                entry.save()
                if form.cleaned_data['entry'].find('CODE') > -1:
                    return HttpResponseRedirect('/code/')
                else:
                    return HttpResponseRedirect('/profile/')
            else:
                print form.errors
                return render_to_response(
                    'entry.html', {'form': form},
                    context_instance=RequestContext(request))
        else:
            ''' user is not submitting the form '''
            form = EntryForm()
            context = {'form': form}
            return render_to_response('entry.html',
                                      context,
                                      context_instance=RequestContext(request))
    else:
        pass
Пример #2
0
Файл: views.py Проект: Barro/PMS
def participate(request, compo):
    party = get_party(request)
    try:
        try:
            compo = Competition.objects.get(slug=compo, party=party)
        except Competition.DoesNotExist:
            raise InvalidCompetition()

    except InvalidCompetition:
        messages.add_message(request, messages.ERROR, "Invalid competition")
        return HttpResponseRedirect(reverse("compo.views.index", args=[request.party]))

    is_admin = request.user.has_perm("compo.admin")
    if (
        compo.can_submit() and (not party.ticket_required or request.user.get_profile().hasPartyTicket(party))
    ) or is_admin:

        if request.method == "POST":
            form = EntryForm(request.POST, request.FILES, compo=compo)
            if form.is_valid():
                entry = form.save(commit=False)
                entry.submitter = request.user
                entry.compo = compo
                entry.save()
                entry_submitted.send_robust(
                    sender=compo, compo=compo, entry=entry, name=entry.name, credits=entry.credits
                )

                return HttpResponseRedirect(reverse("entry.views.upload_entry_version", args=[request.party, entry.id]))
        else:
            form = EntryForm(compo=compo)

        return render_to_response(
            "compo_participate.html", {"compo": compo, "form": form}, context_instance=RequestContext(request)
        )
    else:
        if party.ticket_required and not request.user.get_profile().hasPartyTicket(party):
            messages.add_message(request, messages.ERROR, "You need ticket to participate.")
        else:
            messages.add_message(request, messages.ERROR, "Participation is closed.")

    return HttpResponseRedirect(reverse("compo.views.index", args=[request.party]))
Пример #3
0
def home(request):
    if request.method == "POST":
        entry = EntryForm(request.POST)
        if entry.is_valid():
            entry.save()
            return HttpResponse("success")

    else:
        entry = EntryForm()
        return render(request, "index.html", {'form': entry})
Пример #4
0
def edit(request, id):
    entries = entry.objects.get(id=id)
    form = EntryForm(instance=entries)
    context = {'form': form}
    if request.method == 'POST':
        form = EntryForm(request.POST, instance=entries)
        if form.is_valid():
            form.save()
            return redirect("/show/")
    return render(request, "edit.html", context)
Пример #5
0
def AddEntry(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = EntryForm(request.POST)
            if form.is_valid():
                parent = request.user.get_profile()
                entry = Entry(patient=parent, entry=form.cleaned_data['entry'], desc=form.cleaned_data['desc'])
                entry.save()
                if form.cleaned_data['entry'].find('CODE')>-1:
                    return HttpResponseRedirect('/code/')
                else:
                    return HttpResponseRedirect('/profile/')
            else:
                print form.errors
                return render_to_response('entry.html', {'form':form}, context_instance=RequestContext(request))
        else:
            ''' user is not submitting the form '''
            form = EntryForm()
            context = {'form': form}
            return render_to_response('entry.html', context, context_instance=RequestContext(request))
    else:
        pass
Пример #6
0
def train(request):
	# Get the context from the request.
	context = RequestContext(request)
	# A HTTP POST?
	if request.method == 'POST':
		form = EntryForm(request.POST)
		# Have we been provided with a valid form?
		if form.is_valid():
			# Save the new category to the database.
			form.save(commit=True)
			# Now call the index() view.
			# The user will be shown the homepage.
			print form.errors
		else:
			# The supplied form contained errors - just print them to the terminal.
			print form.errors	
	else:
		# If the request was not a POST, display the form to enter details.
		form = EntryForm()

	# Bad form (or form details), no form supplied...
	# Render the form with error messages (if any).
	return render_to_response('entry/train.html', {'form': form, 'name' : request.user.username}, context)