def mutate(cls, self, info, **kwargs):
        kwargs = input_to_dictionary(kwargs)
        data = kwargs.get("input")
        print(data)
        user = User()
        user.name = data.get("name", "defautltname")
        user.password = data.get("password")

        for _id in data.get("roles", []):
            rid = from_global_id(_id)[1]
            user.roles = [Role.query.get(rid) for i in data.get("roles")]
        db.session.add(user)
        db.session.commit()
        user = User.query.get(user.id)
        return cls(output=user, ok=True, message="操作成功")
示例#2
0
 def test_fields_and_nested_index(self):
     u = yield User({'name': 'Test', 'age': 24}).save(self.db)
     m = Event
     yield m.ensure_index(self.db)
     e = m({'title': 'Something', 'user': u})
     yield e.save(self.db)
     index_info = yield self.db[e._options.namespace].index_information()
     self.assertIn('title_1_user.name_1', index_info)
示例#3
0
def signup():
    form = SignupForm(request.form)
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data)
        user.set_password(form.password.data)
        try:
            db.session.add(user)
            db.session.commit()
            flash(
                f"Hello, {user.first_name} {user.last_name}. You are signed up."
            )
        except IntegrityError:
            db.session.rollback()
            flash(f'Error, unable to register {form.email.data}. ', 'error')
            return redirect(url_for('auth.signup'))
        return redirect(url_for('main.index'))
    return render_template('signup.html', title='Sign Up', form=form)
示例#4
0
def example_action_view(request):
    with DeltaLogger(User, Organization):
        user = User(first_name='x')
        user.save()
        user.last_name = 'y'
        user.save()
        org = Organization(name='A', slug='a')
        org.save()
        org.name = 'B'
        org.save()
        org.delete()
    return JsonResponse({'success': True}, encoder=JsonEncoder, safe=False)
示例#5
0
    def mutate(cls, self, info, **kwargs):
        kwargs = input_to_dictionary(kwargs)
        data = kwargs.get("input")
        print(data)
        user = User()
        user.username = data.get("username")
        user.email = data.get("email")
        user.phone = data.get("phone")
        user.ccode = data.get("ccode")

        db.session.add(user)
        db.session.commit()
        user = User.query.get(user.id)
        return cls(output=user, ok=True, message="correct")
示例#6
0
文件: base.py 项目: st4lk/TurboKit
 def _create_user(self):
     um = User(dict(name=self.get_random_string(), age=randint(20, 50)))
     yield um.save(self.db)
     raise gen.Return(um)