Ejemplo n.º 1
0
def load_pieces():
    """Load pieces from piece.txt into database."""

    print "Pieces"

    for i, row in enumerate(open("data/piece.txt")):
        row = row.rstrip()

        title, pg_id, comp, lyr, pub_yr, onv, ov, lang, oi, to, te, d = row.split(
            ", ")

        piece = Piece(title=title,
                      page_id=pg_id,
                      composer=comp,
                      lyricist=lyr,
                      publication_year=pub_yr,
                      original_num_voices=onv,
                      original_voicing=ov,
                      original_language=lang,
                      original_instrumentation=oi,
                      text_original=to,
                      text_english=te,
                      description=d)

        # Add to the session.
        db.session.add(piece)

    # Commit the session/data to the dbase.
    db.session.commit()
Ejemplo n.º 2
0
def lesson(lesson_id, section_id):
    user_db = auth.current_user_db()
    if user_db.progress < lesson_id:
        return redirect(url_for('lesson', lesson_id=user_db.progress, section_id=1))
    if lesson_id > 0 and not user_db.registered:
        flash(u'Please register with your email below to access additional Lessons.')
        return redirect(url_for('welcome'))
    if request.method == 'POST':
        if answers.check(request.form, lesson_id):
            user_db.progress = lesson_id + 1
            try:
                user_db.put()
                flash(u'Congratulations! Welcome to Lesson %s.' % user_db.progress, 'success')
                return redirect(url_for('lesson', lesson_id=user_db.progress, section_id=1))
            except:
                flash(u'Something went wrong.', 'info')
                return redirect(url_for('lesson', lesson_id=lesson_id,section_id=section_id))
    lesson_db = Lesson.query(Lesson.number == lesson_id).get()
    section_dbs = Section.query(Section.lesson == lesson_id).order(Section.number)
    piece_dbs = Piece.query(Piece.lesson == lesson_id, Piece.section == section_id).order(Piece.number)
    graph_string = 'graphs/graph_' + str(lesson_id) + '_' + str(section_id)
    return render_template(
        'lesson.html',
        html_class='lesson',
        lesson=lesson_db,
        sections=section_dbs,
        pieces=piece_dbs,
        graph=graph_string + '.html',
        graph_head=graph_string + '_head.html',
        lesson_id=lesson_id,
        section_id=section_id,
        progress=user_db.progress
    )
Ejemplo n.º 3
0
def piece_view():
    piece_dbs = Piece.query().order(Piece.lesson, Piece.section, Piece.number)
    return render_template(
        'piece_view.html',
        html_class='piece-view',
        title='Pieces',
        pieces=piece_dbs,
    )
Ejemplo n.º 4
0
def piece_delete(piece_id):
    piece_db = Piece.get_by_id(piece_id)
    try:
        piece_db.key.delete()
        flash(u'Piece id %s successfully deleted.' % piece_id, 'success')
        return redirect(url_for('piece_view'))
    except:
        flash(u'Something went wrong.', 'info')
        return redirect(url_for('piece_view'))
Ejemplo n.º 5
0
def post():
	if request.method == 'GET':
		return render_template('/post.html')
	else:
		pic_url=request.form.get('pic_url')
		description = request.form.get('description')
		piece=Piece(pic_url = pic_url, description = description)
		session.add(piece)
		session.commit()
		return redirect(url_for('my_feed'))
Ejemplo n.º 6
0
def create_piece():
    global active_piece
    type = choice(ALL_PIECES)
    active_piece = Piece("*", type, (4, 0), b)
    active_piece_sprites.clear()
    colour = choice(COLOURS)
    for p in active_piece:
        sprite = scene.layers[1].add_sprite("tile",
                                            pos=grid_to_screen(*p),
                                            color=colour,
                                            scale=0.75)
        active_piece_sprites.append(sprite)
Ejemplo n.º 7
0
	def setup(self, game):
		game.turn = 1
		game.phase = 1

		game.luftwaffe = 3

		game.vp = 0
		game.initiative = 0

		game.axis_armor_track = 0
		game.eliminated_panzer_units = 0
		game.axis_strategic_mode = 'tank-production'

		game.soviet_armor_track = 0
		game.soviet_industry_track = 0
		game.soviet_lend_lease_track = 0

		game.fortified = self.fortified

		# eventually I'll have a proper setup but I need to do some actual
		# game-code work for a change...so we'll just go with a hard-coded setup
		# for now
		#game.state = 'setup'
		game.state = 'playing'

		for ussr in self.ussr_line:
			p = Piece(game=game, side='ussr', type='line', y=ussr[0], x=ussr[1])
			p.put()

		for finn in self.finns:
			p = Piece(game=game, side='axis', type='finn', y=finn[0], x=finn[1])
			p.put()

		Piece(game=game, side='axis', type='panzer', y=6, x=5).put()
		Piece(game=game, side='axis', type='panzer', y=8, x=5).put()
		Piece(game=game, side='axis', type='panzer', y=9, x=5).put()

		Piece(game=game, side='axis', type='mountain', y=11, x=7).put()

		Piece(game=game, side='axis', type='rumanian', y=11, x=6).put()
		Piece(game=game, side='axis', type='rumanian', y=12, x=8).put()

		for german in itertools.chain(self.greater_germany_setup, [[11, 5]]):
			p = Piece(game=game, side='axis', type='line', y=german[0], x=german[1])
			p.put()
Ejemplo n.º 8
0
def piece_create():
    form = PieceForm()
    if form.validate_on_submit():
        piece_db = Piece(
            lesson = form.lesson.data,
            section = form.section.data,
            tag = form.tag.data,
            number = form.number.data,
            content = form.content.data,
        )
        try:
            piece_db.put()
            flash(u'Piece id %s successfully saved.' % piece_db.key.id(), 'success')
            return redirect(url_for('piece_view'))
        except:
            flash(u'Something went wrong.', 'info')
            return redirect(url_for('piece_update'))
    return render_template(
        'piece_update.html',
        html_class='piece-create',
        title='Create Piece',
        form=form)
Ejemplo n.º 9
0
def process_form():

    # gets data from piece form
    user_id = current_user.user_id
    clothing_type = request.form.get("clothing_type")
    img_url = request.form.get("img_url")
    categories = request.form.getlist("category")
    c_id = request.form.get("c_id")
    desc = request.form.get("desc")
    other_desc = request.form.get("other_desc")
    cost = request.form.get("cost")

    if other_desc:
        desc = other_desc

    new_piece = Piece(times_worn=0,
                      desc=desc,
                      clothing_type=clothing_type,
                      user_id=user_id,
                      img_url=img_url,
                      cost=cost,
                      cost_per_use=cost)

    db.session.add(new_piece)
    db.session.commit()

    for item in categories:
        check_category = Category.query.filter(Category.category == item)
        check_category = check_category.first()

        # creates new category in categories table
        if not check_category:
            check_category = Category(category=item)
            db.session.add(check_category)
            db.session.commit()

        new_category_piece = CategoryPiece(piece_id=new_piece.piece_id,
                                           cat_id=check_category.cat_id)
        db.session.add(new_category_piece)
        db.session.commit()

    print("\nPOST REQUEST IS HAPPENING\n")

    return c_id
Ejemplo n.º 10
0
def piece_update(piece_id):
    piece_db = Piece.get_by_id(piece_id)
    form = PieceForm(obj=piece_db)
    if form.validate_on_submit():
        form.populate_obj(piece_db)
        try:
            piece_db.put()
            flash(u'Piece id %s successfully saved.' % piece_db.key.id(), 'success')
            return redirect(url_for('piece_view'))
        except:
            flash(u'Something went wrong.', 'info')
            return redirect(url_for('piece_view'))
    return render_template(
        'piece_update.html',
        html_class='piece-update',
        title='Edit Piece',
        form=form,
        piece_db=piece_db
    )
Ejemplo n.º 11
0
def add_piece(ttl, pg_id, comp, lrc, pb_yr, onv, ov, ol, oi, to, te, desc):
    """Adds piece to the database."""

    piece = Piece(title=ttl,
                  page_id=pg_id,
                  composer=comp,
                  lyricist=lrc,
                  publication_year=pb_yr,
                  original_num_voices=onv,
                  original_voicing=ov,
                  original_language=ol,
                  original_instrumentation=oi,
                  text_original=to,
                  text_english=te,
                  description=desc)

    # Add to the session.
    db.session.add(piece)

    # Commit the session/data to the dbase.
    db.session.commit()

    return piece.piece_id
Ejemplo n.º 12
0
from model import Base, User, Piece
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///project.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
new_user = User(username = "******", p)

new_piece = Piece(title="Test Title", description="Test Description", pic_url="http://www.louvre.fr/sites/default/files/imagecache/940x768/medias/medias_images/images/louvre-portrait-de-lisa-gherardini-epouse-de-francesco-del-giocondo-dite-monna-lisa-la-gioconda-ou-la-jocon.jpg")
Ejemplo n.º 13
0
def process_piece(row):
    """Load pieces from webpage into database."""

    data = row.find_all('td')

    title = data[1].string
    composer_name = data[2].string
    composer_id = db.session.query(
        Composer.composer_id).filter(Composer.name == composer_name).one()[0]

    period_str = data[3].encode('utf8').lstrip('<td>').rstrip(
        '</td>').strip().lower()
    if len(period_str) > 2:
        period = period_str[0].upper() + period_str[1:]
    else:
        period = None

    level = None
    key = None
    tonality = None

    if data[4].string == 'Prep':
        level = 0
    elif data[4].string != None:
        level = int(str(data[4].string))

    if ' in ' in title:
        split = title.split(' ')
        string = split[split.index('in') + 1].rstrip(',.:)"')
        lowerstring = string.lower()

        try:
            string_next = split[split.index('in') + 2].rstrip(',.:)"')
        except Exception as e:
            string_next = ''

        if 'C sharp' in title or 'C-sharp' in title:
            key = "c#"
        elif 'F sharp minor' in title:
            key = "f#"
        elif "B flat Minor" in title:
            key = "bb"
        elif string_next.lower() == 'minor' or string_next.lower() == 'min':
            key = lowerstring
        elif string_next.lower() == 'sharp':
            key = string + '#'
        elif string_next.lower() == 'flat':
            key = string + 'b'
        elif len(string) == 1 and string != ' ':
            key = string
        elif len(string) == 2 and (string[1] == '#' or string[1] == 'b'):
            key = string
        elif len(string) > 2:
            if string[1] == ',':
                key = string[0]
            elif 'sharp' in string:
                key = string[0] + '#'
            elif 'flat' in string:
                key = string[0] + 'b'
        else:
            key = None
    else:
        key = None

    if key != None:
        if key[0].isupper():
            tonality = 'Major'
        else:
            tonality = 'Minor'

    piece = Piece(title=title,
                  composer_id=composer_id,
                  period=period,
                  level=level,
                  key=key,
                  tonality=tonality)

    return piece