def detail(opportunity_id):
    '''View one opportunity in detail

    :status 200: Render the opportunity's detail template
    :status 302: Signup for this particular opportunity via the
        :py:class:`~purchasing.opportunities.forms.OpportunitySignupForm`
    '''
    opportunity = Opportunity.query.get(opportunity_id)
    if opportunity and opportunity.can_view(current_user):
        signup_form = init_form(OpportunitySignupForm)
        if signup_form.validate_on_submit():
            signup_success = signup_for_opp(signup_form, opportunity)
            if signup_success:
                flash('Successfully subscribed for updates!', 'alert-success')
                return redirect(url_for('opportunities.detail', opportunity_id=opportunity.id))

        current_app.logger.info(u'BEACON FRONT OPPORTUNITY DETAIL VIEW | Opportunity {} (ID: {})'.format(
            opportunity.title, opportunity.id
        ))

        return render_template(
            'opportunities/front/detail.html', opportunity=opportunity,
            current_user=current_user, signup_form=signup_form,
        )
    abort(404)
def detail(opportunity_id):
    """View one opportunity in detail
    """
    opportunity = Opportunity.query.get(opportunity_id)
    if opportunity and opportunity.can_view(current_user):
        signup_form = init_form(OpportunitySignupForm)
        if signup_form.validate_on_submit():
            signup_success = signup_for_opp(signup_form, opportunity)
            if signup_success:
                flash("Successfully subscribed for updates!", "alert-success")
                return redirect(url_for("opportunities.detail", opportunity_id=opportunity.id))

        current_app.logger.info(
            "BEACON FRONT OPPORTUNITY DETAIL VIEW | Opportunity {} (ID: {})".format(
                opportunity.title.encode("ascii", "ignore"), opportunity.id
            )
        )

        return render_template(
            "opportunities/front/detail.html",
            opportunity=opportunity,
            current_user=current_user,
            signup_form=signup_form,
        )
    abort(404)
def browse():
    """Browse available opportunities
    """
    _open, upcoming = [], []

    signup_form = init_form(OpportunitySignupForm)
    if signup_form.validate_on_submit():
        opportunities = request.form.getlist("opportunity")
        if signup_for_opp(signup_form, opportunity=opportunities, multi=True):
            flash("Successfully subscribed for updates!", "alert-success")
            return redirect(url_for("opportunities.browse"))

    opportunities = Opportunity.query.filter(Opportunity.planned_submission_end >= datetime.date.today()).all()

    for opportunity in opportunities:
        if opportunity.is_submission_start:
            _open.append(opportunity)
        elif opportunity.is_upcoming:
            upcoming.append(opportunity)

    current_app.logger.info("BEACON FRONT OPEN OPPORTUNITY VIEW")
    return render_template(
        "opportunities/browse.html",
        opportunities=opportunities,
        current_user=current_user,
        signup_form=signup_form,
        _open=sorted(_open, key=lambda i: i.planned_submission_end),
        upcoming=sorted(upcoming, key=lambda i: i.planned_submission_start),
        session_vendor=session.get("email"),
    )
Example #4
0
def detail(opportunity_id):
    '''View one opportunity in detail

    :status 200: Render the opportunity's detail template
    :status 302: Signup for this particular opportunity via the
        :py:class:`~purchasing.opportunities.forms.OpportunitySignupForm`
    '''
    opportunity = Opportunity.query.get(opportunity_id)
    if opportunity and opportunity.can_view(current_user):
        signup_form = init_form(OpportunitySignupForm)
        if signup_form.validate_on_submit():
            signup_success = signup_for_opp(signup_form, opportunity)
            if signup_success:
                flash('Successfully subscribed for updates!', 'alert-success')
                return redirect(
                    url_for('opportunities.detail',
                            opportunity_id=opportunity.id))

        current_app.logger.info(
            u'BEACON FRONT OPPORTUNITY DETAIL VIEW | Opportunity {} (ID: {})'.
            format(opportunity.title, opportunity.id))

        return render_template(
            'opportunities/front/detail.html',
            opportunity=opportunity,
            current_user=current_user,
            signup_form=signup_form,
        )
    abort(404)
Example #5
0
def browse():
    '''Browse available opportunities

    :status 200: render the browse template page
    :status 302: subscribe to one or multiple opportunities via
        the :py:class:`~purchasing.opportunities.forms.OpportunitySignupForm`
    '''
    _open, upcoming = [], []

    signup_form = init_form(OpportunitySignupForm)
    if signup_form.validate_on_submit():
        opportunities = request.form.getlist('opportunity')
        if signup_for_opp(signup_form, opportunity=opportunities, multi=True):
            flash('Successfully subscribed for updates!', 'alert-success')
            return redirect(url_for('opportunities.browse'))

    opportunities = Opportunity.query.filter(
        Opportunity.planned_submission_end >= datetime.date.today()).all()

    for opportunity in opportunities:
        if opportunity.is_submission_start:
            _open.append(opportunity)
        elif opportunity.is_upcoming:
            upcoming.append(opportunity)

    current_app.logger.info('BEACON FRONT OPEN OPPORTUNITY VIEW')
    return render_template(
        'opportunities/browse.html',
        opportunities=opportunities,
        current_user=current_user,
        signup_form=signup_form,
        _open=sorted(_open, key=lambda i: i.planned_submission_end),
        upcoming=sorted(upcoming, key=lambda i: i.planned_submission_start),
        session_vendor=session.get('email'))
def browse():
    '''Browse available opportunities

    :status 200: render the browse template page
    :status 302: subscribe to one or multiple opportunities via
        the :py:class:`~purchasing.opportunities.forms.OpportunitySignupForm`
    '''
    _open, upcoming = [], []

    signup_form = init_form(OpportunitySignupForm)
    if signup_form.validate_on_submit():
        opportunities = request.form.getlist('opportunity')
        if signup_for_opp(
            signup_form, opportunity=opportunities, multi=True
        ):
            flash('Successfully subscribed for updates!', 'alert-success')
            return redirect(url_for('opportunities.browse'))

    opportunities = Opportunity.query.filter(
        Opportunity.planned_submission_end >= datetime.date.today()
    ).all()

    for opportunity in opportunities:
        if opportunity.is_submission_start:
            _open.append(opportunity)
        elif opportunity.is_upcoming:
            upcoming.append(opportunity)

    current_app.logger.info('BEACON FRONT OPEN OPPORTUNITY VIEW')
    return render_template(
        'opportunities/browse.html', opportunities=opportunities,
        current_user=current_user, signup_form=signup_form,
        _open=sorted(_open, key=lambda i: i.planned_submission_end),
        upcoming=sorted(upcoming, key=lambda i: i.planned_submission_start),
        session_vendor=session.get('email')
    )