コード例 #1
0
ファイル: views.py プロジェクト: fugu13/opp-frontpage
def home(request):
    user = local.gae_user
    account = models.GoogleAccount.gql('WHERE google_user = :1', user).get()
    if account:
        any_submission_key = db.GqlQuery('SELECT __key__ FROM Submission WHERE account = :1', account.key()).get()
        if any_submission_key:
            return redirect(url_for('home/dashboard'))
        else:
            return redirect(url_for('home/submit'))
    else:
        account = models.GoogleAccount(google_user=user, email=user.email())
        account.put()
        return redirect(url_for('home/first'))
コード例 #2
0
ファイル: views.py プロジェクト: fugu13/opp-frontpage
def resubmit(request, submission_id):
    submission = models.Submission.get_by_id(submission_id)
    if submission is None or submission.account.key().id() != local.account.key().id():
        logging.warning('Attempt to resubmit submission "%s" by account "%s" with email "%s".' % (submission_id, local.account.key().id(), local.account.email))
        return redirect(url_for('main/index'))
    if request.method == "POST":
        form = forms.ResubmissionForm(request.form)
        if form.validate():
            submission.text_list.append(db.Text(utils.text_tidy(form.text.data)))
            submission.put()
            flash("Your submission has been updated.")
            return redirect(url_for('home/preview', submission_id=submission.key().id()))
    else:
        form = forms.ResubmissionForm(obj=submission)
    return render_response('resubmit.html', form=form, submission=submission)
コード例 #3
0
ファイル: utils.py プロジェクト: fugu13/opp-frontpage
 def wrapper(request, *args, **kwargs):
     account = get_current_account()
     if account:
         local.account = account
         return view(request, *args, **kwargs)
     else:
         return redirect(users.create_login_url(request.path))
コード例 #4
0
ファイル: views.py プロジェクト: fugu13/opp-frontpage
def faq_admin_group(request):
    if request.method == 'POST':
        form = forms.GroupForm(request.form)
        if form.validate():
            group = models.FrequentlyAskedQuestionGroup(title=form.title.data, weight=form.weight.data)
            group.put()
            return redirect(url_for('main/faq'))
    else:
        form = forms.GroupForm()
    return render_response('faq_admin_group.html', form=form)
コード例 #5
0
ファイル: views.py プロジェクト: fugu13/opp-frontpage
def faq_admin_question(request):
    if request.method == 'POST':
        form = forms.QuestionForm(request.form)
        if form.validate():
            group = models.FrequentlyAskedQuestionGroup.get_by_id(int(form.group.data))
            question = models.FrequentlyAskedQuestion(question=form.question.data, answer=form.answer.data, weight=form.weight.data, group=group.key())
            question.put()
            return redirect(url_for('main/faq'))
    else:
        form = forms.QuestionForm()
    return render_response('faq_admin_question.html', form=form)
コード例 #6
0
ファイル: notes.py プロジェクト: passy/glashammer-rdrei
def add_edit_view(req, nid=None):
    if nid is None:
        form = NotesForm(req.form)
        # Validate form
        if req.method == 'POST' and form.validate():
            # No validation errors, save note and redirect to success page
            note = Note(
                        req.form.get('title'),
                        req.form.get('note'),
                        req.form.get('importance')
                        )
            db.add(note)
            db.commit()
            return redirect(url_for('example/success'))
        return render_response('notes_add.jinja', form=form)
    else:
        # Find note
        note = db.query(Note).get(nid)
        # Check if note exists
        if note is None:
            return Response('Not Found', status=404)
        # Form with values
        form = NotesForm(req.form,
                        title = note.title,
                        note = note.note,
                        importance = note.importance
                        )
        # Validate form
        if req.method == 'POST' and form.validate():
            # No validation errors, update note and redirect to success page
            note.title = req.form.get('title')
            note.note = req.form.get('note')
            note.importance = req.form.get('importance')
            db.add(note)
            db.commit()
            return redirect(url_for('example/success'))
        return render_response('notes_edit.jinja', note=note, form=form)
コード例 #7
0
ファイル: views.py プロジェクト: fugu13/opp-frontpage
def submit(request):
    if request.method == "POST":
        form = forms.SubmissionForm(request.form)
        if form.validate():
            submission = models.Submission(account=local.account,
                                           simultaneous=form.simultaneous.data,
                                           cover_letter=db.Text(utils.text_tidy(form.cover_letter.data)),
                                           title=utils.text_tidy(form.title.data),
                                           text_list=[db.Text(utils.text_tidy(form.text.data))],
                                           categories=form.categories.data)
            submission.put()
            flash("Your submission has been saved.")
            return redirect(url_for('home/preview', submission_id=submission.key().id()))
    else:
        form = forms.SubmissionForm()
    return render_response('submit.html', form=form)
コード例 #8
0
ファイル: __init__.py プロジェクト: fugu13/opp-frontpage
def view_login(request):
    """Show a login page."""
    error = None
    form = UserForm(request.form)

    if request.method == 'POST':
        if form.validate():
            username = form.username.data
            password = form.password.data
            if username and check_username_password(username, password):
                login(username)
                return redirect('/')

        error = ('Incorrect password.')

    return render_response('auth_login.jinja', error=error,
                           auth_form=form)
コード例 #9
0
ファイル: views.py プロジェクト: fugu13/opp-frontpage
def render_profile(request, template_name, redirect_url):
    if request.method == "POST":
        form = forms.ProfileForm(request.form)
        if form.validate():
            provided = False
            if form.full_name.data:
                local.account.full_name = form.full_name.data
                provided = True
            if form.alternate_email.data:
                local.account.alternate_email = form.alternate_email.data
                provided = True
            if provided:
                local.account.put()
                flash("Your profile information has been saved.")
            return redirect(redirect_url)
    else:
        form = forms.ProfileForm(obj=local.account)
    return render_response(template_name, form=form)
コード例 #10
0
ファイル: __init__.py プロジェクト: fugu13/opp-frontpage
def view_logout(request):
    """Just logout and redirect to the login screen."""
    logout()
    return redirect(url_for('auth/login'))
コード例 #11
0
ファイル: __init__.py プロジェクト: fugu13/opp-frontpage
 def wrapped(*args, **kw):
     if get_app().conf['auth/token_key'] in get_session():
         return f(*args, **kw)
     else:
         return redirect(url_for('auth/login'))
コード例 #12
0
ファイル: gae.py プロジェクト: fugu13/opp-frontpage
def redirect_gae_login_url():
    req = get_request()
    return redirect(users.create_login_url(req.url))
コード例 #13
0
ファイル: views.py プロジェクト: fugu13/opp-frontpage
def preview(request, submission_id):
    submission = models.Submission.get_by_id(submission_id)
    if submission is None or submission.account.key().id() != local.account.key().id():
        logging.warning('Attempt to retrieve submission "%s" by account "%s" with email "%s".' % (submission_id, local.account.key().id(), local.account.email))
        return redirect(url_for('main/index'))
    return render_response("preview.html", submission=submission)