def requestor(): cform = CreateForm() if cform.validate_on_submit(): print(current_user.first_name) review = Review(title=cform.title.data, description=cform.description.data, biling=cform.biling.data, status=1, requestor=current_user.id, requestor_name=User.get_name(current_user.id), date=datetime.datetime.now(), pic=current_user.profile_pic) db.session.add(review) db.session.commit() tags = cform.tags.data print(tags) tag_list = tags.split(',') print('4444444444444444') print(tag_list) Review.setTags(tag_list, review.id) print('333333333333333333') return redirect(url_for("app.requestor")) else: print('bad') return render_template('requestor.html', cform=cform, user=current_user)
def create(): """ Page to create a new project account """ form = CreateForm(request.form) if form.validate_on_submit(): # On submit, grab form information project_name = form.project_name.data email = form.email.data password = form.password.data hashed_password = generate_password_hash(password) description = form.description.data # Create the account db = DB() resp = db.create(project_name, password, hashed_password, description=description, email=email) if resp['status']: flash('Project successfully created!') return redirect( url_for('admin_home', admin_id=g.admin['project_id'])) else: flash(resp['message']) return render_template('create.html', form=form)
def create(): form = CreateForm() all_users = User.query.order_by(db.func.lower(User.username)) form.usernames.choices = [(u.username, u.username) for u in all_users] if form.validate_on_submit(): users = [ User.query.filter_by(username=username).first() for username in form.usernames.data ] pool = Pool() pool.new_from_cube() auction = Auction(starting_balance=form.starting_balance.data, time_limit=form.time_limit.data, default_lot=form.default_lot.data, pool=pool, users=users, creator=current_user) if form.first_nom.data: auction.add_lot(card=form.first_nom.data) else: auction.add_lot(size=form.default_lot.data) db.session.add(auction) db.session.flush() for user in users: new_balance = Balance(holder=user, auction=auction, amount=form.starting_balance.data) db.session.add(new_balance) db.session.commit() return redirect(url_for("auction", auction_id=auction.id)) return render_template("create.html", title="New Draft", form=form, cube_cards=cube_cards)
def create_subject(): form = CreateForm() if form.validate_on_submit(): login = form.login.data identity_id = form.identity_id.data from sqlalchemy import or_ exists = Identity.query.filter( or_(Identity.identity_id == identity_id, Identity.login == login)).first() if exists: flash(u'Subjekt s danými údajmi už existuje.') return redirect(url_for('create_subject')) identity = Identity(login=login, identity_id=identity_id, organization=form.organization.data) # identity.set_password('PopradTa3') for r_id in form.roles.data: identity.roles.append(Role.query.get(r_id)) db.session.add(identity) db.session.commit() flash(u'Nový subjekt bol úspešne vytvorený.') return redirect(url_for('login')) return render_template('create_subject.html', form=form)
def create(): # 新建 if current_user.is_authenticated: form = CreateForm() if form.validate_on_submit(): post = Post(title=form.title.data, body=form.body.data) db.session.add(post) db.session.commit() flash('创建成功!') return redirect(url_for('index')) return render_template('create.html', title='新建', form=form)
def create(): form = CreateForm() data = form.data if form.validate_on_submit(): del data['csrf_token'] data['date_of_birth'] = str(data['date_of_birth']) redis.create_men([{key: value or '' for key, value in data.items()}]) return redirect( url_for('.index', message='Пользователь успешно добавлен')) else: flash('Введены некорректные данные') return render_template('create_form.html', form=form)
def create(): form = CreateForm() if form.validate_on_submit(): db.session.add( Post(body=form.body.data, title=form.title.data, author=current_user)) db.session.commit() flash('Congratulations, you create new post!', 'success') return redirect(url_for('posts')) return render_template('create.html', form=form)
def creator(): form = CreateForm() if form.validate_on_submit(): qrcode = pyqrcode.create(form.textToCreate.data, error=form.errorCorrection.data) qrid = uuid() qrcode.png('app/static/qrcodes/{}.png'.format(qrid), scale=8) return redirect(url_for('created', qrid=qrid)) return render_template('creator.html', title='QR-CODE CREATOR', form=form)
def createscenario_start(): form = CreateForm() datafiles, datafiles_name = refreshDataFiles() form.option.choices = [(str(i), datafiles_name[i - 1] + ' Scenario - ' + str(i)) for i in range(1, len(datafiles) + 1)] o1 = form.option.data if form.validate_on_submit(): if 'create' in request.form: return redirect( url_for('createscenario_edit', title='Home', option=o1)) elif 'createNew' in request.form: return redirect(url_for('createscenario_new')) return render_template('calculate.html', title='Home', form=form)
def post(self, request, pk=None) : form = CreateForm(request.POST, request.FILES or None) if not form.is_valid() : ctx = {'form' : form} return render(request, self.template, ctx) # Add developer to the model before saving instance = form.save(commit=False) developer = get_object_or_404(Developer, developer_account=request.user) instance.developer = developer instance.save() for language in form.cleaned_data['language']: App_to_language.objects.create(app=instance, language=language) return redirect(self.success_url)
def post(self, request, pk=None) : developer = get_object_or_404(Developer, developer_account=request.user) app = get_object_or_404(App, app_id=pk, developer=developer) form = CreateForm(request.POST, request.FILES or None, instance=app) if not form.is_valid() : ctx = {'form' : form} return render(request, self.template, ctx) app = form.save(commit=False) app.save() app_lan_deletes = get_list_or_404(App_to_language, app=app) for app_lan_delete in app_lan_deletes: app_lan_delete.delete() for language in form.cleaned_data['language']: App_to_language.objects.create(app=app, language=language) return redirect(self.success_url)
def login(): # If the user is already logged in, move them to their game instead if current_user.is_authenticated: return redirect(url_for('main.game', group=current_user.group)) # Instance all the forms joinForm = JoinForm() joinFormPOC = JoinFormPOC() createForm = CreateForm() # If they have joined if joinForm.submit1.data and joinForm.validate(): user = User(group=joinForm.group.data, permission='1') db.session.add(user) db.session.commit() login_user(user) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.game', group=current_user.group) return redirect(next_page) # If they have joined as host if joinFormPOC.submit10.data and joinFormPOC.validate(): user = User(group=joinForm.group.data, permission='2') db.session.add(user) db.session.commit() login_user(user) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.game', group=current_user.group) return redirect(next_page) # If they have created a game if createForm.submit2.data and createForm.validate(): user = User(group=createForm.group.data, permission='2') db.session.add(user) db.session.commit() encounters = Encounter.query.all() game = Game(group=createForm.group.data, compEnc='1', mode='GAME', curEnc='0') game.generateFrequency() game.applyCallsign(CALLSIGN_LIST[randint(0, len(CALLSIGN_LIST) - 1)] + ' ' + str(randint(1, 9))) game.location = LOCATION_LIST[randint(0, len(LOCATION_LIST) - 1)] game.setGoalEnc(20) game.setQRandUpper(len(encounters) - 1) game.setMRandUpper(19) game.selectMarch() game.updateTime() db.session.add(game) db.session.commit() login_user(user) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.game', group=current_user.group) return redirect(next_page) prompt = Prompt.query.all()[0] return render_template(['joinCreate.html', 'base.html'], prompt=prompt, joinForm=joinForm, createForm=createForm, joinFormPOC=joinFormPOC)
def createscenario_edit(option): form = CreateForm() datafiles, datafiles_name = refreshDataFiles() form.option.choices = [(str(i), datafiles_name[i - 1] + ' Scenario - ' + str(i)) for i in range(1, len(datafiles) + 1)] o1 = form.option.data modelfile = modelfile_final for i in range(1, len(datafiles) + 1): if option == str(i): data: str = datafiles[i - 1] couenne = "couenne" option = option model = Model() solver = Solver.lookup(couenne) mini = miniZinc.MiniZincModel(model, solver, data, modelfile) dataList = dataList_final d = mini.getdatainput(dataList) inputdata = {} inputdata['option1'] = d if form.validate_on_submit(): if 'create' in request.form: return redirect( url_for('createscenario_edit', option=o1, form=form)) elif 'createNew' in request.form: return redirect(url_for('createscenario_new')) else: formvalues = request.form for key in formvalues: if key.startswith('nameScenario'): nameScenario = str(request.form[key]) eb = [[0 for x in range(0, d['nproducts'])] for y in range(0, d['ncustomers'])] for key in formvalues: for i in range(0, d['ncustomers']): for j in range(0, d['nproducts']): if key.startswith('eb_' + str(i) + '_' + str(j)): eb[i][j] = int(request.form[key]) for key in formvalues: if key.startswith('nproducts'): nproducts = int(request.form[key]) for key in formvalues: if key.startswith('nsites'): nsites = int(request.form[key]) for key in formvalues: if key.startswith('ncustomers'): ncustomers = int(request.form[key]) for key in formvalues: if key.startswith('payperfine'): payperfine = int(request.form[key]) productionPlan = [[0 for x in range(0, d['nproducts'])] for y in range(0, d['nsites'])] for key in formvalues: for i in range(0, d['nsites']): for j in range(0, d['nproducts']): if key.startswith('productionPlan_' + str(i) + '_' + str(j)): productionPlan[i][j] = int(request.form[key]) supercredit = [0 for x in range(0, d['nproducts'])] for key in formvalues: for i in range(0, d['nproducts']): if key.startswith('supercredit_' + str(i)): supercredit[i] = float(request.form[key]) supercredit[i] = int(supercredit[i] * 100) demand = [[0 for x in range(0, d['nproducts'])] for y in range(0, d['ncustomers'])] for key in formvalues: for i in range(0, d['ncustomers']): for j in range(0, d['nproducts']): if key.startswith('demand_' + str(i) + '_' + str(j)): demand[i][j] = int(request.form[key]) excessdemand = [0 for x in range(0, d['nproducts'])] for key in formvalues: for i in range(0, d['nproducts']): if key.startswith('excessdemand_' + str(i)): excessdemand[i] = float(request.form[key]) maxProduction = [0 for x in range(0, d['nsites'])] for key in formvalues: for i in range(0, d['nsites']): if key.startswith('maxProduction_' + str(i)): maxProduction[i] = int(request.form[key]) emissionWLTP = [0 for x in range(0, d['nproducts'])] for key in formvalues: for i in range(0, d['nproducts']): if key.startswith('emissionWLTP_' + str(i)): emissionWLTP[i] = int(request.form[key]) weight = [0 for x in range(0, d['nproducts'])] for key in formvalues: for i in range(0, d['nproducts']): if key.startswith('weight_' + str(i)): weight[i] = int(request.form[key]) saveData = {} saveData['nproducts'] = nproducts saveData['nsites'] = nsites saveData['ncustomers'] = ncustomers saveData['maxProduction'] = maxProduction saveData['emissionWLTP'] = emissionWLTP saveData['weight'] = weight saveData['excessdemand'] = excessdemand saveData['supercredit'] = supercredit saveData['productionPlan'] = productionPlan saveData['payperfine'] = payperfine saveData['demand'] = demand saveData['eb'] = eb saveData['pname'] = d['pname'] saveData['cname'] = d['cname'] saveData['sname'] = d['sname'] miniZinc.saveDataFile(saveData, nameScenario) return redirect(url_for('calculate')) return render_template('createscenario_edit.html', title='Home', form=form, option=option, input=d)
def get(self, request, pk) : developer = get_object_or_404(Developer, developer_account=request.user) app = get_object_or_404(App, app_id=pk, developer=developer) form = CreateForm(instance=app) ctx = { 'form': form } return render(request, self.template, ctx)
def get(self, request, pk=None) : form = CreateForm() ctx = { 'form': form } return render(request, self.template, ctx)