예제 #1
0
def edit_date_status(photographer_id):
    if photographer_id == current_user.id:
        user = User.query.filter_by(id=photographer_id).first()
        form = DateStatusForm()
        if request.method == 'POST':
            if request.form.get('action') == 'create':
                if form.validate_on_submit():
                    start_date = form.from_day.data
                    end_date = form.end_day.data
                    date_status = DateStatus()
                    date_status.start_date = start_date
                    date_status.end_date = end_date
                    date_status.user_id = photographer_id
                    date_status.status = EnumValues.find_one_by_code(DATE_STATUS_NOT_AVAILABLE)
                    save_obj_commit(date_status)
                    flash('工作日历修改成功')
                else:
                    flash('输入错误,请重新选择起始日期')
            elif request.form.get('action') == 'delete':
                id_to_del = int(request.form.get('id_to_delete'))
                delete_by_id(DateStatus, id_to_del)
                flash('工作日历中不可用时间段删除成功')
        date_statuses = user.date_statuses
        return rt('edit_date_status.html', form=form, date_statuses=date_statuses)
    else:
        flash('您没有权限编辑该用户的工作日历')
        return redirect(url_for('index'))
예제 #2
0
def settings():
    user = User.query.filter_by(id=current_user.id).first()
    all_locations = EnumValues.type_filter(const.LOCATION_TYPE_KEY).all()
    if current_user.type.code == const.PHOTOGRAPHER_USER_TYPE:
        form = PhotographerProfileForm()
    else:
        form = NormalUserProfileForm()
    if request.method == 'POST':
        if request.form.get('gender') is None \
                or request.form.get('gender') == '':
            form.gender.data = u'保密'
        if form.validate_on_submit():
            user.login = form.login.data
            user.display = form.display.data
            user.gender = form.gender.data
            user.birthday = form.birthday.data
            user.mobile_phone = form.mobile_phone.data
            user.email = form.email.data
            user.weibo_account = form.weibo_account.data
            user.wechat_account = form.wechat_account.data
            user.qq_number = form.qq_number.data
            user.introduce = form.introduce.data
            user.daily_price = form.daily_price.data
            user.accept_travel = form.accept_travel.data
            user.location_id = int(form.location.data)
            if ('photo' in request.files) and \
                    (len(request.files.get('photo').filename) > 0):
                view_util.save_user_gallery(user, request.files['photo'])
            save_obj_commit(user)
            flash('更新个人信息成功!')
        else:
            flash('请确保所有必填字段已填写(日拍摄报价为必填字段)')
    return rt('settings.html', user_profile_form=form, user=user, all_locations=all_locations)
예제 #3
0
def process_message():
    operation = request.form.get('operation')
    message_id = int(request.form.get('message_id'))
    msg = Message.query.get(message_id)
    if operation == 'read':
        if msg.receive_user_id == current_user.id:
            status = EnumValues.find_one_by_code(MESSAGE_STATUS_READ)
            msg.status = status
            save_obj_commit(msg)
        else:
            flash("标记消息已读成功")
    return redirect(url_for('messages'))
예제 #4
0
def edit_experience(photographer_id):
    if photographer_id == current_user.id:
        user = User.query.filter_by(id=photographer_id).first()
        exp = user.experience
        if request.method == 'POST':
            if exp is None:
                exp = UserExperience()
            exp.user_id = user.id
            exp.content = request.form['experience-textarea']
            save_obj_commit(exp)
        return rt('edit_experience.html', experience=exp)
    else:
        flash('您没有权限编辑该用户的摄影经历')
        return redirect(url_for('index'))
예제 #5
0
def create_collection():
    categories = EnumValues.type_filter(const.PHOTO_CATEGORY_KEY).all()
    styles = EnumValues.type_filter(const.PHOTO_STYLE_KEY).all()
    photo_collection = PhotoCollection()
    form = PhotoCollectionForm(categories, styles)
    if request.method == "POST":
        if form.validate_on_submit():
            photo_collection.photographer_id = current_user.id
            photo_collection.uploader_id = current_user.id
            save_photo_collection(form, photo_collection)
            save_obj_commit(photo_collection)
            flash("作品集创建成功,您可以在本界面上传作品集中的作品")
            return redirect(url_for("edit_collection", collection_id=photo_collection.id))
        else:
            flash("请填写所有信息并再次尝试创建(作品集的拍摄价格为必填字段)")
    return rt(
        "create_collection.html", photo_collection=photo_collection, categories=categories, form=form, styles=styles
    )
예제 #6
0
def message(msg_id):
    msg = Message.query.get(msg_id)
    status = EnumValues.find_one_by_code(MESSAGE_STATUS_READ)
    msg.status = status
    save_obj_commit(msg)
    return rt('message.html', message=msg)