Exemplo n.º 1
0
def RFI_Resp(id, rfi_number):
    form = ResponseForm()
    rfi = Rfi.query.filter_by(project_id=int(id),
                              rfi_number=rfi_number).first_or_404()
    project = Project.query.filter_by(id=id).first_or_404()
    if form.validate_on_submit():
        rfi.date_response = form.date_response.data
        rfi.response = form.response.data
        rfi.reviewer = form.reviewer.data
        fname = 'State Response RFI ' + str(
            rfi.rfi_number) + ' - ' + rfi.title + '.pdf'
        rfi.response_fname = fname
        db.session.commit()

        create_pdf(rfi, project)

        return redirect(url_for('rfilog', id=project.id))
    elif request.method == 'GET':
        form.date_response.data = rfi.date_response
        form.response.data = rfi.response
        form.reviewer.data = rfi.reviewer
    return render_template('RFI_Resp.html',
                           rfi=rfi,
                           form=form,
                           project=project)
Exemplo n.º 2
0
def response():
    formResponse = ResponseForm()

    if formResponse.validate_on_submit():
        key = str(uuid.uuid4())
        uuid_list.append(key)
        data = {
            'sender_company': formResponse.sender_company.data,
            'sender_name': formResponse.sender_name.data,
            'sender_email': formResponse.sender_email.data,
            'sender_phone': formResponse.sender_phone.data,
            'response': formResponse.response.data,
            'sender_function': formResponse.sender_function.data
        }
        message_list[key] = data

        thread = Thread(target=send_verification_email,
                        args=(current_app._get_current_object(),
                              formResponse.sender_email.data, key))
        thread.setDaemon(True)
        thread.start()

        flash('Письмо с подтверждением выслано вам на почту',
              category='confirmation')
        return redirect(url_for('main.index'))

    return render_template('response.html', formResponse=formResponse)
Exemplo n.º 3
0
def users(username, session_id):
    # Temporary user. We can change this dynamically.
    user = User.query.filter_by(name=username).first_or_404()
    session = Session.query.filter_by(session_id=session_id).first_or_404()
    poll = session.poll

    header = "User: "******" -- Session: " + session.session_id
    form = ResponseForm()

    # When someone's submitted a response.
    if form.validate_on_submit():
        flag = False

        if form.a.data:
            poll.a_num += 1
            flag = True

        if form.b.data:
            poll.b_num += 1
            flag = True

        if form.c.data:
            poll.c_num += 1
            flag = True

        if form.d.data:
            poll.d_num += 1
            flag = True

        if flag:
            db.session.commit()
            flash("Response logged. Thanks!")
            return redirect('/home')
        else:
            flash("Please select atleast one response!")

    # Pull the poll from the DB object.
    question = poll.question

    answers = [poll.a, poll.b, poll.c, poll.d]

    # This function is cool. Research it.
    return render_template('response.html',
                           title='user',
                           header=header,
                           question=question,
                           answers=answers,
                           form=form)
Exemplo n.º 4
0
def create_response():
    """
    Creates a response.
    """
    form = ResponseForm()
    print(request.get_json())
    # Get the csrf_token from the request cookie and put it into the
    # form manually to validate_on_submit can be used
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        response = Response(node_id=form.data['node_id'],
                            politic_id=form.data['politic_id'],
                            answer=form.data['answer'])
        db.session.add(response)
        db.session.commit()
        return response.to_dict()
    return 'invalid form'
Exemplo n.º 5
0
def comment():
    response = request.args.get('response')
    if response:
        form = ResponseForm()
    else:
        response = 0
        form = CommentForm()
    if form.validate_on_submit():
        comment = Posts(content=form.content.data,
                        uid=current_user.id,
                        rid=session['post_id'],
                        rrid=response)
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('main.comment'))
    post_id = request.args.get('post_id')
    if post_id:
        session['post_id'] = post_id
    else:
        post_id = session['post_id']
    post = Posts.query.get(post_id)
    page = request.args.get('page', 1, type=int)
    pagination = Posts.query.filter_by(rid=post_id, rrid=0).order_by(
        Posts.timestamp.desc()).paginate(page, per_page=3, error_out=True)
    comment_list = pagination.items
    response_dict = {}
    for comment in comment_list:
        resp = Posts.query.filter_by(rrid=comment.id).order_by(
            Posts.timestamp.desc())
        response_dict[comment.id] = resp
    return render_template('main/post_comment.html',
                           comment_list=comment_list,
                           pagination=pagination,
                           post=post,
                           form=form,
                           response_dict=response_dict)
Exemplo n.º 6
0
def proj(id):
    form = ResponseForm()
    project = Project.query.filter_by(id=id).first_or_404()

    return render_template('proj.html', project=project)
Exemplo n.º 7
0
def index():
    form = PosterForm()
    formResponse = ResponseForm()
    formLike = LikeForm()
    posts = Poster.getPostersChecked()
    questions = {}
    for post in posts:
        questions[post.id] = QuestionOption.getOpcionPreguntaByPosterId(
            post.id)

    if formResponse.validate_on_submit():
        options = QuestionOption.getOpcionPreguntaByPosterId(
            formResponse.id.data)
        print("A CONTINUACION ID POSTER")
        print(formResponse.id.data)
        if formResponse.opcion1:
            if (current_user.is_authenticated):
                respuesta = UserResponse(id_usuario=current_user.id,
                                         id_poster=formResponse.id.data,
                                         opcion=options[0].opcion)
            else:
                respuesta = UserResponse(id_poster=formResponse.id.data,
                                         opcion=options[0].opcion)
            respuesta.addUserResponse()

        if formResponse.opcion2.data:
            if (current_user.is_authenticated):
                respuesta = UserResponse(id_usuario=current_user.id,
                                         id_poster=formResponse.id.data,
                                         opcion=options[1].opcion)
            else:
                respuesta = UserResponse(id_poster=formResponse.id.data,
                                         opcion=options[1].opcion)
            respuesta.addUserResponse()

        if formResponse.opcion3.data:
            if (current_user.is_authenticated):
                respuesta = UserResponse(id_usuario=current_user.id,
                                         id_poster=formResponse.id.data,
                                         opcion=options[2].opcion)
            else:
                respuesta = UserResponse(id_poster=formResponse.id.data,
                                         opcion=options[2].opcion)
            respuesta.addUserResponse()

        if formResponse.opcion4.data:
            if (current_user.is_authenticated):
                respuesta = UserResponse(id_usuario=current_user.id,
                                         id_poster=formResponse.id.data,
                                         opcion=options[3].opcion)
            else:
                respuesta = UserResponse(id_poster=formResponse.id.data,
                                         opcion=options[3].opcion)
            respuesta.addUserResponse()
        if (current_user.is_anonymous):
            return redirect(url_for('stat'))
        else:
            stat = Stat.getUsers(current_user.id)
            if (stat is not None):
                return redirect(url_for('index'))
            else:
                return redirect(url_for('stat'))

    if form.validate_on_submit():
        post = Poster(id_usuario=current_user.id,
                      titulo=form.titulo.data,
                      corregido=0,
                      imagen=form.imagen.data,
                      reto=form.reto.data,
                      info=form.info.data,
                      pregunta=form.pregunta.data)
        post.addPoster()
        resp1 = QuestionOption(id_poster=post.id, opcion=form.respuesta1.data)
        resp2 = QuestionOption(id_poster=post.id, opcion=form.respuesta2.data)
        resp3 = QuestionOption(id_poster=post.id, opcion=form.respuesta3.data)
        resp4 = QuestionOption(id_poster=post.id, opcion=form.respuesta4.data)
        resp1.addOpcionPregunta()
        resp2.addOpcionPregunta()
        resp3.addOpcionPregunta()
        resp4.addOpcionPregunta()
        flash(
            'Poster almacenado con éxito. Debes esperar a que un administrador lo corrija para que se pueda mostrar'
        )
        return redirect(url_for('index'))

    return render_template('index.html',
                           title='Home',
                           posts=posts,
                           form=form,
                           formResponse=formResponse,
                           questions=questions,
                           formLike=formLike)
Exemplo n.º 8
0
def response():
    # TODO create a responses table e.g. Accepted, Declined, with primary key
    event_id = request.args['event_id']
    logger.debug(f'Responding to event id {event_id}')
    focus_event = Event.query.filter_by(id=event_id)

    event_query = db.session.query(
        Event.id,
        EventEvents.name,
        Event.cycle_id,
        Event.notice_days,
        EventEvents.start_at,
        EventEvents.end_at
    ).join(
        EventEvents, Event.id == EventEvents.event_id
    ).filter(
        and_(EventEvents.is_active_update,
             Event.id == event_id)
    )

    focus_event_data = event_query.first()

    event_name = focus_event_data.name
    cycle_id = focus_event_data.cycle_id
    notice = focus_event_data.notice_days
    start_at = focus_event_data.start_at
    end_at = focus_event_data.end_at
    days = (end_at - start_at).total_seconds()/60/60/24

    form = ResponseForm()
    if form.validate_on_submit():
        if request.args.get('modify'):
            existing_response = ProposalResponse.query.filter_by(
                id=request.args.get('response_id'))
            existing_response.update(
                dict(is_active=False))

        response_descr = form.response.data
        new_response = ProposalResponse(description=response_descr, is_active=True,
                                        event_id=event_id,
                                        user_id=current_user.id)
        db.session.add(new_response)

        query = db.session.query(
            func.coalesce(func.count(ProposalResponse.id) + 1, 1).label(
                'expected_attendance')
        ).join(
            Event, ProposalResponse.event_id == Event.id
        ).filter(and_(Event.id == event_id, ProposalResponse.is_active,
                      ProposalResponse.description == 'Accepted')
                 )

        logger.debug(f"expected attendees query: {query}")
        expected_attendance = query.first().expected_attendance
        attendance_mult = attendance_score(cycle_id, expected_attendance)
        focus_event.update(
            dict(attendee_cnt=expected_attendance,
                 attendee_mult=attendance_mult,
                 points_pp=calculate_points(cycle_id, notice, expected_attendance, days)))
        db.session.commit()
        flash(f"You've responded to the {event_name}")
        return redirect(url_for('index'))
    return render_template('response.html', title='Respond to an event proposal',
                           event=focus_event, form=form)
Exemplo n.º 9
0
def response():
    form = ResponseForm()