Beispiel #1
0
def picture_migrate():
    """
    设置相册的归属
    :return:
    """
    album_id = request.form['albumId']
    picture_list = request.form['pictureList']

    print album_id, picture_list
    album = Album.query.filter(Album.id == album_id,
                               # Album.authorId == session['author_id']
                               ).first()
    print type(album_id)
    if album and picture_list:
        picture_id_list = picture_list.split(',')
        print picture_id_list
        Picture.query.filter(Picture.id.in_(picture_id_list)).update(
            {'albumId': album.id}, synchronize_session=False)

        try:
            db.session.commit()
        except Exception, reason:
            return response_factory(success=False, message=reason)
        else:
            return response_factory()
Beispiel #2
0
def album_create():
    form = AlbumCreateFrom(request.form)

    if not form.validate():
        print(form.errors)
        return response_factory(success=False, message=form.errors)

    title = request.form['title']
    remark = request.form['remark']
    privacy = bool(request.form['privacy'])
    author_id = session['author_id']
    tagId = request.form['tagId']

    album = Album(title=title,
                  remark=remark,
                  privacy=privacy,
                  authorId=author_id,
                  tagId=tagId)

    db.session.add(album)

    try:
        db.session.commit()
    except Exception, reason:
        return response_factory(success=False, message=reason)
Beispiel #3
0
def picture_delete(pictureId):
    picture = Picture.query.filter(Picture.id == pictureId).first()
    if picture and picture.authorId == session['author_id']:
        db.session.delete(picture)
        try:
            db.session.commit()
        except Exception, reason:
            return response_factory(success=False, message=reason)
        else:
            return response_factory()
Beispiel #4
0
def author_login():
    username = request.form['username']
    password = request.form['password']

    author = Author.get_author_by_username_and_password(username, password)

    if author:
        session['author_id'] = author.id
        session['author_name'] = author.nickname

        return response_factory(data={'id': author.id})
    else:

        return response_factory(success=False, message=u'账户或用户名错误')
Beispiel #5
0
def album_set_cover():
    albumId = request.args.get('albumId')
    pictureId = request.args.get('pictureId')
    picture = Picture.query.filter(Picture.id == pictureId).first()
    print picture.tinyLink, albumId
    if picture:
        print Album.query.filter(Album.id == albumId).first()
        Album.query.filter(Album.id == albumId).update(
            {'cover': picture.tinyLink})
        try:
            db.session.commit()
        except Exception, reason:
            return response_factory(success=False, message=reason)
        else:
            return response_factory()
Beispiel #6
0
def album_set_carrousel(albumId):
    old_album = Album.query.filter(Album.iscarrousel).first()

    new_album = Album.query.filter(Album.id == albumId).first()

    if not new_album:
        return response_factory(success=False, message=u'相册不存在')
    else:
        new_album.iscarrousel = True
        if old_album:
            old_album.iscarrousel = False

        try:
            db.session.commit()
        except Exception, reason:
            return response_factory(success=False, message=reason)
        else:
Beispiel #7
0
def page_author_register():
    if request.method == 'GET':
        return render_template('register.html', )
    else:
        username = request.form['username']
        password = request.form['password']
        nickname = request.form['nickname']
        print(request.form)
        form = RegisterForm(request.form)

        if not form.validate():
            return render_template('register.html',
                                   username=username,
                                   nickname=nickname,
                                   error=response_factory(success=False,
                                                          message=form.errors))
        else:
            exist_author = Author.query.filter(
                Author.username == username).first()

            if exist_author:
                return render_template('register.html',
                                       username=username,
                                       nickname=nickname,
                                       error=response_factory(
                                           success=False, message=u'用户已存在'))

            author = Author(username=username)
            author.set_password(password)
            author.nickname = nickname

            db.session.add(author)

            try:
                db.session.commit()
            except Exception, reason:
                return render_template('register.html',
                                       username=username,
                                       nickname=nickname,
                                       error=response_factory(success=False,
                                                              message=reason))
            else:
Beispiel #8
0
def article_submit():
    """
    we have to differentiate auto submit and manually submit
    :return:
    """
    articleId = request.form['articleId']
    title = request.form['title']
    content = request.form['content']
    tagId = request.form['tagId']
    privacy = int(request.form['privacy'])
    cover = request.form['cover']
    summary = request.form['summary']

    if articleId:
        Article.query.filter(Article.id == articleId).update({
            'title':
            title,
            'content':
            content,
            'privacy':
            privacy,
            'tagId':
            tagId,
            'cover':
            cover,
            'summary':
            summary,
        })
    else:
        essay = Article(title=title,
                        content=content,
                        summary=summary,
                        cover=cover,
                        privacy=privacy,
                        tagId=tagId,
                        authorId=1)

        db.session.add(essay)

    try:
        db.session.commit()
    except Exception, reason:
        return response_factory(
            success=False,
            message=reason,
        )
Beispiel #9
0
def author_update():
    author_id = session['author_id']
    nickname = request.form['nickname']
    portrait = request.form['portrait']
    description = request.form['description']

    try:
        Author.query.filter(Author.id == author_id).update({
            'nickname':
            nickname,
            'portrait':
            portrait,
            'description':
            description,
        })
        db.session.commit()
    except Exception, reason:
        return response_factory(success=False, message=reason)
Beispiel #10
0
def album_update():
    album_id = request.form['albumId']
    title = request.form['title']
    remark = request.form['remark']
    privacy = request.form['privacy']
    tagId = request.form['tagId']

    Album.query.filter(Album.id == album_id,
                       Album.authorId == session['author_id']).update({
                           'title':
                           title,
                           'remark':
                           remark,
                           'privacy':
                           privacy,
                           'tagId':
                           tagId,
                       })

    try:
        db.session.commit()
    except Exception, reason:
        return response_factory(success=False, message=reason)
Beispiel #11
0
            message=u'上传失败' if int(not photo_path_arr) else '')


@picture.route('/delete/<int:pictureId>', methods=['get'])
def picture_delete(pictureId):
    picture = Picture.query.filter(Picture.id == pictureId).first()
    if picture and picture.authorId == session['author_id']:
        db.session.delete(picture)
        try:
            db.session.commit()
        except Exception, reason:
            return response_factory(success=False, message=reason)
        else:
            return response_factory()
    else:
        return response_factory(success=False, message=u'相片不存在')


@picture.route('/migrate', methods=['post'])
# @login_required
def picture_migrate():
    """
    设置相册的归属
    :return:
    """
    album_id = request.form['albumId']
    picture_list = request.form['pictureList']

    print album_id, picture_list
    album = Album.query.filter(Album.id == album_id,
                               # Album.authorId == session['author_id']
Beispiel #12
0
def author_logout():
    session.pop('author_id')

    return response_factory(message=u'登出成功')
Beispiel #13
0

@login_required
@author.route("/update", methods=['post'])
def author_update():
    author_id = session['author_id']
    nickname = request.form['nickname']
    portrait = request.form['portrait']
    description = request.form['description']

    try:
        Author.query.filter(Author.id == author_id).update({
            'nickname':
            nickname,
            'portrait':
            portrait,
            'description':
            description,
        })
        db.session.commit()
    except Exception, reason:
        return response_factory(success=False, message=reason)

    return response_factory(data={'id': author_id})


@login_required
@author.route("/index", methods=['get'])
def page_author_update():
    return render_template('author-center.html')
Beispiel #14
0
            'privacy':
            privacy,
            'tagId':
            tagId,
            'cover':
            cover,
            'summary':
            summary,
        })
    else:
        essay = Article(title=title,
                        content=content,
                        summary=summary,
                        cover=cover,
                        privacy=privacy,
                        tagId=tagId,
                        authorId=1)

        db.session.add(essay)

    try:
        db.session.commit()
    except Exception, reason:
        return response_factory(
            success=False,
            message=reason,
        )

    return response_factory(success=True,
                            data={'articleId': articleId or essay.id})