コード例 #1
0
ファイル: views.py プロジェクト: FooBarQuaxx/flaskbb
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first_or_404()

    if not can_edit_user(current_user):
        flash("You are not allowed to edit this user.", "danger")
        return redirect(url_for("management.users"))

    secondary_group_query = Group.query.filter(
        db.not_(Group.id == user.primary_group_id),
        db.not_(Group.banned == True),
        db.not_(Group.guest == True))

    form = EditUserForm(user)
    form.secondary_groups.query = secondary_group_query
    if form.validate_on_submit():
        form.populate_obj(user)
        user.primary_group_id = form.primary_group.data.id

       # Don't override the password
        if form.password.data:
            user.password = form.password.data

        user.save(groups=form.secondary_groups.data)

        flash("User successfully edited", "success")
        return redirect(url_for("management.edit_user", user_id=user.id))

    return render_template("management/user_form.html", form=form,
                           title="Edit User")
コード例 #2
0
ファイル: views.py プロジェクト: vlttnv/flaskbb
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first_or_404()

    if not can_edit_user(current_user):
        flash(_("You are not allowed to edit this user."), "danger")
        return redirect(url_for("management.users"))

    secondary_group_query = Group.query.filter(
        db.not_(Group.id == user.primary_group_id), db.not_(Group.banned),
        db.not_(Group.guest == True))

    form = EditUserForm(user)
    form.secondary_groups.query = secondary_group_query
    if form.validate_on_submit():
        form.populate_obj(user)
        user.primary_group_id = form.primary_group.data.id

        # Don't override the password
        if form.password.data:
            user.password = form.password.data

        user.save(groups=form.secondary_groups.data)

        flash(_("User successfully updated."), "success")
        return redirect(url_for("management.edit_user", user_id=user.id))

    return render_template("management/user_form.html",
                           form=form,
                           title=_("Edit User"))
コード例 #3
0
ファイル: views.py プロジェクト: FrontSide/flaskbb
def sent():
    messages = PrivateMessage.query.filter(
        PrivateMessage.user_id == current_user.id,
        PrivateMessage.draft == False,
        PrivateMessage.trash == False,
        db.not_(PrivateMessage.to_user_id == current_user.id)).all()
    return render_template("pms/sent.html", messages=messages)
コード例 #4
0
ファイル: views.py プロジェクト: ulysseswolf/flaskbb
def inbox():
    messages = PrivateMessage.query.filter(
        PrivateMessage.user_id == current_user.id,
        PrivateMessage.draft == False,
        PrivateMessage.trash == False,
        db.not_(PrivateMessage.from_user_id == current_user.id)).all()
    return render_template("message/inbox.html", messages=messages)
コード例 #5
0
ファイル: views.py プロジェクト: marvinwu/flaskbb
def sent():
    messages = PrivateMessage.query.filter(
        PrivateMessage.user_id == current_user.id,
        PrivateMessage.draft == False,
        PrivateMessage.trash == False,
        db.not_(PrivateMessage.to_user_id == current_user.id)).all()
    return render_template("message/sent.html", messages=messages)
コード例 #6
0
    def get(self, user_id):
        user = User.query.filter_by(id=user_id).first_or_404()
        form = self.form(user)
        member_group = db.and_(
            * [
                db.not_(getattr(Group, p))
                for p in ['admin', 'mod', 'super_mod', 'banned', 'guest']
            ]
        )

        filt = db.or_(
            Group.id.in_(g.id for g in current_user.groups), member_group
        )

        if Permission(IsAtleastSuperModerator, identity=current_user):
            filt = db.or_(filt, Group.mod)

        if Permission(IsAdmin, identity=current_user):
            filt = db.or_(filt, Group.admin, Group.super_mod)

        if Permission(CanBanUser, identity=current_user):
            filt = db.or_(filt, Group.banned)

        group_query = Group.query.filter(filt)

        form.primary_group.query = group_query
        form.secondary_groups.query = group_query

        return render_template(
            'management/user_form.html', form=form, title=_('Edit User')
        )
コード例 #7
0
ファイル: views.py プロジェクト: eirnym/flaskbb
    def get(self, user_id):
        user = User.query.filter_by(id=user_id).first_or_404()
        form = self.form(user)
        member_group = db.and_(
            * [
                db.not_(getattr(Group, p))
                for p in ['admin', 'mod', 'super_mod', 'banned', 'guest']
            ]
        )

        filt = db.or_(
            Group.id.in_(g.id for g in current_user.groups), member_group
        )

        if Permission(IsAtleastSuperModerator, identity=current_user):
            filt = db.or_(filt, Group.mod)

        if Permission(IsAdmin, identity=current_user):
            filt = db.or_(filt, Group.admin, Group.super_mod)

        if Permission(CanBanUser, identity=current_user):
            filt = db.or_(filt, Group.banned)

        group_query = Group.query.filter(filt)

        form.primary_group.query = group_query
        form.secondary_groups.query = group_query

        return render_template(
            'management/user_form.html', form=form, title=_('Edit User')
        )
コード例 #8
0
ファイル: forms.py プロジェクト: vlttnv/flaskbb
    def validate_name(self, field):
        if hasattr(self, "group"):
            group = Group.query.filter(db.and_(Group.name.like(field.data), db.not_(Group.id == self.group.id))).first()
        else:
            group = Group.query.filter(Group.name.like(field.data)).first()

        if group:
            raise ValidationError(_("This Group name is already taken."))
コード例 #9
0
ファイル: forms.py プロジェクト: vlttnv/flaskbb
    def validate_guest(self, field):
        if hasattr(self, "group"):
            group = Group.query.filter(db.and_(Group.guest, db.not_(Group.id == self.group.id))).count()
        else:
            group = Group.query.filter_by(guest=True).count()

        if field.data and group > 0:
            raise ValidationError(_("There is already a Guest group."))
コード例 #10
0
ファイル: forms.py プロジェクト: vlttnv/flaskbb
    def validate_username(self, field):
        if hasattr(self, "user"):
            user = User.query.filter(db.and_(User.username.like(field.data), db.not_(User.id == self.user.id))).first()
        else:
            user = User.query.filter(User.username.like(field.data)).first()

        if user:
            raise ValidationError(_("This Username is already taken."))
コード例 #11
0
ファイル: views.py プロジェクト: FrontSide/flaskbb
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first()

    secondary_group_query = Group.query.filter(
        db.not_(Group.id == user.primary_group_id),
        db.not_(Group.banned == True),
        db.not_(Group.guest == True))

    form = EditUserForm(user)
    form.secondary_groups.query = secondary_group_query
    if form.validate_on_submit():
        user.username = form.username.data
        user.email = form.email.data
        user.birthday = form.birthday.data
        user.gender = form.gender.data
        user.website = form.website.data
        user.location = form.location.data
        user.signature = form.signature.data
        user.avatar = form.avatar.data
        user.notes = form.notes.data
        user.primary_group_id = form.primary_group.data.id

       # Don't override the password
        if form.password.data:
            user.password = form.password.data

        user.save(groups=form.secondary_groups.data)

        flash("User successfully edited", "success")
        return redirect(url_for("admin.edit_user", user_id=user.id))
    else:
        form.username.data = user.username
        form.email.data = user.email
        form.birthday.data = user.birthday
        form.gender.data = user.gender
        form.website.data = user.website
        form.location.data = user.location
        form.signature.data = user.signature
        form.avatar.data = user.avatar
        form.notes.data = user.notes
        form.primary_group.data = user.primary_group
        form.secondary_groups.data = user.secondary_groups

    return render_template("admin/edit_user.html", form=form)
コード例 #12
0
    def validate_username(self, field):
        if hasattr(self, "user"):
            user = User.query.filter(
                db.and_(User.username.like(field.data),
                        db.not_(User.id == self.user.id))).first()
        else:
            user = User.query.filter(User.username.like(field.data)).first()

        if user:
            raise ValidationError(_("This Username is already taken."))
コード例 #13
0
    def validate_guest(self, field):
        if hasattr(self, "group"):
            group = Group.query.filter(
                db.and_(Group.guest,
                        db.not_(Group.id == self.group.id))).count()
        else:
            group = Group.query.filter_by(guest=True).count()

        if field.data and group > 0:
            raise ValidationError(_("There is already a Guest group."))
コード例 #14
0
    def validate_name(self, field):
        if hasattr(self, "group"):
            group = Group.query.filter(
                db.and_(Group.name.like(field.data),
                        db.not_(Group.id == self.group.id))).first()
        else:
            group = Group.query.filter(Group.name.like(field.data)).first()

        if group:
            raise ValidationError(_("This Group name is already taken."))
コード例 #15
0
ファイル: forms.py プロジェクト: mcdir/flaskbb
    def validate_email(self, field):
        if hasattr(self, "user"):
            user = User.query.filter(
                db.and_(User.email.like(field.data),
                        db.not_(User.id == self.user.id))).first()
        else:
            user = User.query.filter(User.email.like(field.data)).first()

        if user:
            raise ValidationError("This email is taken")
コード例 #16
0
ファイル: forms.py プロジェクト: mcdir/flaskbb
    def validate_banned(self, field):
        if hasattr(self, "group"):
            group = Group.query.filter(
                db.and_(Group.banned == True,
                        db.not_(Group.id == self.group.id))).count()
        else:
            group = Group.query.filter_by(banned=True).count()

        if field.data and group > 0:
            raise ValidationError("There is already a Banned group")
コード例 #17
0
    def validate_email(self, field):
        if hasattr(self, "user"):
            user = User.query.filter(
                db.and_(User.email.like(field.data.lower()),
                        db.not_(User.id == self.user.id))).first()
        else:
            user = User.query.filter(User.email.like(
                field.data.lower())).first()

        if user:
            raise ValidationError(_("This email address is already taken."))
コード例 #18
0
ファイル: forms.py プロジェクト: RJacksonm1/flaskbb
    def validate_email(self, field):
        if hasattr(self, "user"):
            user = User.query.filter(
                db.and_(User.email.like(field.data),
                        db.not_(User.id == self.user.id)
                        )
            ).first()
        else:
            user = User.query.filter(User.email.like(field.data)).first()

        if user:
            raise ValidationError("This email is taken")
コード例 #19
0
ファイル: forms.py プロジェクト: RJacksonm1/flaskbb
    def validate_banned(self, field):
        if hasattr(self, "group"):
            group = Group.query.filter(
                db.and_(Group.banned == True,
                        db.not_(Group.id == self.group.id)
                        )
            ).count()
        else:
            group = Group.query.filter_by(banned=True).count()

        if field.data and group > 0:
            raise ValidationError("There is already a Banned group")
コード例 #20
0
    def get(self):

        page = request.args.get("page", 1, type=int)

        conversations = (Conversation.query.filter(
            Conversation.user_id == current_user.id,
            Conversation.draft == False,
            Conversation.trash == False,
            db.not_(Conversation.to_user_id == current_user.id),
        ).order_by(Conversation.date_modified.desc()).paginate(
            page, flaskbb_config["TOPICS_PER_PAGE"], False))

        return render_template("sent.html", conversations=conversations)
コード例 #21
0
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first_or_404()

    secondary_group_query = Group.query.filter(
        db.not_(Group.id == user.primary_group_id),
        db.not_(Group.banned == True), db.not_(Group.guest == True))

    form = EditUserForm(user)
    form.secondary_groups.query = secondary_group_query
    if form.validate_on_submit():
        form.populate_obj(user)
        user.primary_group_id = form.primary_group.data.id

        # Don't override the password
        if form.password.data:
            user.password = form.password.data

        user.save(groups=form.secondary_groups.data)

        flash("User successfully edited", "success")
        return redirect(url_for("admin.edit_user", user_id=user.id))
    else:
        form.username.data = user.username
        form.email.data = user.email
        form.birthday.data = user.birthday
        form.gender.data = user.gender
        form.website.data = user.website
        form.location.data = user.location
        form.signature.data = user.signature
        form.avatar.data = user.avatar
        form.notes.data = user.notes
        form.primary_group.data = user.primary_group
        form.secondary_groups.data = user.secondary_groups

    return render_template("admin/user_form.html",
                           form=form,
                           title="Edit User")
コード例 #22
0
ファイル: forms.py プロジェクト: eirnym/flaskbb
    def validate_email(self, field):
        if hasattr(self, "user"):
            user = User.query.filter(
                db.and_(
                    User.email.like(field.data.lower()),
                    db.not_(User.id == self.user.id)
                )
            ).first()
        else:
            user = User.query.filter(
                User.email.like(field.data.lower())
            ).first()

        if user:
            raise ValidationError(_("This email address is already taken."))
コード例 #23
0
    def get(self):

        page = request.args.get('page', 1, type=int)

        conversations = Conversation.query. \
            filter(
                Conversation.user_id == current_user.id,
                Conversation.draft == False,
                Conversation.trash == False,
                db.not_(Conversation.to_user_id == current_user.id)
            ).\
            order_by(Conversation.date_modified.desc()). \
            paginate(page, flaskbb_config['TOPICS_PER_PAGE'], False)

        return render_template("message/sent.html",
                               conversations=conversations)
コード例 #24
0
ファイル: views.py プロジェクト: zhy0313/hotface
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first_or_404()

    if not Permission(CanEditUser, identity=current_user):
        flash(_("You are not allowed to edit this user."), "danger")
        return redirect(url_for("management.users"))

    member_group = db.and_(*[
        db.not_(getattr(Group, p))
        for p in ['admin', 'mod', 'super_mod', 'banned', 'guest']
    ])

    filt = db.or_(Group.id.in_(g.id for g in current_user.groups),
                  member_group)

    if Permission(IsAtleastSuperModerator, identity=current_user):
        filt = db.or_(filt, Group.mod)

    if Permission(IsAdmin, identity=current_user):
        filt = db.or_(filt, Group.admin, Group.super_mod)

    if Permission(CanBanUser, identity=current_user):
        filt = db.or_(filt, Group.banned)

    group_query = Group.query.filter(filt)

    form = EditUserForm(user)
    form.primary_group.query = group_query
    form.secondary_groups.query = group_query
    if form.validate_on_submit():
        form.populate_obj(user)
        user.primary_group_id = form.primary_group.data.id

        # Don't override the password
        if form.password.data:
            user.password = form.password.data

        user.save(groups=form.secondary_groups.data)

        flash(_("User updated."), "success")
        return redirect(url_for("management.edit_user", user_id=user.id))

    return render_template("management/user_form.html",
                           form=form,
                           title=_("Edit User"))
コード例 #25
0
ファイル: views.py プロジェクト: 0xsKu/flaskbb
def sent():
    page = request.args.get('page', 1, type=int)

    conversations = Conversation.query.\
        filter(
            Conversation.user_id == current_user.id,
            Conversation.draft == False,
            Conversation.trash == False,
            db.not_(Conversation.to_user_id == current_user.id)
        ).\
        paginate(page, flaskbb_config['TOPICS_PER_PAGE'], False)

    message_count = Conversation.query.\
        filter(Conversation.user_id == current_user.id).\
        count()

    return render_template("message/sent.html", conversations=conversations,
                           message_count=message_count)
コード例 #26
0
ファイル: views.py プロジェクト: yonglehou/flaskbb
def sent():
    page = request.args.get('page', 1, type=int)

    conversations = Conversation.query.\
        filter(
            Conversation.user_id == current_user.id,
            Conversation.draft == False,
            Conversation.trash == False,
            db.not_(Conversation.to_user_id == current_user.id)
        ).\
        paginate(page, flaskbb_config['TOPICS_PER_PAGE'], False)

    message_count = Conversation.query.\
        filter(Conversation.user_id == current_user.id).\
        count()

    return render_template("message/sent.html", conversations=conversations,
                           message_count=message_count)
コード例 #27
0
ファイル: views.py プロジェクト: eirnym/flaskbb
    def post(self, user_id):
        user = User.query.filter_by(id=user_id).first_or_404()

        member_group = db.and_(
            * [
                db.not_(getattr(Group, p))
                for p in ['admin', 'mod', 'super_mod', 'banned', 'guest']
            ]
        )

        filt = db.or_(
            Group.id.in_(g.id for g in current_user.groups), member_group
        )

        if Permission(IsAtleastSuperModerator, identity=current_user):
            filt = db.or_(filt, Group.mod)

        if Permission(IsAdmin, identity=current_user):
            filt = db.or_(filt, Group.admin, Group.super_mod)

        if Permission(CanBanUser, identity=current_user):
            filt = db.or_(filt, Group.banned)

        group_query = Group.query.filter(filt)

        form = EditUserForm(user)
        form.primary_group.query = group_query
        form.secondary_groups.query = group_query
        if form.validate_on_submit():
            form.populate_obj(user)
            user.primary_group_id = form.primary_group.data.id

            # Don't override the password
            if form.password.data:
                user.password = form.password.data

            user.save(groups=form.secondary_groups.data)

            flash(_('User updated.'), 'success')
            return redirect(url_for('management.edit_user', user_id=user.id))

        return render_template(
            'management/user_form.html', form=form, title=_('Edit User')
        )
コード例 #28
0
ファイル: views.py プロジェクト: abshkd/flaskbb
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first_or_404()

    if not can_edit_user(current_user):
        flash(_("You are not allowed to edit this user."), "danger")
        return redirect(url_for("management.users"))

    member_group = db.and_(*[db.not_(getattr(Group, p)) for p in ['admin',
                                              'mod',
                                              'super_mod',
                                              'banned',
                                              'guest'
                                              ]])

    filt = db.or_(Group.id.in_(g.id for g in user.groups),
                   member_group)

    if any(user.permissions[p] for p in ['super_mod', 'admin']):
        filt = db.or_(filt, Group.mod)

    if user.permissions['admin']:
        filt = db.or_(filt, Group.admin, Group.super_mod)

    group_query = Group.query.filter(filt)

    form = EditUserForm(user)
    form.primary_group.query = group_query
    form.secondary_groups.query = group_query
    if form.validate_on_submit():
        form.populate_obj(user)
        user.primary_group_id = form.primary_group.data.id

        # Don't override the password
        if form.password.data:
            user.password = form.password.data

        user.save(groups=form.secondary_groups.data)

        flash(_("User successfully updated."), "success")
        return redirect(url_for("management.edit_user", user_id=user.id))

    return render_template("management/user_form.html", form=form,
                           title=_("Edit User"))
コード例 #29
0
ファイル: forms.py プロジェクト: PPPython/flaskbb
 def validate_email(self, field):
     user = User.query.filter(db.and_(
                              User.email.like(field.data),
                              db.not_(User.id == self.user.id))).first()
     if user:
         raise ValidationError(_("This E-Mail Address is already taken."))
コード例 #30
0
ファイル: forms.py プロジェクト: tknomanzr/codeclimatepyt
 def validate_email(self, field):
     user = User.query.filter(
         db.and_(User.email.like(field.data),
                 db.not_(User.id == self.user.id))).first()
     if user:
         raise ValidationError(_("This E-Mail Address is already taken."))