def render(self, deck_ids):
        db = Datasource().get_db()
        decks_sql = 'SELECT * FROM deck WHERE d_id in (%s)' % ','.join(
            '?' * len(deck_ids))
        decks = select(db, decks_sql, deck_ids)

        return render_template('deck-browser/index.html',
                               decks=decks,
                               page_title='Favourite Decks')
Beispiel #2
0
    def render(self, deckid):
        db = Datasource().get_db()
        deck_result = select(db, 'SELECT * FROM deck WHERE d_id = ?', [deckid])
        card_results = select(db, 'SELECT * FROM card WHERE c_d_id = ?',
                              [deckid])
        if len(deck_result) == 0 or len(card_results) == 0:
            return '401 bad request'

        deck = deck_result[0]
        cards = json.dumps(card_results)

        return render_template('deck-viewer/index.html',
                               deck=deck,
                               cards=cards)
def create_deck(deck):
    db = Datasource().get_db()
    deck_insert_sql = '''
    INSERT INTO deck
    (d_title, d_desc, d_author, d_dt_created)
    VALUES(?, ?, ?, datetime('now'));
  '''
    deck_id = insert(db, deck_insert_sql,
                     [deck['title'], deck['description'], deck['author']])
    print(deck_id)
    card_insert_sql = '''
    INSERT INTO card
    (c_d_id, c_question, c_answer, c_dt_created)
    VALUES(?, ?, ?, datetime('now'));
  '''
    questions = deck['questions']
    for question in questions:
        insert(db, card_insert_sql,
               [deck_id, question['question'], question['answer']])

    return {'deck_id': deck_id}, 200
Beispiel #4
0
import json
from flask import Flask, request
from flaskr.views.home import HomeView
from flaskr.views.viewdeck import ViewDeckView
from flaskr.views.createdeck import CreateDeckView
from flaskr.views.mydecks import MyDecksView
from flaskr.views.favouritedecks import FavouriteDecksView
from flaskr.data.datasource import Datasource
from flaskr.handlers.deckhandler import create_deck

app = Flask(__name__)

with app.app_context():
    datasource = Datasource()
    datasource.get_db()
    datasource.init_db()

##                   ##
## ROUTE DEFINITIONS ##
##                   ##


@app.route('/')
def home():
    home_view = HomeView()

    return home_view.render()


@app.route('/deck/create', methods=['GET', 'POST'])
def handle_create_deck():
Beispiel #5
0
  def render(self):
    db = Datasource().get_db()
    decks = select(db, 'SELECT * FROM deck')


    return render_template('deck-browser/index.html', decks=decks, page_title='Decks')
    def render(self):
        db = Datasource().get_db()

        return render_template('deck-creator/index.html')