Example #1
0
def agenda_add_view(request):
    allowed_methods = ['GET', 'POST']
    template_name = 'agendas/agenda_add.html'

    if not request.user.is_superuser:
        return HttpResponseRedirect('/agenda/')

    if request.method == 'POST':
        form = AddAgendaForm(request.POST)
        if form.is_valid():
            agenda = Agenda()
            agenda.name = form.cleaned_data['name']
            agenda.public_owner_name = form.cleaned_data['public_owner_name']
            agenda.description = form.cleaned_data['description']
            agenda.save()
            agenda.editors.add(request.user)
            return HttpResponseRedirect(
                agenda.get_absolute_url())  # Redirect after POST
    else:
        initial_data = {'public_owner_name': request.user.username}
        form = AddAgendaForm(
            initial=initial_data)  # An unbound form with initial data

    return render_to_response(template_name, {'form': form},
                              context_instance=RequestContext(request))
def agregar_registro(request):
	nom = request.GET.get('nom','')
	ape = request.GET.get('ape','')
	pais = request.GET.get('pais','')
	correo = request.GET.get('correo','')
	if nom:
		if ape:
			if pais:
				if correo:
					p=Agenda(nombre=nom,apellido=ape,pais=pais,correo=correo)
					p.save()
					return render_to_response('agregar.html',{"exito":True})							
	else:
		return render_to_response('agregar.html')
Example #3
0
def makeCandidate(username, details, postname, photo, approved=False):
	# if GlobalVariables.objects.filter(varname='electionState') != 'pre-election':
	# 	return False
	if len(Users.objects.filter(username=username)) == 0:
		 return False
	else:
		assert(len(Users.objects.filter(username=username)) == 1)
		#assert(approved == False)
		assert(len(details) != 0)
		voteInfo = "{'totVotes':0, 'courseWise': {'btech': 0, 'mtech': 0, 'phd': 0, 'other': 0, 'prof': 0}, 'genderWise': {'m': 0, 'f':0}, 'departmentWise': {'cs':0, 'ee':0, 'bt':0, 'cl':0, 'ce':0, 'me':0, 'dd':0, 'ma':0, 'ph':0}, 'hostelWise': {'kameng':0, 'barak':0, 'umiam':0, 'manas':0, 'dihing':0, 'bramhaputra':0, 'lohith':0, 'kapili':0, 'siang':0, 'dibang':0, 'dhansiri':0, 'subhansiri':0, 'married-scholars':0}}"
		p1 = Candidates(username=username, details=details, postname=postname, photo=photo, approved=approved, voteInfo=voteInfo)
		p1.save()
		a1 = Agenda(candidate=Users.objects.filter(username=username)[0], content='.')
		a1.save()
		return True
Example #4
0
def agendas(user_id=None, id=None):
    if request.method == 'GET':
        if id is not None and user_id is not None:
            agenda = Agenda.query.filter_by(user_id=user_id, id=id).first()
            if agenda:
                return jsonify(agenda.serialize()), 200
            else:
                return jsonify({"agenda": "Not found"}), 404
        elif id is not None:
            agenda = Agenda.query.get(id)
            if agenda:
                return jsonify(agenda.serialize()), 200
            else:
                return jsonify({"agenda": "Not found"}), 404
        elif user_id is not None:
            agendas = Agenda.query.filter_by(user_id=user_id).all()
            agendas = list(map(lambda agenda: agenda.serialize(), agendas))
            return jsonify(agendas), 200
        else:
            agendas = Agenda.query.all()
            agendas = list(map(lambda agenda: agenda.serialize(), agendas))
            return jsonify(agendas), 200

    if request.method == 'POST':
        title = request.json.get('title')
        user_id = request.json.get('user_id')
        if not title:
            return jsonify({"msg": "Título es obligatorio"}), 422
        if not user_id:
            return jsonify({"msg": "user_id es obligatorio"}), 422

        agenda = Agenda()
        agenda.title = title
        agenda.user_id = user_id

        db.session.add(agenda)
        db.session.commit()

        return jsonify(agenda.serialize()), 201

    if request.method == 'PUT':

        agenda = Agenda.query.get(id)
        agenda.title = request.json.get('title')
        agenda.user_id = request.json.get('user_id')

        db.session.commit()

        return jsonify(agenda.serialize()), 200

    if request.method == 'DELETE':

        agenda = Agenda.query.get(id)
        db.session.delete(agenda)
        db.session.commit()

        return jsonify({'agenda': 'Deleted'}), 200
Example #5
0
def agenda_add_view(request):
    allowed_methods = ['GET', 'POST']
    template_name = 'agendas/agenda_add.html'

    if not request.user.is_superuser:
        return HttpResponseRedirect('/agenda/')

    if request.method == 'POST':
        form = AddAgendaForm(request.POST)
        if form.is_valid():
            agenda = Agenda()
            agenda.name = form.cleaned_data['name']
            agenda.public_owner_name = form.cleaned_data['public_owner_name']
            agenda.description = form.cleaned_data['description']
            agenda.save()
            agenda.editors.add(request.user)
            return HttpResponseRedirect(agenda.get_absolute_url()) # Redirect after POST
    else:
        initial_data = {'public_owner_name': request.user.username}
        form = AddAgendaForm(initial=initial_data) # An unbound form with initial data

    return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))
Example #6
0
def agenda_add_view(request):
    allowed_methods = ["GET", "POST"]
    template_name = "agendas/agenda_add.html"

    if not request.user.is_superuser:
        return HttpResponseRedirect("/agenda/")

    if request.method == "POST":
        form = AddAgendaForm(request.POST)
        if form.is_valid():
            agenda = Agenda()
            agenda.name = form.cleaned_data["name"]
            agenda.public_owner_name = form.cleaned_data["public_owner_name"]
            agenda.description = form.cleaned_data["description"]
            agenda.save()
            agenda.editors.add(request.user)
            return HttpResponseRedirect(agenda.get_absolute_url())  # Redirect after POST
    else:
        initial_data = {"public_owner_name": request.user.username}
        form = AddAgendaForm(initial=initial_data)  # An unbound form with initial data

    return render_to_response(template_name, {"form": form}, context_instance=RequestContext(request))