Ejemplo n.º 1
0
def add_sample_tracks():
    db.session.add(
        Track(u'The Divine Conspiracy', u'Epica', u'The Divine Conspiracy',
              u'Avalon'))
    db.session.add(
        Track(u'Second Stone', u'Epica', u'The Quantum Enigma',
              u'Nuclear Blast'))
    db.session.commit()
Ejemplo n.º 2
0
def add_track():
    title = request.form['title'].strip()
    album = request.form['album'].strip()
    artist = request.form['artist'].strip()
    label = request.form['label'].strip()

    track = Track(title, artist, album, label)
    if not track.validate():
        return jsonify(success=False,
                       error="The track information you entered did not validate. Common reasons for this include missing or improperly entered information, especially the label. Please try again. If you continue to get this message after several attempts, and you're sure the information is correct, please contact the IT staff for help.")

    db.session.add(track)
    db.session.commit()
    return jsonify(success=True, track_id=track.id)
Ejemplo n.º 3
0
def find_or_insert_track(title, artist, album, label, playedtime):
    title = title.strip()
    artist = artist.strip()
    album = album.strip()
    label = label.strip()

    # set label to "Not Available" if it is empty
    if len(label) <= 0:
        label = u"Not Available"

    existing = Track.query.filter(Track.title == title, Track.artist == artist,
                                  Track.album == album,
                                  Track.label == label).first()
    if existing is None:
        track = Track(title, artist, album, label)
        track.added = playedtime
        db.session.add(track)
        db.session.commit()
    else:
        track = existing

    return track
Ejemplo n.º 4
0
def edit_tracklog(tracklog_id):
    tracklog = TrackLog.query.get(tracklog_id)
    if not tracklog:
        return jsonify(success=False, error="tracklog_id not found")
    if tracklog.djset.dtend is not None:
        return jsonify(success=False, error="Session expired, please login again")

    if request.method == 'DELETE':
        # TODO: Check if the currently playing track changed
        db.session.delete(tracklog)
        db.session.commit()
        return jsonify(success=True)

    # This is a post time to do data sanitation!
    artist = request.form.get("artist", "").strip()
    title = request.form.get("title", "").strip()
    album = request.form.get("album", "").strip()
    label = request.form.get("label", "").strip()
    is_request = request.form.get('request', 'false') != 'false'
    vinyl = request.form.get('vinyl', 'false') != 'false'
    new = request.form.get('new', 'false') != 'false'
    rotation = request.form.get("rotation", 1)

    # Validate
    if len(artist) <= 0 or len(title) <= 0 or len(album) <= 0 or \
            len(label) <= 0:
        return jsonify(
            success=False,
            error="Must fill out artist, title, album, and label field")

    # First check if the artist et. al. are the same
    if artist != tracklog.track.artist or title != tracklog.track.title or \
            album != tracklog.track.album or label != tracklog.track.label:
        # This means we try to create a new track
        track = Track(title, artist, album, label)
        if not track.validate():
            return jsonify(success=False,
                           error="The track information you entered did not validate. Common reasons for this include missing or improperly entered information, especially the label. Please try again. If you continue to get this message after several attempts, and you're sure the information is correct, please contact the IT staff for help.")


        db.session.add(track)
        db.session.commit()
        tracklog.track_id = track.id

    # Update played time
    played = request.form.get('played', None)
    if played is not None:
        tracklog.played = dateutil.parser.parse(played)
    # Update boolean information
    tracklog.request = is_request
    tracklog.new = new
    tracklog.vinyl = vinyl

    # Update rotation
    rotation = Rotation.query.get(rotation)
    if not rotation:
        return jsonify(
            success=False,
            error="Rotation specified by rotation_id does not exist")
    tracklog.rotation_id = rotation.id

    db.session.commit()

    return jsonify(success=True)