Beispiel #1
0
def new_issue():
    '''Main view where people come to report issues.'''
    form = IssueForm(request.form)
    # add browser and version to form object data
    form.browser.data = get_browser_name(request.headers.get('User-Agent'))
    form.version.data = get_browser_version(request.headers.get('User-Agent'))
    # GET means you want to file a report.
    if request.method == 'GET':
        return render_template('index.html', form=form)
    # Form submission.
    elif request.method == 'POST' and form.validate():
        if request.form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(request.form)
                return redirect(url_for('thanks',
                                number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = request.form
                return redirect(url_for('login'))
        elif request.form.get('submit-type') == PROXY_REPORT:
            # `response` here is a Requests Response object, because
            # the proxy_report_issue crafts a manual request with Requests
            response = proxy_report_issue(request.form)
            return redirect(url_for('thanks',
                            number=response.json().get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=form)
Beispiel #2
0
def index():
    '''Main view where people come to report issues.'''
    bug_form = IssueForm(request.form)
    # add browser and version to bug_form object data
    ua_header = request.headers.get('User-Agent')
    bug_form.browser.data = get_browser(ua_header)
    bug_form.os.data = get_os(ua_header)
    browser_name = get_browser_name(ua_header)
    # GET means you want to file a report.
    if request.method == 'GET':
        if g.user:
            get_user_info()
        return render_template('index.html', form=bug_form,
                               browser=browser_name)
    # Form submission.
    elif request.method == 'POST' and bug_form.validate():
        # copy the form so we can add the full UA string to it.
        form = request.form.copy()
        form['ua_header'] = ua_header
        if form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(form)
                return redirect(url_for('thanks',
                                number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = form
                return redirect(url_for('login'))
        elif form.get('submit-type') == PROXY_REPORT:
            response = report_issue(form, proxy=True).json()
            return redirect(url_for('thanks', number=response.get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=bug_form)
Beispiel #3
0
def new_issue():
    '''Main view where people come to report issues.'''
    form = IssueForm(request.form)
    # add browser and version to form object data
    form.browser.data = get_browser_name(request.headers.get('User-Agent'))
    form.version.data = get_browser_version(request.headers.get('User-Agent'))
    # GET means you want to file a report.
    if request.method == 'GET':
        return render_template('index.html', form=form)
    # Form submission.
    elif request.method == 'POST' and form.validate():
        if request.form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(request.form)
                return redirect(
                    url_for('thanks', number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = request.form
                return redirect(url_for('login'))
        elif request.form.get('submit-type') == PROXY_REPORT:
            # `response` here is a Requests Response object, because
            # the proxy_report_issue crafts a manual request with Requests
            response = proxy_report_issue(request.form)
            return redirect(
                url_for('thanks', number=response.json().get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=form)
Beispiel #4
0
def index():
    '''Main view where people come to report issues.'''
    bug_form = IssueForm(request.form)
    # add browser and version to bug_form object data
    ua_header = request.headers.get('User-Agent')
    bug_form.browser.data = get_browser(ua_header)
    bug_form.os.data = get_os(ua_header)
    browser_name = get_browser_name(ua_header)
    # GET means you want to file a report.
    if request.method == 'GET':
        if g.user:
            get_user_info()
        return render_template('index.html',
                               form=bug_form,
                               browser=browser_name)
    # Form submission.
    elif request.method == 'POST' and bug_form.validate():
        # copy the form so we can add the full UA string to it.
        form = request.form.copy()
        form['ua_header'] = ua_header
        if form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(form)
                return redirect(
                    url_for('thanks', number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = form
                return redirect(url_for('login'))
        elif form.get('submit-type') == PROXY_REPORT:
            response = report_issue(form, proxy=True).json()
            return redirect(url_for('thanks', number=response.get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=bug_form)
Beispiel #5
0
def issues():
    form = IssueForm()
    user = get_user()
    include_private = False
    if not user:
        return redirect(url_for("index"))
    if form.validate_on_submit():
        issue = market.add_issue(user, form.url.data)
        verb = "updated"
        if issue.new:
            verb = "added"
        flash("%s %s" % (issue.displayname, verb))
        return redirect(url_for("issue"))
    if user.banker:
        include_private = True
    project = request.args.get("project")
    issues = market.get_issues(include_private, project)
    if project:
        issueheader = "Issues for project %s" % project
    else:
        issueheader = "All issues in the market"

    for issue in issues:
        issue.action_button = offer_button(issue)
    return render_template(
        "issues.html",
        issueheader=issueheader,
        user=user,
        form=form,
        issues=issues,
        title="Issues",
    )
def get_form(ua_header):
    """Return an instance of flask_wtf.Form with browser and os info added"""
    bug_form = IssueForm()
    # add browser and version to bug_form object data
    bug_form.browser.data = get_browser(ua_header)
    bug_form.os.data = get_os(ua_header)
    return bug_form
Beispiel #7
0
def index():
    '''Main view where people come to report issues.'''
    bug_form = IssueForm()
    # add browser and version to bug_form object data
    ua_header = request.headers.get('User-Agent')
    bug_form.browser.data = get_browser(ua_header)
    bug_form.os.data = get_os(ua_header)
    browser_name = get_browser_name(ua_header)
    # GET means you want to file a report.
    if request.method == 'GET':
        if g.user:
            get_user_info()
        return render_template('index.html', form=bug_form,
                               browser=browser_name)
    # Validate, then create issue.
    elif bug_form.validate_on_submit():
        return create_issue()

    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=bug_form)
Beispiel #8
0
def index():
    '''Main view where people come to report issues.'''
    bug_form = IssueForm()
    # add browser and version to bug_form object data
    ua_header = request.headers.get('User-Agent')
    bug_form.browser.data = get_browser(ua_header)
    bug_form.os.data = get_os(ua_header)
    browser_name = get_browser_name(ua_header)
    # GET means you want to file a report.
    if request.method == 'GET':
        if g.user:
            get_user_info()
        return render_template('index.html',
                               form=bug_form,
                               browser=browser_name)
    # Validate, then create issue.
    elif bug_form.validate_on_submit():
        return create_issue()

    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=bug_form)
Beispiel #9
0
def issues():
    form = IssueForm()
    user = get_user()
    include_private = False
    if not user:
        return redirect(url_for('index'))
    if form.validate_on_submit():
        issue = market.add_issue(user, form.url.data)
        verb = "updated"
        if issue.new:
            verb = "added"
        flash("%s %s" % (issue.displayname, verb))
        return redirect(url_for('issue'))
    if user.banker:
        include_private = True
    issues = market.get_issues(include_private)
    for issue in issues:
        issue.action_button = offer_button(issue)
    return render_template('issues.html',
                           user=user,
                           form=form,
                           issues=issues,
                           title="Issues")
Beispiel #10
0
def index():
    '''Main view where people come to report issues.'''
    bug_form = IssueForm(request.form)
    # add browser and version to bug_form object data
    bug_form.browser.data = get_browser_name(request.headers.get('User-Agent'))
    bug_form.version.data = get_browser_version(
        request.headers.get('User-Agent'))
    # GET means you want to file a report.
    if request.method == 'GET':
        if g.user:
            try:
                user = User.query.get(session['user_id'])
                if user.avatar_url != '' and user.username != '':
                    session['username'] = user.username
                    session['avatar_url'] = user.avatar_url
                else:
                    gh_user = github.get('user')
                    user.username = gh_user.get('login')
                    user.avatar_url = gh_user.get('avatar_url')
                    db_session.commit()
                    session['username'] = user.username
                    session['avatar_url'] = user.avatar_url
            except ConnectionError, e:
                print e
            user_issues = get_user_issues(session['username'])
            contact_ready = get_contact_ready()
            needs_diagnosis = get_needs_diagnosis()
        else:
            user_issues = []
            contact_ready = proxy_get_contact_ready()
            needs_diagnosis = proxy_get_needs_diagnosis()
        return render_template('index.html',
                               form=bug_form,
                               user_issues=user_issues,
                               contact_ready=contact_ready,
                               needs_diagnosis=needs_diagnosis)