Exemple #1
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.forms.front.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('front.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(
            'beacon/front/detail.html', opportunity=opportunity,
            current_user=current_user, signup_form=signup_form,
        )
    abort(404)
Exemple #2
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.forms.front.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('front.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(
        'beacon/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')
    )
Exemple #3
0
 def post_validate_action(self, opportunity):
     signup_success = signup_for_opp(self, opportunity)
     if signup_success:
         flash(Markup("Successfully subscribed for updates! <a href=" + url_for('front.signup') + ">Sign up</a> for alerts about future opportunities."), 'alert-success')
         return redirect(url_for('front.detail', opportunity_id=opportunity.id))