Example #1
0
def	New(request):

    try:
	if CheckAccess(request,'23') != 'OK':
	    return render_to_response("mtmc/notaccess/mtmc.html")
    except:
	return HttpResponseRedirect('/')


    if request.method == 'POST':
	form = NameForm(request.POST)
	if form.is_valid():
	    name = form.cleaned_data['name']
	    result = NewEq(request,name)
	    if result:
		return HttpResponseRedirect('/mtmcedit/?eq_id=%s' % result)


    form = NameForm(None)



    c = RequestContext(request,{'form':form})
    c.update(csrf(request))
    return render_to_response("mtmc/new.html",c)
Example #2
0
def get_msg(request):
    user_msg = "Thanks :)"
    form = NameForm()
    if request.method == "POST":
        form = NameForm(request.POST)
        if form.is_valid():
            # p = Person()
            user_msg = form.cleaned_data["msg"]
            print user_msg

    details = {}
    facebook_profile = request.user
    user = User.objects.filter(username=facebook_profile)
    access_token = (UserSocialAuth.objects.filter(
        user=user))[0].extra_data['access_token']

    url = "https://graph.facebook.com/me?fields=first_name,name,picture,birthday"
    parameters = {'access_token': access_token}
    detail = requests.get(url, params=parameters).json()

    details['name'] = detail['name']
    details['first_name'] = detail['first_name']
    details['picture'] = detail['picture']['data']['url']
    details['birthday'] = detail['birthday']

    bday = requests.get(url, params=parameters)
    bday = detail['birthday']
    bday_date = str(bday.split('/')[1])
    bday_nextdate = str(int(bday.split('/')[1]) + 1)
    bday_month = str(bday.split('/')[0])
    current_year = str(date.today().year)

    current_bday = bday_month + "/" + bday_date + "/" + current_year
    next_day = bday_month + "/" + bday_nextdate + "/" + current_year

    url = "https://graph.facebook.com/v2.4/me/feed?since=" + "08/17/2015" + "&until=" + "08/18/2015"
    # url = "https://graph.facebook.com/v2.4/me"
    parameters = {'access_token': access_token}
    related_list = requests.get(url, params=parameters)
    related_list = related_list.json()
    print related_list
    for msg in related_list['data']:
        try:
            print msg['id']
            url = "https://graph.facebook.com/" + msg['id']
            parameters = {'access_token': access_token}
            per_post = requests.get(url, params=parameters).json()
            print per_post
            bday_list = [
                "birthday", "birth", "bdae", "bday", "b'day", "janamdin",
                "janmdin", "returns", "day", "brth", "hbd", "hb", "happy",
                "day", "wish", "wishing"
            ]
            for txt in bday_list:
                if txt in per_post['message']:
                    thanks(per_post['id'], user_msg, access_token)
                    break
        except:
            print "Error"
    return render(request, 'index.html', {'details': details})
Example #3
0
def index():
    name = None
    form = NameForm()
    if form.validate_on_submit():
        name = form.name.data
        form.name.data = ''
    return render_template('auth.html', form=form, name=name)
Example #4
0
def index():
    form = NameForm(csrf_enabled=False)
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if user is None:
            flash(u'数据表里面无此姓名,添加进数据库!')
            user = User(username=form.name.data)
            db.session.add(user)
            db.session.commit()
            session['known'] = False

        else:
            flash(u'数据库此人姓名已存在,不做重复添加!')
            session['known'] = True

    #     old_name = session.get('name')
    #     if old_name is not None and old_name !=form.name.data:
    #         flash(u'你居然修改自己的名字,你妈知道吗?')
        session['name'] = form.name.data
        form.name.data = ''
        return redirect(url_for('main.index'))

    #将数据传值给前段页面引用
    return render_template('index.html',
                           current_time=datetime.utcnow(),
                           form=form,
                           name=session.get('name'),
                           known=session.get('known', False))
Example #5
0
def enternames(id, num_players):
    form = NameForm()
    if form.validate_on_submit():
        name = form.playername.data
        flash(f'Good luck {name}!! ', 'dark')
        if num_players == 1:
            session['name'] = name
            rand_week = random.randrange(38)
            session['week'] = rand_week
            session['id'] = 1
            session['score'] = 0
            return redirect(url_for('game', id=1, attempt=1))
        if id < num_players:
            session['name_1'] = name
            return redirect(
                url_for('enternames', id=id + 1, num_players=num_players))
        elif id == num_players:
            session['name_2'] = name
            rand_week = random.randrange(38)
            session['week'] = rand_week
            session['score_a'] = 0
            session['score_b'] = 0
            return redirect(url_for('multiplayer', id=1, p_num=1, attempt=1))
    return render_template('enternames.html',
                           form=form,
                           id=id,
                           num_players=num_players)
Example #6
0
def login():
    form = NameForm()
    if form.validate_on_submit():
        if form.radio.data == 'admin':
            user = admin.query.filter_by(username=form.email.data,
                                         password=form.password.data).first()
            if user is not None:
                login_user(user)
                return redirect(url_for('main.employee'))
            flash(u'无效的邮箱或者密码')
        elif form.radio.data == 'trainset':
            user = trainset.query.filter_by(
                username=form.email.data, password=form.password.data).first()
            if user is not None:
                login_user(user)
                return redirect(url_for('main.trainset_attendance'))
            flash(u'无效的邮箱或者密码')
        elif form.radio.data == 'test':
            user = test.query.filter_by(username=form.email.data,
                                        password=form.password.data).first()
            if user is not None:
                login_user(user)
                return redirect(url_for('main.result'))
            flash(u'无效的邮箱或者密码')
        else:
            flash(u'请选择角色')
    return render_template('auth/auth.html', form=form)
Example #7
0
def form_email():
    form = NameForm()

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if user is None:
            user = User(username=form.name.data)
            db.session.add(user)
            db.session.commit()
            session['known'] = False
            if app.config['FLASKY_ADMIN']:
                email_job = mails.send_email(
                    app.config['FLASKY_ADMIN'],
                    'New User',
                    'mail/new_user',
                    user=user
                )
                print("email_job", email_job)
        else:
            session['known'] = True
        old_name = session.get('name')
        if old_name is not None and old_name != form.name.data:
            flash('Looks like you have changed your name!')
        session['name'] = form.name.data
        return redirect(url_for('form_email'))

    return render_template('form.html',
                           form=form,
                           name=session.get('name'),
                           known=session.get('known', False))
def index_with_session_and_post_redirect():
    name_form = NameForm()
    if name_form.validate_on_submit():
        if name_form.name.data == 'stevo':
            flash('Enter another name, stevo is reserved.')
        session['name'] = name_form.name.data
        return redirect(url_for('.index_with_session_and_post_redirect'))
    return render_template('index.html', name=session.get('name'), form=name_form)
Example #9
0
def register():
    form = NameForm()
    if form.validate_on_submit():
        session['name'] = form.name.data
        flash('Looks like you have changed your name!')
        return redirect(url_for('index'))
    return render_template('register.html',
                           form=form,
                           name=session.get('name'))
Example #10
0
def hello():
	form=NameForm()
	if form.validate_on_submit():
		old_name=session.get('name')
		if old_name is not None and old_name != form.name.data:
			flash('name changed')
		session['name']=form.name.data
		return redirect(url_for('hello'))
	return render_template('index.html',form=form,name=session.get('name'))
Example #11
0
def getname():
    form_data = NameForm()
    if form_data.validate_on_submit():
        username = form_data.name.data
        user = User.query.filter_by(user_id=current_user.user_id).first()
        user.username = username
        db.session.commit()
        return flask.redirect(url_for('account'))
    return render_template('getname.html', form_data=form_data)
Example #12
0
def index():
    form = NameForm()

    if form.validate_on_submit():
        notify(session.get('name'), form.name.data)
        session['name'] = form.name.data
        return redirect(url_for('index'))

    return render_template('index.html', form=form, name=session.get('name'))
Example #13
0
def form_view2():
    form = NameForm()
    if form.validate_on_submit():
        old_name = session.get('name')
        if old_name is not None and old_name != form.name.data:
            flash('Looks like you have changed your name!')
        session['name'] = form.name.data
        return redirect(url_for('form_view2'))
    return render_template('form.html', form=form, name=session.get('name'))
Example #14
0
def index():

    form = NameForm()
    if form.validate_on_submit():
        old_name = session.get('name')
        if old_name is not None and old_name != form.name.data:
            flash(u'二次输入的姓名不一样!')
        session['name'] = form.name.data
        return redirect(url_for('.index'))
    return render_template('index.html', form=form, name=session.get('name'))
Example #15
0
def index():

    form = NameForm()
    if form.validate_on_submit():
        old_name = session.get("name")
        if old_name is not None and old_name != form.name.data:
            flash(u"二次输入的姓名不一样!")
        session["name"] = form.name.data
        return redirect(url_for(".index"))
    return render_template("index.html", form=form, name=session.get("name"))
Example #16
0
def get_msg(request):
	user_msg = "Thanks :)"
	form = NameForm()
	if request.method == "POST":
		form = NameForm(request.POST)
		if form.is_valid():
				# p = Person()
				user_msg = form.cleaned_data["msg"]
				print user_msg

	details = {}
	facebook_profile = request.user
	user = User.objects.filter(username = facebook_profile)
	access_token = (UserSocialAuth.objects.filter(user = user))[0].extra_data['access_token']

	url = "https://graph.facebook.com/me?fields=first_name,name,picture,birthday"
	parameters = {'access_token': access_token}
	detail = requests.get(url, params = parameters).json()

	details['name'] = detail['name']
	details['first_name'] = detail['first_name']
	details['picture']= detail['picture']['data']['url']
	details['birthday'] = detail['birthday']

	bday = requests.get(url, params = parameters)
	bday =  detail['birthday']
	bday_date = str(bday.split('/')[1])
	bday_nextdate = str(int(bday.split('/')[1])+1)
	bday_month = str(bday.split('/')[0])
	current_year = str(date.today().year)

	current_bday = bday_month+"/"+bday_date+"/"+current_year
	next_day = bday_month+"/"+bday_nextdate+"/"+current_year

	url = "https://graph.facebook.com/v2.4/me/feed?since="+"08/17/2015"+"&until="+"08/18/2015"
	# url = "https://graph.facebook.com/v2.4/me"
	parameters = {'access_token': access_token}
	related_list = requests.get(url, params = parameters)
	related_list = related_list.json()
	print related_list
	for msg in related_list['data']:
		try:
			print msg['id']
			url = "https://graph.facebook.com/"+msg['id']
			parameters = {'access_token': access_token}
			per_post = requests.get(url, params = parameters).json()
			print per_post
			bday_list = ["birthday", "birth", "bdae", "bday", "b'day", "janamdin", "janmdin", "returns", "day", "brth", "hbd", "hb", "happy", "day", "wish", "wishing"]
			for txt in bday_list:
				if txt in per_post['message']:
					thanks(per_post['id'], user_msg, access_token)
					break
		except:
			print "Error"
	return render(request, 'index.html',{ 'details' : details })
Example #17
0
def form_edit(request,pk=id):
    if request.POST:
        form=NameForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/show/")
    else:
        form=NameForm()
        

    return render(request,"form.html",locals())
Example #18
0
def index():
    #return render_template('index.html')
    form = NameForm()
    if form.validate_on_submit():
        #...
        return redirect(url_for('index'))
    return render_template('index.html',
                           form = form,
                           name = session.get('name'),
                           known = session.get('known', False),
                           current_time = datetime.utcnow())
Example #19
0
def get_name(request):
    form=NameForm()
    form1=UpdateForm()
    s8 = prediction_content.get_prediction_content()
    json_pre = json.dumps(s8)

    # if this is a POST request we need to process the form data
    if request.method == 'POST' and 'search' in request.POST:
        # create a form instance and populate it with data from the request:
        form = NameForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            #start of search processing time
            start_time=time.time()
            your_name = request.POST.get('your_name')
            your_name1=your_name
            s=search1.get_search_result(your_name1)
            s1=search1.get_file_name()
            s3=[]
            s4=search1.pre()
            s5=search1.get_knownerror()
            for i in s1:
                if i not in s3:
                    s3.append(i)
            s2=zip(s,s1,s4,s5)
            c=len(s)
            tim=time.time()-start_time
            tim=str(tim)+" sec"
            #end of search process time
            form=NameForm()

            return render(request,'myapp/thanks.html',{'name':your_name1,'file':s3,'filename':s2,'number':c,'result':s,'form':form,'form1':form1,'soln':s,'ti':tim,'json_pre':json_pre})

    if request.method == 'POST' and 'update' in request.POST:
        form1 = UpdateForm(request.POST)
        if form1.is_valid():
            question = request.POST.get('question')
            answer = request.POST.get('comment')
            pre = request.POST.get('pre')
            file_choice=request.POST.get('file_choice')
            print answer

            print question
            print file_choice
            form1 = UpdateForm()
            update.update(question,answer,pre,file_choice)

            return render(request, 'myapp/thanks.html',
                          {'form':form,'form1':form1,'json_pre':json_pre})
    else:
            form = NameForm()
            form1=UpdateForm()


    #template = loader.get_template("myapp/name.html")
    context = {'form': form,'form1':form1,'json_pre':json_pre}
    #return HttpResponse(template.render(context, request))
    return render(request, "myapp/name.html", context)
def index():
    """List all examples"""
    example = NameModel.query()
    form = NameForm()
    if form.validate_on_submit():
        example = NameModel(
            name=form.name.data,
        )
        example.put()
        flash(u"Well, that went fine didn't it?", 'success')
        return redirect(url_for('index'))
    examples = NameModel.query().order(-NameModel.timestamp) # descending
    return render_template('index.html', nav_title="The Flask Project", examples=examples, form=form, current_time=datetime.utcnow())
Example #21
0
def login():   
    form = NameForm()
    if request.method == 'GET':
        return render_template("login.html", form=form)
    if request.method == 'POST' and form.validate():
        user = User.query.filter_by(username=form.name.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            flash(u'登录成功!')
            return redirect(url_for('list')) 
        else:
            flash(u'用户名或密码错误')
            return redirect(url_for('login'))
Example #22
0
def profile(request):
    if request.method=="POST":
        form=NameForm(request.POST, request.FILES)
        if form.is_valid():
            name=form.cleaned_data['name']
            surname=form.cleaned_data['surname']
            email=form.cleaned_data['email']
            ssc=form.cleaned_data['ssc']
            inter=form.cleaned_data['inter']
            phone_number=form.cleaned_data['phone_number']
            highest_qualification=form.cleaned_data['highest_qualification']
            docfile=form.cleaned_data['docfile']
            p=Profile()
            p.name=name
            p.surname=surname
            p.email=email
            p.ssc=ssc
            p.inter=inter
            p.phone_number=phone_number
            p.highest_qualification=highest_qualification
            p.docfile=docfile
            p.save()
            print docfile
            from email.mime.text import MIMEText
            #attachment.add_header('Content-Disposition', 'attachment', filename=f) 
            success = "yes"
            subject="profile informayion"
            #url='http://127.0.0.1:8000/resetpwd/'
            url='http://127.0.0.1:8000/resetpwd/{0}'
            html_content='<a href="%s" > download</a>'% url
            body = preprocess_email_body(request,  html_content)
            email = EmailMessage(subject, body, to=[email])
            try:
              #email =EmailMultiAlternatives(subject,body,to=[email])
              email.attach(docfile.name, docfile.read(), docfile.content_type)
              content_subtype = "html"
              #email.attach_alternative(html_content, "text/html")
              #email.attach(attachment)
              email.send()
              #return render(request,"profile.html",locals())       
              success = "yes"
            except Exception as e:
              print e
             
            return render (request,"profile.html",locals())
        else:
            error = "yes"
            print "34233333434", form.errors
    else:
        form=NameForm()
    return render(request,"profile.html",{"form":form})
Example #23
0
def index():
    form = NameForm()
    if form.validate_on_submit():
        old_name = session.get('name')
        if old_name is not None and old_name != form.name.data:
            flash('Looks like you have changed your name!')
        session['name'] = form.name.data
        return redirect(url_for('index'))
    context = {
        'current_time': datetime.utcnow(),
        'form': form,
        'name': session.get('name')
    }
    return render_template('index.html', **context)
Example #24
0
def login2():
    if 'pno' not in session.keys():
        flash('enter pno first')
        return redirect(url_for('login'))

    form = NameForm()
    if form.validate_on_submit():
        firstname = form.firstname.data
        lastname = form.lastname.data

        session['firstname'] = firstname
        session['lastname'] = lastname
        return redirect(url_for('login3'))
    return render_template('login.html', form=form)
Example #25
0
def index():
    name = None
    form = NameForm()
    if form.validate_on_submit():
        old_name = session.get('name')
        if old_name is not None and old_name != form.name.data:
            flash('Похоже, вы изменили свое имя!')
        session['name'] = form.name.data
        form.name.data = ''
        return redirect(url_for('index'))
    return render_template('index.html',
                           form=form,
                           name=session.get('name'),
                           current_time=datetime.utcnow())
Example #26
0
def index():
	form = NameForm()
	if form.validate_on_submit():
		user = User.query.filter_by(username=form.name.data).first()
		if user is None:
			user = User(username=form.name.data)
			db.session.add(user)
			#db.session.commit()
			session['known'] = False
		else:
			session['known'] = True
		session['name'] = form.name.data
		form.name.data = ''
		return redirect('/')
	return render_template('index.html', current_time = datetime.utcnow(), form = form, name = session.get('name'), known = session.get('known', False))
Example #27
0
def form():
    #name=''
    nameform = NameForm()
    if nameform.validate_on_submit():
        #name=nameform.name.data
        old_name = session.get('name')
        if old_name and old_name != nameform.name.data:
            flash('您更换了名字')
        session['name'] = nameform.name.data
        nameform.name.data = ''

        return redirect(url_for('form'))
    return render_template('nameform.html',
                           nameform=nameform,
                           name=session.get('name'))
Example #28
0
def index():
    tweet = {}
    form = PostForm()
    name = NameForm()

    tweetText = form.post.data
    userName = name.name.data

    if tweetText != "":
        tweet[userName] = tweetText
        if (os.path.exists('./file.json')):
            with open('./file.json', 'r') as fr:
                data = json.load(fr)
            data.append(tweet)
            with open('./file.json', "w") as fw:
                f = json.dumps(data)
                fw.write(f)
        else:
            print("File doesn't exist!")
            with open('./file.json', "w+") as f:
                json.dump([], f)
    else:
        pass

    with open('./file.json', 'r') as fr:
        posts = json.load(fr)

    posts = reversed(posts)

    print(posts)
    return render_template('index.html',
                           title='Twitter Clone',
                           name=name,
                           form=form,
                           posts=posts)
Example #29
0
def edit_speaker_profile(request):
    profile = Speaker.objects.get(user = request.user)
    done = False
    if request.method == 'POST':
        name_form = NameForm(request.POST, instance=request.user)
        speaker_form = SpeakerProfile(request.POST, instance=profile)
        if name_form.is_valid() and speaker_form.is_valid():
            name_form.save()
            speaker_form.save()
            done = True
    else:
        name_form = NameForm(instance=request.user)
        speaker_form = SpeakerProfile(instance=profile)

    return render(request, 'access/edit_profile.html',
            {'title': u"Editar Perfil", 'name_form': name_form, 'speaker_form': speaker_form, 'done': done } )
Example #30
0
def form(request):
    if request.method == 'POST':
        form=NameForm(request.POST)
        if form.is_valid():
            name=form.cleaned_data['name']
            city=form.cleaned_data['city']
            m=Metro()
            m.name=name
            m.city=city
            m.save()
            return HttpResponseRedirect("/show/")

    else:
        form=NameForm()
        

    return render(request,"form.html",locals())
Example #31
0
def new_user():
    form = NameForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if user is None:
            user = User(username=form.name.data)
            db.session.add(user)
            session['known'] = False
            flash('Looks like you have changed your name!')
        else:
            session['known'] = True
        session['name'] = form.name.data
        form.name.data = ''
        return redirect(url_for('home'))
    return render_template('newuser.html',
                           form=form,
                           name=session.get('name'),
                           known=session.get('known', False))
Example #32
0
def index():
    predicted_tags = None
    if request.method == 'POST':
        sentence = ' ' + request.form['sentence']
        predicted_tags = predict_tags(MODEL, sentence, WORD, TAG)

    form = NameForm()

    return render_template('index.html', form=form, predicted_tags=predicted_tags)
Example #33
0
def home_forms(request):
    print 'welcome to my forms'

    if request.method == 'POST':

        form = NameForm(request.POST)

        if form.is_valid():

            return HttpResponseRedirect('/thanks/')

    else:

        form = NameForm()

    context = {'form': form}

    return render(request, 'blogs/forms.html', context)
Example #34
0
def index():
    names = None
    if request.method == 'POST':
        start_seed = ' ' + request.form['start_seed']
        names = inference(start_seed, 10)

    form = NameForm()

    return render_template('index.html', form=form, names=names)
Example #35
0
def index():
    form = NameForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if user is None:
            user = User(username=form.name.data)
            db.session.add(user)
            session['known'] = False
            if current_app.config['FLASKY_ADMIN']:
                send_email(current_app.config['FLASKY_ADMIN'], 'New User',
                           'mail/new_user', user=user)
        else:
            session['known'] = True
        session['name'] = form.name.data
        return redirect(url_for('.index'))
    return render_template('index.html',
                           form=form, name=session.get('name'),
                           known=session.get('known', False))
Example #36
0
def get_name(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = NameForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            #return HttpResponseRedirect('app2/name.html')
            return render(request, 'app2/name.html', {'form': form})

    # if a GET (or any other method) we'll create a blank form
    else:
        form = NameForm()

    return render(request, 'app2/name.html', {'form': form})
Example #37
0
def login():
    form = NameForm()
    
    if request.method == 'POST':
        session['name'] = form.name.data
        return redirect(url_for('hours'))
    elif request.method == 'GET':
        return render_template('login.html',
                               form=form,
                               now=datetime.now())
Example #38
0
def get_name(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = NameForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            p = models.Person()
            p.your_name = request.POST['your_name']
            p.pub_date = timezone.now()
            p.save()
            # redirect to a new URL:
            return HttpResponseRedirect('/thanks/')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = NameForm()

        return render(request, 'forms/name.html', {'form': form})
Example #39
0
    def get(self, request):
        games = Frame.objects.select_related('game').order_by('id')
        form = NameForm()
        template = 'bowling/index.html'

        data = {
            'form': form,
            'games': games
        }

        return render(request, template, )
Example #40
0
def form_db():
    """ Render a form for username and save the user name to a db """
    form = NameForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if user is None:
            user = User(username=form.name.data)
            db.session.add(user)
            db.session.commit()
            session['known'] = False
        else:
            session['known'] = True
        old_name = session.get('name')
        if old_name is not None and old_name != form.name.data:
            flash('Looks like you have changed your name!')
        session['name'] = form.name.data
        return redirect(url_for('form_db'))
    return render_template('form.html',
                           form=form,
                           name=session.get('name'),
                           known=session.get('known', False))
Example #41
0
def home_forms(request):
	print 'welcome to my forms'

	if request.method == 'POST':

		form = NameForm(request.POST)

		if form.is_valid():

			return HttpResponseRedirect('/thanks/')

	else:

		form = NameForm()


	context = {
		'form' : form
	}

	return render(request, 'blogs/forms.html', context)
Example #42
0
def index():
    name = None
    form = NameForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if user is None:
            user = User(username = form.name.data)
            db.session.add(user)
            session['known'] = False
            if  app.config['FLASKY_ADMIN']:
                send_email(app.config['FLASKY_ADMIN'], 'New User', \
                    'mail/new_user', user=user)
        else:
            session['known'] = True
            flash('Haha !')
        session['name'] = form.name.data
        form.name.data = ''
        return redirect(url_for('index'))
    return render_template('index.html',    \
        form=form, name=session.get('name'), \
        current_time=datetime.utcnow())
Example #43
0
def add_name():
    """
    Add a name to the database
    """
    check_admin()

    add_name = True

    form = NameForm()
    if form.validate_on_submit():
        name = Name(name_male=form.name_male.data,
                    script_male=form.script_male.data,
                    name_female=form.name_female.data,
                    script_female=form.script_female.data,
                    meaning=form.meaning.data,
                    first_name=form.first_name.data,
                    second_name=form.second_name.data,
                    language=form.language.data,
                    source=form.source.data,
                    confirmation=form.confirmation.data,
                    popularity=form.popularity.data,
                    note=form.note.data)

        try:
            # add name to the database
            db.session.add(name)
            db.session.commit()
            flash('You have successfully added a new name.')
        except:
            # in case name name already exists
            flash('Error: name already exists.')

        # redirect to the names page
        return redirect(url_for('admin.list_names'))

    # load name template
    return render_template('admin/names/name.html',
                           add_name=add_name,
                           form=form,
                           title='Add Name')
Example #44
0
def index():
 name=None
 form = NameForm()
 ford=submit()
 
 if form.validate_on_submit():
         name= form.name.data
         form.name.data=""
         bdd.append(name)
         return redirect(url_for('main.index'))
 if ford.boole.data==True:
            ford.boole.data=False
            re=request.form['text']
            l=0
            for idd in bdd:
                 if idd==re:
                         bod.append(re)
                         del bdd[l]
                         break
                 l=l+1      
            return redirect(url_for('main.index'))
 return render_template('a.html', form=form, name=bdd,ford=ford,bod=bod)
Example #45
0
def data():
    nameform = NameForm()
    if nameform.validate_on_submit():
        user = User.query.filter_by(username=nameform.name.data).first()
        if user:
            session['known'] = True
        else:

            session['known'] = False
            newuser = User(username=nameform.name.data, role_id=2)
            db.session.add(newuser)
            send_mail(app.config['FLASKY_ADMIN'],
                      '新用户',
                      'mail/new_user',
                      user=newuser)
        session['name'] = nameform.name.data
        nameform.name.data = ''
        return redirect(url_for('data'))
    return render_template('nameform.html',
                           name=session.get('name'),
                           nameform=nameform,
                           known=session.get('known', False))
Example #46
0
def create_category():
    '''handles creation of a new category'''
    # This function uses the Flask-wtf form, to demonstrate it. The others don't
    # again, to demonstrate the different methods.
    form = NameForm()
    if form.validate_on_submit() and 'username' in login_session:
        category_name = form.name.data
        if session.query(Category).filter_by(name=category_name).first():
            flash('Category: {} already exits'.format(category_name))
        else:
            new_category = Category(name=category_name,
                                    creator_id=login_session['user_id'])
            session.add(new_category)
            session.commit()
            flash('{} created'.format(new_category.name))
    elif 'username' in login_session:
        # i.e. we have a logged in user, so go to createCategory.html
        return render_template('createCategory.html', form=form)
    else:
        flash('You need to login first to create a Category')
        return render_template('login.html')
    return redirect(url_for('show_catalog'))
Example #47
0
def	Edit(request):

    try:
	if CheckAccess(request,'23') != 'OK':
	    return render_to_response("mtmc/notaccess/mtmc.html")
    except:
	return HttpResponseRedirect('/')

    try:
	eq_id = request.GET['eq_id']
	request.session['eq_id'] = eq_id
    except:
	pass

    try:
	eq_id = request.session['eq_id']
    except:
	return HttpResponseRedirect('/mtmc')
	

    if request.method == 'POST':
	form = NameForm(request.POST)
	if form.is_valid():
	    name = form.cleaned_data['name']
	    EditName(eq_id,name)

    eq = GetEq(eq_id)

    form = NameForm(None)
    form.fields['name'].initial = eq['name']
    
    field = DateTimeField()
    create = field._to_python(eq['create'])
    author = eq['author_name'].split()[1]+' '+eq['author_name'].split()[0]

    c = RequestContext(request,{'form':form,'eq':eq,'create':create,'author':author,'tmc':TmcUrl(eq)})
    c.update(csrf(request))
    return render_to_response("mtmc/edit.html",c)
Example #48
0
def index():
    form = NameForm()
    if form.validate_on_submit():
        user = Users.query.filter_by(name=form.name.data).first()
        if user is None:
            user = '******'
            # user = User(name = form.name.data, email=form.email.data, market)
            # db.session.add(user)
    # user = g.user  # Added user to the g object in before_request func. (far below)

    # Mock markets data; these will be used as a starting point
    # + for each users' comparisons for new ad data and alerts
    # + (i.e., I don't necessarily want all of Scott's alerts and v.v.).


    # What we want is a list of users and their subscriptions (so, two text fields,
    # + one for user name and one for markets followed), with a blank one for new
    # + email addresses and/or subscriptions. This blank one will allow for creation.

    # users = [{'name':'James', 'email':'*****@*****.**'},
             # {'name':'Scott', 'email':'*****@*****.**'}]

    ## Super testing of user-db storage -- FIXME
    # james = User(name='James', email='*****@*****.**', role=ROLE_USER)
    # scott = models.User(name='Scott', email='*****@*****.**', role=modles.ROLE_USER)

    ## Add me to db.session, for committing (adding a new row).
    ## NB: To add more than one row at once, use db.session.add_all([list of objects]).
    if 'james' not in Users.query().all():
        db.session.add(james)
        db.session.commit()


    return render_template('index.html',
                            title = 'Home',
                            user =  james,  ### FIXME
                            dmas = dmas)
Example #49
0
def index(template):
	form = NameForm(request.form)
	if request.method == 'POST' and form.validate():
		session["name"] = form.name.data
	return render_template(template, form=form)
def index():
    name_form = NameForm()
    if name_form.validate_on_submit():
        name = name_form.name.data
    user_agent = request.headers.get('User-Agent')
    return render_template('index.html', user_agent=user_agent, name=name, form=name_form)
Example #51
0
def tool():
	form = NameForm(request.form)
	if request.method == 'POST' and form.validate():
		session["name"] = name_alter(form.name.data)
	return render_template('tool.html', form=form)