Exemplo n.º 1
0
def addGroup():

  if 'email' not in session:
    return redirect(url_for('signin'))

  user = Smarketer.query.filter_by(username = session['email']).first()

  if user is None:
    return redirect(url_for('signin'))
  else:
    form = GroupForm()

    if request.method == 'POST':
      if form.validate() == False:
        return render_template('addGroup.html', form=form)
      else:
	totalTitle = form.groupTitle.data + " - " + form.groupID.data
        newGroup = Group(form.groupID.data, totalTitle)
        db.session.add(newGroup)
        db.session.commit()

	form.groupID.data = ""
	form.groupTitle.data = ""
        return render_template('addGroup.html', form=form, success=True)

    elif request.method == 'GET':
      return render_template('addGroup.html', form=form)
Exemplo n.º 2
0
def edit_group(grupo):
	# grupo = Grupo.objects.get_or_404(nombre=grupo)
	grupo = Grupo.objects.get_or_create(nombre=grupo,defaults={'horario': 'Sin definir'})
	grupo_id=grupo[0].id
	# if len(grupo[0].horario)<1:
	# 	grupo[0].horario = 'Sin definir'
	# user_json=usuario
	# uuu = [{'nombre':'nombre','username':'******'}]
	# post = Usuario.objects.get_or_404(username=username)
	form = GroupForm(request.form,grupo[0])
	if request.method == 'POST':
		if form.validate() == False:
			flash('Todos los campos son necesarios.')
			return render_template('usuarios/groups.html', form=form, data_type="Grupos", action="Editar")
		else:
			# flash('Valores por defecto.')
			g=Grupo.objects.get(id=grupo_id)
			g.update(set__nombre=form.nombre.data)
			g.update(set__horario=form.horario.data)
			# grupo[0].nombre=form.nombre.data
			# grupo[0].horario=form.horario.data
			# grupo[0].save()
			# return render_template('usuarios/groups.html', form=form, data_type="Grupos", action="Editar")
			grupos = Grupo.objects.all()
			return render_template ('usuarios/groups.html', grupos=grupos, action="Listar")
			# return render_template('grupos.html')
 
	elif request.method == 'GET':
		return render_template('usuarios/groups.html', form=form, data_type="Grupos", action="Editar")
Exemplo n.º 3
0
def addGroup():

    if 'email' not in session:
        return redirect(url_for('signin'))

    user = Smarketer.query.filter_by(username=session['email']).first()

    if user is None:
        return redirect(url_for('signin'))
    else:
        form = GroupForm()

        if request.method == 'POST':
            if form.validate() == False:
                return render_template('addGroup.html', form=form)
            else:
                totalTitle = form.groupTitle.data + " - " + form.groupID.data
                newGroup = Group(form.groupID.data, totalTitle)
                db.session.add(newGroup)
                db.session.commit()

                form.groupID.data = ""
                form.groupTitle.data = ""
                return render_template('addGroup.html',
                                       form=form,
                                       success=True)

        elif request.method == 'GET':
            return render_template('addGroup.html', form=form)
Exemplo n.º 4
0
def groups(group_id=None):
    form = GroupForm(request.form)
    if request.method == 'POST':
        if not form.validate():
            pass
        else:
            pass
    return render_template('groups.html', user=get_user(), form=form)
Exemplo n.º 5
0
def creategroup():
    form = GroupForm()
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('creategroup.html', form=form, session = session)
        else:
            newgroup = Group(form.groupname.data, session['email'],session['email'])
            db.session.add(newgroup)
            db.session.commit()
            user = User.query.filter_by(email = session['email']).first()
            if user.grouplist == None or user.grouplist == "":
                user.grouplist = form.groupname.data
            else:
                user.grouplist += "," + form.groupname.data
            db.session.commit()
            return redirect(url_for('index'))


    elif request.method == 'GET':
        return render_template('creategroup.html', form=form)