Exemple #1
0
    def test_delete_transform_deletes_association_record(self):
        transform = Transform.query.first()
        db_session.delete(transform)
        db_session.commit()

        self.assertEqual(db_session.query(BaseModel.metadata.tables["transform_destinations"]).count(), 0)
        self.assertEqual(Destination.query.count(), 1)
Exemple #2
0
    def test_delete_destination_removes_from_relation_collection(self):
        dest = Destination.query.first()
        db_session.delete(dest)
        db_session.commit()

        transform = Transform.query.first()
        self.assertEqual(len(transform.for_destinations), 0)

        self.assertEqual(db_session.query(BaseModel.metadata.tables["transform_destinations"]).count(), 0)
Exemple #3
0
    def test_delete_transform_deletes_association_record(self):
        transform = Transform.query.first()
        db_session.delete(transform)
        db_session.commit()

        self.assertEqual(
            db_session.query(
                BaseModel.metadata.tables["transform_destinations"]).count(),
            0)
        self.assertEqual(Destination.query.count(), 1)
Exemple #4
0
    def test_delete_destination_removes_from_relation_collection(self):
        dest = Destination.query.first()
        db_session.delete(dest)
        db_session.commit()

        transform = Transform.query.first()
        self.assertEqual(len(transform.for_destinations), 0)

        self.assertEqual(
            db_session.query(
                BaseModel.metadata.tables["transform_destinations"]).count(),
            0)
Exemple #5
0
def add_question():
    form = AddQuestionForm()
    if request.method == 'POST' and form.validate():
        user_id = g.user.id
        question = request.form['question']
        details = request.form['details']
        new_question = Questions(question=question, details=details,
                                 user_id=user_id)
        db_session.add(new_question)
        db_session.commit()
        flash('Your question successfully submitted!')
        return redirect(url_for('main_page'))
    return render_template('add_question.html', title='Add question', form=form)
Exemple #6
0
def generate_db():
    app.logger.info("Start make db")
    currentsession = get_user_session_by_userid()
    serviceprovider = [
        '3 River Wireless', 'ACS Wireless', 'Alltel', 'AT&T', 'Bell Canada',
        'Bell Canada', 'Bell Mobility (Canada)', 'Bell Mobility',
        'Blue Sky Frog', 'Bluegrass Cellular', 'Boost Mobile', 'BPL Mobile',
        'Carolina West Wireless', 'Cellular One', 'Cellular South',
        'Centennial Wireless', 'CenturyTel', 'Cingular (Now AT&T)', 'Clearnet',
        'Comcast', 'Corr Wireless Communications', 'Dobson', 'Edge Wireless',
        'Fido', 'Golden Telecom', 'Helio', 'Houston Cellular', 'Idea Cellular',
        'Illinois Valley Cellular', 'Inland Cellular Telephone', 'MCI',
        'Metrocall', 'Metrocall 2-way', 'Metro PCS', 'Microcell',
        'Midwest Wireless', 'Mobilcomm', 'MTS', 'Nextel', 'OnlineBeep',
        'PCS One', "President's Choice", 'Public Service Cellular', 'Qwest',
        'Rogers AT&T Wireless', 'Rogers Canada', 'Satellink',
        'Southwestern Bell', 'Sprint', 'Sumcom', 'Surewest Communicaitons',
        'T-Mobile', 'Telus', 'Tracfone', 'Triton', 'Unicel', 'US Cellular',
        'Solo Mobile', 'Sprint', 'Sumcom', 'Surewest Communicaitons',
        'T-Mobile', 'Telus', 'Triton', 'Unicel', 'US Cellular', 'US West',
        'Verizon', 'Virgin Mobile', 'Virgin Mobile Canada',
        'West Central Wireless', 'Western Wireless'
    ]
    db_session.close()
    drop_db()
    init_db()

    user = User('admin', '1')
    user.email = 'admin@localhost'
    user.mobilenumber = '800 000 0000'
    user.referfrom = 'admin'
    user.active = 1
    user.paidservice = 1
    user.create_date = datetime.datetime.now()
    user.modified_date = datetime.datetime.now()
    db_session.add(user)
    db_session.commit()

    sps = {}
    for row in serviceprovider:
        if row not in sps:
            sps[row] = 1
            sp = ServiceProvider()
            sp.name = row
            try:
                db_session.add(sp)
                db_session.commit()
            except:
                db_session.rollback()

    return output_json("status:ok", 200)
Exemple #7
0
def answer(question_id):
    form = AnswerForm()
    question = Questions.query.filter_by(id=question_id).first()
    if not question:
        flash('Looks like this question is not available')
        return redirect(url_for('main_page'))
    if request.method == 'POST' and form.validate():
        answer_text = request.form['answer']
        user = g.user.id
        answer = Answers(answer_text, user, question.id)
        db_session.add(answer)
        db_session.commit()
        flash('Your answer successfully submitted')
        return redirect(url_for('main_page'))
    return render_template('answers.html', title='Add answer',
                           question=question, form=form)
Exemple #8
0
def like(answer_id):
    user = g.user.id
    answer = Answers.query.filter_by(id=answer_id).first()
    if Like.query.filter_by(user=user, answer=answer_id).first():
        flash('Already voted')
        return redirect(url_for('main_page'))
    elif answer:
        vote = Like(answer=answer_id, user=user)
        db_session.add(vote)
        answer.likes += 1
        db_session.commit()
        flash("You'r vote successfully submitted")
        return redirect(url_for("main_page"))
    else:
        flash('This answer not available for voting')
        return redirect(url_for('main_page'))
Exemple #9
0
def add_question():
    form = AddQuestionForm()
    if request.method == 'POST' and form.validate():
        user_id = g.user.id
        question = request.form['question']
        details = request.form['details']
        new_question = Questions(question=question,
                                 details=details,
                                 user_id=user_id)
        db_session.add(new_question)
        db_session.commit()
        flash('Your question successfully submitted!')
        return redirect(url_for('main_page'))
    return render_template('add_question.html',
                           title='Add question',
                           form=form)
Exemple #10
0
def like(answer_id):
    user = g.user.id
    answer = Answers.query.filter_by(id=answer_id).first()
    if Like.query.filter_by(user=user, answer=answer_id).first():
        flash('Already voted')
        return redirect(url_for('main_page'))
    elif answer:
        vote = Like(answer=answer_id, user=user)
        db_session.add(vote)
        answer.likes += 1
        db_session.commit()
        flash("You'r vote successfully submitted")
        return redirect(url_for("main_page"))
    else:
        flash('This answer not available for voting')
        return redirect(url_for('main_page'))
Exemple #11
0
def answer(question_id):
    form = AnswerForm()
    question = Questions.query.filter_by(id=question_id).first()
    if not question:
        flash('Looks like this question is not available')
        return redirect(url_for('main_page'))
    if request.method == 'POST' and form.validate():
        answer_text = request.form['answer']
        user = g.user.id
        answer = Answers(answer_text, user, question.id)
        db_session.add(answer)
        db_session.commit()
        flash('Your answer successfully submitted')
        return redirect(url_for('main_page'))
    return render_template('answers.html',
                           title='Add answer',
                           question=question,
                           form=form)
Exemple #12
0
def register():
    form = LoginForm()
    if g.user.is_authenticated():
        return redirect(url_for('main_page'))

    if request.method == 'POST' and form.validate():
        name = request.form['name']
        password = request.form['password']
        if not User.query.filter_by(name=name).first():
            user = User(name, password)
            db_session.add(user)
            db_session.commit()
            flash("You have successfully registered. Now you can log in.")
            return redirect(url_for('login'))
        else:
            flash('This name already used. Please try again.')
            return render_template('login_form.html',
                                   form=form,
                                   title='Sign up')
    return render_template('login_form.html', form=form, title='Sign up')
Exemple #13
0
def register():
    form = LoginForm()
    if g.user.is_authenticated():
        return redirect(url_for('main_page'))

    if request.method == 'POST' and form.validate():
        name = request.form['name']
        password = request.form['password']
        if not User.query.filter_by(name=name).first():
            user = User(name, password)
            db_session.add(user)
            db_session.commit()
            flash("You have successfully registered. Now you can log in.")
            return redirect(url_for('login'))
        else:
            flash('This name already used. Please try again.')
            return render_template('login_form.html',
                                   form=form,
                                   title='Sign up')
    return render_template('login_form.html', form=form, title='Sign up')
Exemple #14
0
 def addToDatabase(self, *args):
     for obj in args:
         db_session.add(obj)
     db_session.commit()
Exemple #15
0
 def addToDatabase(self, *args):
     for obj in args:
         db_session.add(obj)
     db_session.commit()