Пример #1
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})
Пример #2
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)
Пример #3
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))
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #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))
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
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'))
Пример #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'))
Пример #13
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)
Пример #14
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'))
Пример #15
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)
Пример #16
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})
Пример #17
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())
Пример #18
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'))
Пример #19
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, )
Пример #20
0
def extraction(request):
    if request.method == 'POST':
        form = NameForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            extracted_data = data['news_link']
            link, news, title = manual_extract(extracted_data)

            #
            # If you want to save the input news
            oldlinks = rssdata.objects.values_list('link', flat=True)

            if link not in oldlinks:
                id = extract(link, news, title)
                return render(
                    request, 'extraction.html', {
                        'form': form,
                        'news_id': id,
                        'article': rssdata.objects.get(pk=id)
                    })
            else:
                id = 5
                return render(
                    request, 'extraction.html', {
                        'form': form,
                        'news_id': id,
                        'article': rssdata.objects.get(link=link)
                    })

        # #

        #

    else:
        form = NameForm()

    return render(request, 'extraction.html', {'form': form})
Пример #21
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)
Пример #22
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())
Пример #23
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)
Пример #24
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'))
Пример #25
0
def edit_name(id):
    """
    Edit a name
    """
    check_admin()

    add_name = False

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

        db.session.add(name)
        db.session.commit()
        flash('You have successfully edited the name.')

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

    form.name_male = name.name_male
    form.script_male = name.script_male
    form.name_female = name.name_female
    form.script_female = name.script_female
    form.meaning = name.meaning
    form.first_name = name.first_name
    form.second_name = name.second_name
    form.language = name.language
    form.source = name.source
    form.confirmation = name.confirmation
    form.popularity = name.popularity
    form.note = name.note
    return render_template('admin/names/name.html',
                           add_name=add_name,
                           form=form,
                           title="Edit Name")
Пример #26
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))
Пример #27
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))
Пример #28
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())
Пример #29
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))
Пример #30
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')