Example #1
0
def show_microblog(page):
    pagination = Microblog.query.order_by(Microblog.post_time.desc()).\
        paginate(page, per_page=50)
    microblogs = pagination.items
    return render_template('admin/microblog.html',
                           microblogs=microblogs,
                           pagination=pagination)
Example #2
0
def album(id):
    people = People.query.get_or_404(id)
    # albums = PhotoAlbum.query.filter_by(people_id=id).all()
    # default_album_photos = Photo.query.filter_by(people_id=id).all()
    return render_template('photo/all-albums.html',
                           people=people,
                           title='所有相册')
Example #3
0
def login():
    # 已登录用户则返回首页
    if g.user.is_authenticated:
        return redirect(url_for('frontend.index'))

    login_form = LoginForm()
    if login_form.validate_on_submit():
        people = People.query.authenticate(
            login_form.login.data,
            login_form.password.data,
        )

        if people:
            login_user(people, remember=login_form.remember.data)
            # Flask-Principal 发送信号
            identity_changed.send(current_app._get_current_object(),
                                  identity=Identity(people.id))
            print 'sent by login'
            ip = get_client_ip()
            login_log = LoginLog(people.id, ip)
            db.session.add(login_log)
            db.session.commit()

            flash('登录成功', 'success')
            return redirect(url_for('frontend.index'))
        else:
            flash('登录失败', 'warning')

    return render_template('login.html', form=login_form)
Example #4
0
def login():
    # 已登录用户则返回首页
    if g.user.is_authenticated:
        return redirect(url_for('frontend.index'))

    login_form = LoginForm()
    if login_form.validate_on_submit():
        people = People.query.authenticate(
            login_form.login.data,
            login_form.password.data,
        )

        if people:
            login_user(people, remember=login_form.remember.data)
            # Flask-Principal 发送信号
            identity_changed.send(current_app._get_current_object(), identity=Identity(people.id))
            print 'sent by login'
            ip = get_client_ip()
            login_log = LoginLog(people.id, ip)
            db.session.add(login_log)
            db.session.commit()

            flash('登录成功', 'success')
            return redirect(url_for('frontend.index'))
        else:
            flash('登录失败', 'warning')

    return render_template('login.html', form=login_form)
Example #5
0
def avatar():
    avatar_form = AvatarForm()
    if avatar_form.validate_on_submit():
        if avatar_form.avatar.data:
            # 上传头像
            avatar_filename = g.user.get_avatar_uri()
            avatar_data = request.files[avatar_form.avatar.name]
            uploader = get_uploader()
            avatar_filename = uploader.save(avatar_data)
            if not avatar_filename:
                flash('上传失败', 'danger')
                return redirect(url_for('account.avatar'))
            # url = photos.url(avatar_filename)
            # print url
            # old_avatar = photos.url(people.avatar)
            # os.remove(old_avatar)   # 删除旧头像
            print avatar_filename
            g.user.change_avatar(avatar_filename)
            db.session.add(g.user)
            db.session.commit()
            flash('上传成功', 'success')
            return redirect(url_for('account.avatar'))

    return render_template('avatar.html',
                           avatar_form=avatar_form,
                           title='修改头像')
Example #6
0
def show_login_log(page):
    pagination = LoginLog.query.order_by(LoginLog.login_time.desc()).\
        paginate(page, per_page=50)
    login_logs = pagination.items
    return render_template('admin/login-log.html',
                           login_logs=login_logs,
                           pagination=pagination)
Example #7
0
def show_people(page):
    pagination = People.query.paginate(page, per_page=50)
    people = pagination.items
    return render_template(
        'admin/people.html',
        people=people,
        pagination=pagination
    )
Example #8
0
def show_login_log(page):
    pagination = LoginLog.query.order_by(LoginLog.login_time.desc()).\
        paginate(page, per_page=50)
    login_logs = pagination.items
    return render_template(
        'admin/login-log.html',
        login_logs=login_logs,
        pagination=pagination
    )
Example #9
0
def post():
    post_form = PostForm()
    if post_form.validate_on_submit():
        microblog = Microblog(g.user.id, post_form.content.data)
        db.session.add(microblog)
        db.session.commit()
        flash('发布成功', 'success')
        return redirect(url_for('frontend.index'))
    return render_template('post.html', form=post_form)
Example #10
0
def show_visit_log(page):
    pagination = VisitLog.query.order_by(VisitLog.visit_time.desc()).\
        paginate(page, per_page=50)
    # For BAE f*****g MySQL
    # pagination = VisitLog.query.paginate(page, per_page=50)
    visit_logs = pagination.items
    return render_template('admin/visit-log.html',
                           visit_logs=visit_logs,
                           pagination=pagination)
Example #11
0
def post():
    post_form = PostForm()
    if post_form.validate_on_submit():
        microblog = Microblog(g.user.id, post_form.content.data)
        db.session.add(microblog)
        db.session.commit()
        flash('发布成功', 'success')
        return redirect(url_for('frontend.index'))
    return render_template('post.html', form=post_form)
Example #12
0
def show_microblog(page):
    pagination = Microblog.query.order_by(Microblog.post_time.desc()).\
        paginate(page, per_page=50)
    microblogs = pagination.items
    return render_template(
        'admin/microblog.html',
        microblogs=microblogs,
        pagination=pagination
    )
Example #13
0
def show_album(id):
    """显示相册里的所有照片,只能查看自己的相册"""
    album = PhotoAlbum.query.get_or_404(id)
    #if album.people_id != g.user.id:
    #    flash('权限不足', 'warning')
    #    return redirect(url_for('frontend.index'))
    return render_template(
        'photo/album.html',
        album=album,
        title='查看相册'
    )
Example #14
0
def show_visit_log(page):
    pagination = VisitLog.query.order_by(VisitLog.visit_time.desc()).\
        paginate(page, per_page=50)
    # For BAE f*****g MySQL
    # pagination = VisitLog.query.paginate(page, per_page=50)
    visit_logs = pagination.items
    return render_template(
        'admin/visit-log.html',
        visit_logs=visit_logs,
        pagination=pagination
    )
Example #15
0
def upload_photo(id=None):
    if id:
        album = PhotoAlbum.query.get_or_404(id)
        if album.people_id != g.user.id:
            flash('权限不足', 'warning')
            return redirect('frontend.index')
    # 列出所有相册
    album_choices = [(str(a.id), a.title) for a in g.user.albums]
    if not album_choices:
        # 如果没有任何相册,则新建一个默认相册
        default_album = PhotoAlbum(
            title='默认相册',
            people_id=g.user.id
        )
        db.session.add(default_album)
        db.session.commit()
        album_choices.append((str(default_album.id), default_album.title))
        
    upload_form = UploadForm()
    upload_form.album.choices = album_choices
    if not id:
        id = album_choices[0][0]    # 第一个相册的 id
    upload_form.album.data = str(id)
    
    if upload_form.validate_on_submit():
        print 'id:', upload_form.album.data
        album = PhotoAlbum.query.get_or_404(upload_form.album.data)
        if album.people_id != g.user.id:
            flash('权限不足', 'warning')
            return redirect('frontend.index')
         # 循环上传照片
        for field in upload_form:
            print field.name
            if 'photo' in field.name and field.data:
                photo_data = request.files[field.name]
                uploader = get_uploader()
                filename = uploader.save(photo_data)
                if not filename:
                    flash('上传失败', 'danger')
                    return redirect(url_for('frontend.album', id=g.user.id))
                print upload_form.album.data
                photo = Photo(uri=filename, album_id=upload_form.album.data, people_id=g.user.id)
                db.session.add(photo)
                db.session.commit()
        flash('上传成功', 'success')
        return redirect(url_for('frontend.album', id=g.user.id))

    return render_template(
        'photo/upload.html',
        form=upload_form,
        title='上传照片'
    )
Example #16
0
def index():
    if g.user.is_authenticated:
        # 只显示关注的人
        microblogs = Microblog.query.\
            filter(Microblog.people_id.in_([p.id for p in g.user.following]+[g.user.id])).\
            order_by(Microblog.post_time.desc()).all()
    else:
        microblogs = Microblog.query.order_by(
            Microblog.post_time.desc()).limit(10).all()
    # print microblogs
    return render_template('index.html',
                           microblogs=microblogs,
                           post_form=PostForm())
Example #17
0
def repost(id):
    microblog = Microblog.query.get_or_404(id)
    repost_form = RepostForm()
    if repost_form.validate_on_submit():
        rp_microblog = Microblog(g.user.id, repost_form.content.data, parent_microblog_id=id)
        db.session.add(rp_microblog)
        if g.user.id != microblog.people_id:
            notification = Notification(
                from_id=g.user.id, to_id=microblog.people_id,
                object_table='microblog', object_id=id
            )
            db.session.add(notification)
        db.session.commit()
        flash('转发成功', 'success')
        return redirect(url_for('frontend.index'))
    return render_template('repost.html', form=repost_form, microblog=microblog)
Example #18
0
def comment(mid, cid=None):
    microblog = Microblog.query.get_or_404(mid)

    # 如果是对评论的评论,则在表单中显示回复的目标(字符串)
    # 并在提交时使用切片运算忽略该字符串
    if cid:
        parent_comment = Comment.query.get_or_404(cid)
        # 不能回复自己
        if g.user.id == parent_comment.people.id:
            flash('不能回复自己', 'warning')
            return redirect(url_for('mblog.comment', mid=mid))
        content = '回复 ' + parent_comment.people.nickname + ': '
    else:
        parent_comment = None
        content = ''
    comment_form = CommentForm(content=content)
    if comment_form.validate_on_submit():
        comment = Comment(
            g.user.id,
            comment_form.content.data[len(content):],
            mid,
            cid
        )
        db.session.add(comment)
        db.session.commit()
        if cid and g.user.id != parent_comment.people_id:
            notification = Notification(
                from_id=g.user.id, to_id=parent_comment.people_id,
                object_table='comment', object_id=comment.id
            )
            db.session.add(notification)
            db.session.commit()
        elif g.user.id != microblog.people_id:
            notification = Notification(
                from_id=g.user.id, to_id=microblog.people_id,
                object_table='microblog', object_id=mid
            )
            db.session.add(notification)
            db.session.commit()
        flash('评论成功', 'success')
        return redirect(url_for('mblog.comment', mid=mid))
    return render_template(
        'comment.html',
        form=comment_form,
        microblog=microblog,
        parent_comment=parent_comment
    )
Example #19
0
def modify_photo(id):
    photo = Photo.query.get_or_404(id)
    if photo.people_id != g.user.id:
        flash('权限不足', 'warning')
        return redirect(url_for('frontend.index'))
    photo_form = PhotoForm(obj=photo)
    if photo_form.validate_on_submit():
        photo.description = photo_form.description.data
        db.session.add(photo)
        db.session.commit()
        flash('修改成功', 'success')
        return redirect(url_for('show_photo', id=id))
    return render_template(
        'photo/photo-info.html',
        form=photo_form,
        title='修改照片属性'
    )
Example #20
0
def profile_detail():
    people_info = PeopleInfo.query.get(g.user.id)
    profile_detail_form = ModifyProfileDetailForm(obj=people_info)
    if profile_detail_form.validate_on_submit():
        if people_info:
            people_info.change_info(
                fullname=profile_detail_form.fullname.data,
                gender=profile_detail_form.gender.data,
                sexual_orientation=profile_detail_form.sexual_orientation.data,
                birthday=profile_detail_form.birthday.data,
                blood_type=profile_detail_form.blood_type.data,
                profession=profile_detail_form.profession.data,
                education=profile_detail_form.education.data,
                school=profile_detail_form.school.data,
                homepage=profile_detail_form.homepage.data,
                hometown=profile_detail_form.hometown.data,
                location=profile_detail_form.location.data,
                address=profile_detail_form.address.data,
                zip_code=profile_detail_form.zip_code.data,
                qq=profile_detail_form.qq.data,
                introduction=profile_detail_form.introduction.data)
        else:
            people_info = PeopleInfo(
                id=g.user.id,
                fullname=profile_detail_form.fullname.data,
                gender=profile_detail_form.gender.data,
                sexual_orientation=profile_detail_form.sexual_orientation.data,
                birthday=profile_detail_form.birthday.data,
                blood_type=profile_detail_form.blood_type.data,
                profession=profile_detail_form.profession.data,
                education=profile_detail_form.education.data,
                school=profile_detail_form.school.data,
                homepage=profile_detail_form.homepage.data,
                hometown=profile_detail_form.hometown.data,
                location=profile_detail_form.location.data,
                address=profile_detail_form.address.data,
                zip_code=profile_detail_form.zip_code.data,
                qq=profile_detail_form.qq.data,
                introduction=profile_detail_form.introduction.data)
        db.session.add(people_info)
        db.session.commit()
        flash('详细资料修改成功', 'success')
        return redirect(url_for('account.profile_detail'))
    return render_template('profile-detail.html',
                           form=profile_detail_form,
                           title='详细资料')
Example #21
0
def password():
    change_password_form = ChangePasswordForm()
    if change_password_form.validate_on_submit():
        people = People.query.authenticate(
            g.user.get_email(),
            change_password_form.password_old.data,
        )
        if people:
            people.change_password(change_password_form.password_new.data)
            db.session.add(people)
            db.session.commit()
            db.session.close()
            flash('密码修改成功', 'success')
            return redirect(url_for('account.password'))
        else:
            flash('原密码不正确', 'warning')
    return render_template('password.html', form=change_password_form, title='修改密码')
Example #22
0
def profile_detail():
    people_info = PeopleInfo.query.get(g.user.id)
    profile_detail_form = ModifyProfileDetailForm(obj=people_info)
    if profile_detail_form.validate_on_submit():
        if people_info:
            people_info.change_info(
                fullname=profile_detail_form.fullname.data,
                gender=profile_detail_form.gender.data,
                sexual_orientation=profile_detail_form.sexual_orientation.data,
                birthday=profile_detail_form.birthday.data,
                blood_type=profile_detail_form.blood_type.data,
                profession=profile_detail_form.profession.data,
                education=profile_detail_form.education.data,
                school=profile_detail_form.school.data,
                homepage=profile_detail_form.homepage.data,
                hometown=profile_detail_form.hometown.data,
                location=profile_detail_form.location.data,
                address=profile_detail_form.address.data,
                zip_code=profile_detail_form.zip_code.data,
                qq=profile_detail_form.qq.data,
                introduction=profile_detail_form.introduction.data
            )
        else:
            people_info = PeopleInfo(
                id=g.user.id,
                fullname=profile_detail_form.fullname.data,
                gender=profile_detail_form.gender.data,
                sexual_orientation=profile_detail_form.sexual_orientation.data,
                birthday=profile_detail_form.birthday.data,
                blood_type=profile_detail_form.blood_type.data,
                profession=profile_detail_form.profession.data,
                education=profile_detail_form.education.data,
                school=profile_detail_form.school.data,
                homepage=profile_detail_form.homepage.data,
                hometown=profile_detail_form.hometown.data,
                location=profile_detail_form.location.data,
                address=profile_detail_form.address.data,
                zip_code=profile_detail_form.zip_code.data,
                qq=profile_detail_form.qq.data,
                introduction=profile_detail_form.introduction.data
            )
        db.session.add(people_info)
        db.session.commit()
        flash('详细资料修改成功', 'success')
        return redirect(url_for('account.profile_detail'))
    return render_template('profile-detail.html', form=profile_detail_form, title='详细资料')
Example #23
0
def profile():
    people = g.user
    profile_form = ModifyProfileForm(obj=people)
    if profile_form.validate_on_submit():
        #new_password = profile_form.password.data
        new_nickname = profile_form.nickname.data
        new_mobile = profile_form.mobile.data
        #if new_password:
        #    people.change_password(new_password)
        if new_nickname:
            people.change_nickname(new_nickname)
        if new_mobile:
            people.change_mobile(new_mobile)
        db.session.add(people)
        db.session.commit()
        db.session.close()
        flash('个人资料修改成功', 'success')
        return redirect(url_for('account.profile'))
    return render_template('profile.html', form=profile_form, title='修改资料')
Example #24
0
def password():
    change_password_form = ChangePasswordForm()
    if change_password_form.validate_on_submit():
        people = People.query.authenticate(
            g.user.get_email(),
            change_password_form.password_old.data,
        )
        if people:
            people.change_password(change_password_form.password_new.data)
            db.session.add(people)
            db.session.commit()
            db.session.close()
            flash('密码修改成功', 'success')
            return redirect(url_for('account.password'))
        else:
            flash('原密码不正确', 'warning')
    return render_template('password.html',
                           form=change_password_form,
                           title='修改密码')
Example #25
0
def profile():
    people = g.user
    profile_form = ModifyProfileForm(obj=people)
    if profile_form.validate_on_submit():
        #new_password = profile_form.password.data
        new_nickname = profile_form.nickname.data
        new_mobile = profile_form.mobile.data
        #if new_password:
        #    people.change_password(new_password)
        if new_nickname:
            people.change_nickname(new_nickname)
        if new_mobile:
            people.change_mobile(new_mobile)
        db.session.add(people)
        db.session.commit()
        db.session.close()
        flash('个人资料修改成功', 'success')
        return redirect(url_for('account.profile'))
    return render_template('profile.html', form=profile_form, title='修改资料')
Example #26
0
def repost(id):
    microblog = Microblog.query.get_or_404(id)
    repost_form = RepostForm()
    if repost_form.validate_on_submit():
        rp_microblog = Microblog(g.user.id,
                                 repost_form.content.data,
                                 parent_microblog_id=id)
        db.session.add(rp_microblog)
        if g.user.id != microblog.people_id:
            notification = Notification(from_id=g.user.id,
                                        to_id=microblog.people_id,
                                        object_table='microblog',
                                        object_id=id)
            db.session.add(notification)
        db.session.commit()
        flash('转发成功', 'success')
        return redirect(url_for('frontend.index'))
    return render_template('repost.html',
                           form=repost_form,
                           microblog=microblog)
Example #27
0
def add_album():
    """新建相册"""
    add_album_form = AddAlbumForm()
    if add_album_form.validate_on_submit():
        album = PhotoAlbum(
            title=add_album_form.title.data,
            description=add_album_form.description.data,
            people_id=g.user.id
        )
        db.session.add(album)
        db.session.commit()
        flash('相册新建成功', 'success')
        return redirect(url_for('show_album', id=album.id))
        # return '添加成功'

    return render_template(
        'photo/album-info.html',
        form=add_album_form,
        title='新建相册'
    )
Example #28
0
def comment(mid, cid=None):
    microblog = Microblog.query.get_or_404(mid)

    # 如果是对评论的评论,则在表单中显示回复的目标(字符串)
    # 并在提交时使用切片运算忽略该字符串
    if cid:
        parent_comment = Comment.query.get_or_404(cid)
        # 不能回复自己
        if g.user.id == parent_comment.people.id:
            flash('不能回复自己', 'warning')
            return redirect(url_for('mblog.comment', mid=mid))
        content = '回复 ' + parent_comment.people.nickname + ': '
    else:
        parent_comment = None
        content = ''
    comment_form = CommentForm(content=content)
    if comment_form.validate_on_submit():
        comment = Comment(g.user.id, comment_form.content.data[len(content):],
                          mid, cid)
        db.session.add(comment)
        db.session.commit()
        if cid and g.user.id != parent_comment.people_id:
            notification = Notification(from_id=g.user.id,
                                        to_id=parent_comment.people_id,
                                        object_table='comment',
                                        object_id=comment.id)
            db.session.add(notification)
            db.session.commit()
        elif g.user.id != microblog.people_id:
            notification = Notification(from_id=g.user.id,
                                        to_id=microblog.people_id,
                                        object_table='microblog',
                                        object_id=mid)
            db.session.add(notification)
            db.session.commit()
        flash('评论成功', 'success')
        return redirect(url_for('mblog.comment', mid=mid))
    return render_template('comment.html',
                           form=comment_form,
                           microblog=microblog,
                           parent_comment=parent_comment)
Example #29
0
def show_photo(pid, aid=None):
    photo = Photo.query.get_or_404(pid)
    prev_id = next_id = None
    if aid:
        if photo.album_id != aid:
            abort(404)
        else:
            # 获取 prev_id & next_id
            # 上一张和下一张
            prev_photo = Photo.query.filter(and_(Photo.id<pid, Photo.album_id==aid)).order_by(Photo.id.desc()).first()
            if prev_photo:
                prev_id = prev_photo.id
            next_photo = Photo.query.filter(and_(Photo.id>pid, Photo.album_id==aid)).first()
            if next_photo:
                next_id = next_photo.id
    return render_template(
        'photo/photo.html',
        photo=photo,
        prev_id=prev_id,
        next_id=next_id,
        title='查看照片'
    )
Example #30
0
def register():
    # 已登录用户则返回首页
    if g.user.is_authenticated:
        return redirect(url_for('frontend.index'))

    register_form = RegisterForm()
    if register_form.validate_on_submit():
        ip = get_client_ip()
        people = People(
            email=register_form.email.data,
            password=register_form.password.data,
            nickname=register_form.nickname.data,
            mobile=register_form.mobile.data,
            reg_time=datetime.datetime.utcnow(),
            reg_ip=ip,
        )
        # 将用户写入数据库
        db.session.add(people)
        db.session.commit()
        db.session.close()
        flash('注册成功', 'success')
        return redirect(url_for('frontend.index'))
    return render_template('register.html', register_form=register_form)
Example #31
0
def register():
    # 已登录用户则返回首页
    if g.user.is_authenticated:
        return redirect(url_for('frontend.index'))

    register_form = RegisterForm()
    if register_form.validate_on_submit():
        ip = get_client_ip()
        people = People(
            email=register_form.email.data,
            password=register_form.password.data,
            nickname=register_form.nickname.data,
            mobile=register_form.mobile.data,
            reg_time=datetime.datetime.utcnow(),
            reg_ip=ip,
        )
        # 将用户写入数据库
        db.session.add(people)
        db.session.commit()
        db.session.close()
        flash('注册成功', 'success')
        return redirect(url_for('frontend.index'))
    return render_template('register.html', register_form=register_form)
Example #32
0
def modify_album(id):
    """修改相册属性"""
    album = PhotoAlbum.query.get_or_404(id)
    if album.people_id != g.user.id:
        flash('权限不足', 'warning')
        return redirect(url_for('show_album', id=album.id))
    if album.title == '默认相册':
        flash('无法修改属性', 'warning')
        return redirect(url_for('show_album', id=album.id))
    modify_album_form = ModifyAlbumForm(obj=album)
    if modify_album_form.validate_on_submit():
        album.title = modify_album_form.title.data
        album.description = modify_album_form.description.data

        db.session.add(album)
        db.session.commit()
        flash('相册修改成功', 'success')
        return redirect(url_for('show_album', id=album.id))

    return render_template(
        'photo/album-info.html',
        form=modify_album_form,
        title='修改相册属性'
    )
Example #33
0
def avatar():
    avatar_form = AvatarForm()
    if avatar_form.validate_on_submit():
        if avatar_form.avatar.data:
            # 上传头像
            avatar_filename = g.user.get_avatar_uri()
            avatar_data = request.files[avatar_form.avatar.name]
            uploader = get_uploader()
            avatar_filename = uploader.save(avatar_data)
            if not avatar_filename:
                flash('上传失败', 'danger')
                return redirect(url_for('account.avatar'))
            # url = photos.url(avatar_filename)
            # print url
            # old_avatar = photos.url(people.avatar)
            # os.remove(old_avatar)   # 删除旧头像
            print avatar_filename
            g.user.change_avatar(avatar_filename)
            db.session.add(g.user)
            db.session.commit()
            flash('上传成功', 'success')
            return redirect(url_for('account.avatar'))

    return render_template('avatar.html', avatar_form=avatar_form, title='修改头像')
Example #34
0
def square():
    microblogs = Microblog.query.order_by(Microblog.post_time.desc()).all()
    # print microblogs
    return render_template('square.html',
                           microblogs=microblogs,
                           post_form=PostForm())
Example #35
0
def show_notification():
    notifications = Notification.query.filter_by(to_id=g.user.id).order_by(Notification.create_time.desc()).all()
    return render_template('notification.html', notifications=notifications)
Example #36
0
def show_about():
    return render_template('about.html')
Example #37
0
def index():
    return render_template('admin/index.html')
Example #38
0
def people(id):
    people = People.query.get_or_404(id)
    return render_template('people.html', people=people)
Example #39
0
def show_people(page):
    pagination = People.query.paginate(page, per_page=50)
    people = pagination.items
    return render_template('admin/people.html',
                           people=people,
                           pagination=pagination)
Example #40
0
def index():
    return render_template('admin/index.html')