def _register():
    current_user = get_current_user()

    form = Register_form(request.form, csrf_enabled=False)

    msg = None

    if form.validate_on_submit():

        old_user = sess.query(User).filter(User.email==form.email.data).first()

        if old_user is not None:
            msg = 'Det finns redan en användare med den här email addressen!'
        else:
            user = User(
                email=form.email.data,
                first_name=form.first_name.data,
                last_name=form.last_name.data,
                password=form.password.data
            )

            sess.add(user)
            sess.commit()

            msg = 'Välkommen, <a href="/login">logga in</a>'

    return render_template('register.html', current_user=current_user, form=form, msg=msg)
Beispiel #2
0
def _upload():
    form = SongForm(csrf_enabled=False)

    error = None

    if form.validate_on_submit():
        filename = secure_filename(form.song.data.filename)
        fname, file_extension = os.path.splitext(form.song.data.filename)
        if not 'mp3' in file_extension:
            error = 'Must be mp3'
        else:
            form.song.data.save('flaskr/static/music/' + filename)

            song = Song(artist=form.artist.data,
                        title=form.title.data,
                        file=secure_filename(form.song.data.filename))
            sess.add(song)
            sess.commit()
    else:
        filename = None
        error = None

    return render_template('upload.html',
                           error=error,
                           filename=filename,
                           form=form)
Beispiel #3
0
def _action(act):

    if act == 'delete':
        song_id = request.form['id']
        song = sess.query(Song).filter(Song.id==song_id).first()


        os.remove(os.path.dirname(os.path.dirname(__file__)) + '/static/music/{file}'.format(file=song.file))

        sess.delete(song)
        sess.commit()

        return 'ok'
def _forum_upload():
    current_user = get_current_user()

    if current_user is None:
        return redirect('/')

    form = Upload_image_form(csrf_enabled=False)

    msg = None

    if form.validate_on_submit():
        title = form.title.data
        description = form.description.data
        place = form.place.data

        old_place = sess.query(Place).filter(Place.name==place).first()

        if old_place is None:
            new_place = Place(
                name=place
            )
            sess.add(new_place)
            sess.commit()
        else:
            new_place = old_place

        new_filename = get_random_string(16) + '.' + form.image.data.filename.split('.')[1]

        old_image = sess.query(Image).filter(Image.filename==new_filename).first()

        while old_image is not None:
            new_filename = get_random_string(16) + '.' + form.image.data.filename.split('.')[1]
            old_image = sess.query(Image).filter(Image.filename==new_filename).first()

        image = Image(
            filename=new_filename,
            place_id=new_place.id,
            user_id=current_user.id,
            title=title,
            description=description
        )

        sess.add(image)
        sess.commit()

        form.image.data.save('flaskr/static/upload/image/' + new_filename)

        msg = 'Din bild var uppladdad!'

    return render_template('forum_upload.html', current_user=current_user, form=form, msg=msg)
Beispiel #5
0
def _action(act):

    if act == 'delete':
        song_id = request.form['id']
        song = sess.query(Song).filter(Song.id == song_id).first()

        os.remove(
            os.path.dirname(os.path.dirname(__file__)) +
            '/static/music/{file}'.format(file=song.file))

        sess.delete(song)
        sess.commit()

        return 'ok'
Beispiel #6
0
def _upload():
    form = SongForm(csrf_enabled=False)

    error = None

    if form.validate_on_submit():
        filename = secure_filename(form.song.data.filename)
        fname, file_extension = os.path.splitext(form.song.data.filename)
        if not 'mp3' in file_extension:
            error = 'Must be mp3'
        else:
            form.song.data.save('flaskr/static/music/' + filename)

            song = Song(artist=form.artist.data, title=form.title.data, file=secure_filename(form.song.data.filename))
            sess.add(song)
            sess.commit()
    else:
        filename = None
        error = None

    return render_template('upload.html', error=error, filename=filename, form=form)
def _forum_images_image(image_id):
    current_user = get_current_user()
    image_owner = None

    form = Comment_form(csrf_enabled=False)

    image = sess.query(Image).filter(Image.id==image_id).first()

    if current_user is None:
        return redirect('/')
    else:
        notifications = sess.query(Notification).filter(
            Notification.user_id==current_user.id,
            Notification.image_id==image.id
        ).delete()
        sess.commit()

    comments = []

    
    if image is not None:
        uploader = sess.query(User).filter(User.id==image.user_id).first()
        place = sess.query(Place).filter(Place.id==image.place_id).first()
        image_owner = sess.query(User).filter(User.id==image.user_id).first()

        if request.method == 'POST':
            if 'submit' in request.form:
                if request.form['submit'] == 'Skicka':
                    if form.validate_on_submit():
                        comment_text = form.text.data
                        new_comment = Comment(text=comment_text, image_id=image.id, user_id=current_user.id)
                       
                        if image_owner.id != current_user.id:
                            notification = Notification(
                                image_id = image.id,
                                user_caused_id = current_user.id,
                                user_id = image_owner.id,
                                type = 'comment'
                            )
                            sess.add(notification)

                        sess.add(new_comment)
                        sess.commit()
                        form.text.data = None
                elif request.form['submit'] == 'Kasta':
                    selected_comment_id = request.form['comment_selected']
                    selected_comment = sess.query(Comment).filter(Comment.id==selected_comment_id).delete()
                    sess.commit()

        comments = sess.query(Comment, User).filter(Comment.image_id==image.id).order_by(Comment.created.desc()).join(User).all()

    return render_template('forum_image.html',
            current_user=current_user,
            image=image,
            place=place,
            comments=comments,
            uploader=uploader,
            form=form
    )
from player.player import Player
from flaskr.models import sess
from functions.songs import get_all_songs


for song in get_all_songs():
    song.playing = 0
    sess.commit()


player = Player()
player.start()
Beispiel #9
0
from player.player import Player
from flaskr.models import sess
from functions.songs import get_all_songs

for song in get_all_songs():
    song.playing = 0
    sess.commit()

player = Player()
player.start()