def User_Registration(request): if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user( username=form.cleaned_data["username"], email=form.cleaned_data["email"], password=form.cleaned_data["password"], ) user.save() # users = user.get.profile() # users.name = form.cleaned_data['name'] # users.birthday = form.cleaned_data['birthday'] # users.save() users = Users(user=user, name=form.cleaned_data["name"], birthday=form.cleaned_data["birthday"]) users.save() return HttpResponseRedirect("/") else: return render_to_response("RegisterUser.html", {"form": form}, context_instance=RequestContext(request)) else: """ user is not submitting the form, show them a blank registration form """ form = RegistrationForm() context = {"form": form} return render_to_response("RegisterUser.html", context, context_instance=RequestContext(request))
def create_user(username, password, first_name, last_name, risk_status, cash_amount): new_user = Users(username=username, password=password, first_name=first_name, last_name=last_name, risk_status=risk_status, cash_amount=cash_amount) init_share = Shares(username=new_user, risk_status=new_user.risk_status, cash_amount=new_user.cash_amount) new_user.save() init_share.save()
def signup(): """ Handle requests to the /signup route Add an user to the database through the registration form """ if current_user.is_authenticated: return redirect(url_for('dashboard.index')) formSignUp = SignupForm() if request.method == 'POST' and formSignUp.validate_on_submit(): _user = Users(mark_active=formSignUp.accept_tos.data, username=formSignUp.username.data, email=formSignUp.email.data, password=formSignUp.password.data) try: db.session.add(_user) db.session.commit() flash(u'You account has been created.', 'success') except Exception as e: flash(u'Can\'t add account to the database.' + str(e), 'error') return redirect(url_for('auth.signin')) return render_template('auth/signup.html', title='Sign Up | Auth', form=formSignUp)
def create_user(): if request.method == "POST": data = request.get_json(force=True) user = Users(data["name"]) db.session.add(user) db.session.commit() db.create_all() return "hello"
def users_page(): users = Users.query.all() form = UserAddForm() if form.validate_on_submit(): newUser = Users(username=form.username.data, age=form.age.data) db.session.add(newUser) db.session.commit() flash(f"{newUser.username} has been added!", "success") return redirect(url_for("users_bp.users_page")) form.username.data = '' form.age.data = '' return render_template("users.html", users=users, form=form, title="ulanyjylar tablisasy")
def save(self, commit=True): user = super(RegistrationForm, self).save(commit=False) user.first_name = self.cleaned_data['first'] user.last_name = self.cleaned_data['last'] user.email = self.cleaned_data['email'] #user.save() if commit: user.save() a = User.objects.get(id=user.id) newusr = Users() newusr.usr_acct = a newusr.isEnrolled = self.cleaned_data['enrled'] newusr.isFaculty = self.cleaned_data['fclty'] deg = Degrees.objects.all() deg = deg[0] newusr.degree = deg newusr.save() return user
import json import os from main.models import Users, Products directory = os.environ['dir'] with open(f'{directory}/users.json', 'r') as users: data = json.load(users) for value in data: users = Users(first_name=value['first_name'], last_name=value['last_name'], birthdate=value['birthdate']) users.save() with open(f'{directory}/products.json') as products: data = json.load(products) for value in data: products = Products(price=value['price'], title=value['title'], description=value['description'], base_discount_percent=value['base_discount_percent']) products.save()
from main import db, create_app from main.models import (Resource, Users) app = create_app() app.app_context().push() db.drop_all() db.create_all() resource = Resource() resource.ResName = "hello" db.session.add(resource) db.session.commit() user = Users() user.username = "******" user.age = 22 db.session.add(user) db.session.commit() user = Users() user.username = "******" user.age = 21 db.session.add(user) db.session.commit()