Beispiel #1
0
    def parse(filename):
        with open(filename) as csv_file:
            csv_reader = csv.DictReader(csv_file)
            line_count = 0
            for row in csv_reader:
                is_ques_duplicate = len(
                    Question.query.filter(
                        func.lower(Question.question) ==
                        row['question'].lower()).all()) > 0

                if is_ques_duplicate:
                    raise BadRequest("Question %s already exists" %
                                     row['question'])

                question = Question(question=row['question'],
                                    author=row['question_author_name'])

                if 'question_date' in row and row['question_date'] != '':
                    question.created_on = row['question_date']

                db.session.add(question)
                db.session.commit()

                if row['answer'] != '':
                    answer = Answer(text=row['answer'],
                                    question_id=question.id,
                                    author=row['answer_author_name'])
                    if 'answer_date' in row and row['answer_date'] != '':
                        answer.created_on = row['answer_date']
                    db.session.add(answer)
                    db.session.commit()

                if row['tags'] != '':
                    for tag_text in row['tags'].split(","):
                        tag = Tag.query.filter(Tag.name.ilike(
                            tag_text.lower())).first()
                        if not tag:
                            tag = Tag(name=tag_text)
                            db.session.add(tag)
                            db.session.commit()

                        tag_map = TagQuestionMap(tag_id=tag.id,
                                                 question_id=question.id)
                        db.session.add(tag_map)
                        db.session.commit()
Beispiel #2
0
def ask():
    if request.method == 'POST':
        question = request.form['question']

        question = Question(question=question, author=current_user.name)

        db.session.add(question)
        db.session.commit()

        return redirect(url_for('main.index'))

    return render_template('ask.html')
Beispiel #3
0
def ask():
    if request.method == 'POST':
        question = request.form['question']
        expert = request.form['expert']

        question = Question(question=question,
                            expert_id=expert,
                            asked_by_id=current_user.id)
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('main.index'))
    experts = User.query.filter_by(expert=True).all()
    context = {'experts': experts}
    return render_template('ask.html', **context)
Beispiel #4
0
def new_question():
    '''
        View for new question
    '''
    form = QuestionForm()
    if form.validate_on_submit():
        question = Question(title=form.title.data,
                            content=form.content.data,
                            asker=current_user)
        db.session.add(question)
        db.session.commit()
        flash('Your question has been created!', 'success')
        return redirect(url_for('question', question_id=question.id))
    return render_template('create_ques.html',
                           title='New Question',
                           form=form,
                           legend='New Question')
def ask(role):
    if request.method == 'POST':
        question = request.form['question']

        question = Question(question=question,
                            score=0,
                            asked_by_id=0,
                            hint='',
                            hint_requested=False)

        db.session.add(question)
        db.session.commit()

        questions = Question.query.filter(Question.answer != None).all()

        context = {'questions': questions}
        return render_template('home.html', role=role, **context)
    else:
        # GET part
        experts = User.query.filter_by(expert=True).all()

        context = {'experts': experts}
        return render_template('ask.html', role=role, **context)