def handle(self, *args, **options): # create Ingredients Ingredient(ingredient_name="Hefe", price_per_unit=0.014, unit="g").save() Ingredient(ingredient_name="Wasser", price_per_unit=0.01, unit="l").save() Ingredient(ingredient_name="Eier", price_per_unit=0.17, unit="Stück").save() Ingredient(ingredient_name="Zucker", price_per_unit=0.00065, unit="g").save() Ingredient(ingredient_name="Salz", price_per_unit=0.014, unit="Prise").save() Ingredient(ingredient_name="Milch", price_per_unit=0.014, unit="1").save() butter = Ingredient(ingredient_name="Butter", price_per_unit=0.01, unit="g") butter.save() mehl = Ingredient(ingredient_name="Mehl", price_per_unit=0.49, unit="kg") mehl.save() # create SuperUser superuser = User.objects.create_superuser('superuser', '*****@*****.**', 'hallo123') # create NormalUsers user_georg = User.objects.create_user('Bäckerei ungebunden', password='******') user_georg.first_name = "Georg" user_georg.last_name = "Ungebunden" user_georg.save() # create Bakery-Profile UserProfile(user=user_georg, bakery_name="Bäckerei ungebunden", adress_street="Musterstraße", adress_street_number=10, adress_plz="0815", adress_city="Mosbach").save() # create Recipes kuchen = Recipe(rezept_bezeichnung="Kuchen", benutzer=user_georg) kuchen.save() mehlsack = Recipe(rezept_bezeichnung="Sackvoll Mehl", benutzer=superuser) mehlsack.save() # create RecipeIngredients RecipeList(recipe=kuchen, ingredient=butter, amount=300).save() RecipeList(recipe=kuchen, ingredient=mehl, amount=0.5).save() RecipeList(recipe=mehlsack, ingredient=mehl, amount=100).save() print("Inserted sample entries into the database.")
def test_student_edit_info_leak(self): c = Client() t_email, t_pass = signup_teacher_directly() c.login(email=t_email, password=t_pass) profile = UserProfile(user=User.objects.create_user("test")) profile.save() stu = Student(user=profile) stu.save() self.assertEqual( c.get(reverse("teacher_edit_student", kwargs={"pk": "9999"})).status_code, c.get(reverse("teacher_edit_student", kwargs={"pk": stu.pk})).status_code, )
def register(request): unidades = Empresa.objects.all().order_by('nome_fantasia') if request.method == 'POST': user_form = RegistroForm(request.POST) if user_form.is_valid(): User.objects.create_user( username=user_form.cleaned_data['username'], password=user_form.cleaned_data['password'], email=user_form.cleaned_data['email'], first_name=user_form.cleaned_data['first_name'], # last_name=user_form.cleaned_data['last_name'], is_active=False, ) id = request.POST['SelectUnidade'] empresa = get_object_or_404(Empresa, id=id) usuario = get_object_or_404( User, username=user_form.cleaned_data['username']) profile = UserProfile() profile.user = usuario profile.empresa = empresa profile.siape = int(request.POST['username']) profile.save() email = [] email_user = [] email.append(empresa.email_responsavel_sistema) email_user.append(usuario.email) ResponsavelUsuarioMail(usuario).send(email) RegistraUsuarioMail(usuario).send(email_user) return redirect('login_register_success') user_form = RegistroForm() context = {'user_form': user_form, 'unidades': unidades} return render(request, 'registration/login.html', context)
def my_data(request): user = User.objects.get(pk=request.user.pk) user_form = UserForm(instance=user) try: user_profile = UserProfile.objects.get(user=user) except: user_profile = UserProfile() user_profile.user = user user_profile.save() profile_form = UserProfileForm(instance=user_profile) if request.method == 'POST': user_form = UserForm(request.POST) profile_form = UserProfileForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): user.first_name = user_form.cleaned_data['first_name'] user.last_name = user_form.cleaned_data['last_name'] user.save() user_profile.cpf = profile_form.cleaned_data['cpf'] user_profile.address = profile_form.cleaned_data['address'] user_profile.number = profile_form.cleaned_data['number'] user_profile.address2 = profile_form.cleaned_data['address2'] user_profile.city = profile_form.cleaned_data['city'] user_profile.district = profile_form.cleaned_data['district'] user_profile.state = profile_form.cleaned_data['state'] user_profile.country = profile_form.cleaned_data['country'] user_profile.zipcode = profile_form.cleaned_data['zipcode'] user_profile.phone = profile_form.cleaned_data['phone'] user_profile.remote_receiver_id = profile_form.cleaned_data[ 'remote_receiver_id'] user_profile.save() context = { 'user_form': user_form, 'profile_form': profile_form, 'user': user } return render(request, 'portal/my_data.html', context)
def create_remote_customer(self, user): try: profile = user.userprofile except: profile = UserProfile() profile.user = user profile.save() if not profile.remote_customer_id: data = {'email': user.email} customer = Customer() res = customer.create(data) if res['id']: user.userprofile.remote_customer_id = res['id'] user.userprofile.save() if user.userprofile.remote_customer_id: return user return False
def create_remote_costumer(self, user): try: profile = user.userprofile except: profile = UserProfile() profile.user = user profile.save() if not profile.remote_costumer_id: data = { 'email': user.email, 'name': user.first_name + user.last_name, } customer = Customer() res = customer.create(data) if res['id']: user.userprofile.remote_costumer_id = res['id'] user.userprofile.save() if user.userprofile.remote_costumer_id: print('yeahh') return user return False