Forms

SignupForm

class diet_optimizer_website.forms.SignupForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)

Sign up form. Used to allow the user to create an account.

This form will ask the user for:

Parameters:
  • username – The user name the user wants to have on the website.
  • email – The email the website will use to contact the user.
  • password1 – The password the user will be using to connect to the website.
  • password2 – The password is asked twice to verify the user didn’t make any typo.

Note

Once filled, this form won’t directly create a User. You will need to fill The next form for the User to be created.

clean_email()

This function verifies if it has received something that is an email. If not it will generate an error. It then verifies if a User with this email already exists. If one does exist it will generate an error.

Returns:The email entered.
clean_password1()

This function verifies if the password entered has at least 6 characters. Else it will be considered too weak and generate an error.

Returns:the password entered in the first case.
clean_password2()

This function verifies if the password entered in password1 and password2 are the same. If not the user mistyped and the form will generate an error.

Returns:the password entered in the second case.
clean_username()

This function verifies if a User with this name already exists. If one does exist it will generate an error.

Returns:The username entered.
save(commit=True)

This function will create an user with the username and password given and store it in the database.

Returns:The user created.

PersonalDetailsForm

class diet_optimizer_website.forms.PersonalDetailsForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None)

Personal details form. Used to get some information about the user’s habits and his diet.

This form will ask the user for:

Parameters:
  • first_name – The first name of the user.
  • last_name – The last name of the user.
  • height – The user’s height. (used to calculate bmi)
  • weight – The user’s weight. (used to calculate bmi)
  • birth_date – The user’s birth date. (And thus his age)
  • activity_level – The user’s activity level. (To calculate his nutrients needs)
  • diet – The user’s diet.
  • gender – The user’s gender.
  • intolerences – The user’s intolerences.

LoginForm

class diet_optimizer_website.forms.LoginForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)

Log in form. Used to allow the user to log onto the website.

This form will ask the user for:

Parameters:
  • nick_name – The username of the user.
  • password – The password of the user.

Note

This form is outdated and not used in the website anymore. We now use django’s built-in login form.

clean_nick_name()

This function will get the username and check if a user with this username is in the database. If there is none or if the username given is not correct it will raise an error.

Returns:The nick_name entered
clean_password()

This function will get the password entered and verify it for the username entered.

If the password and user doesn’t match or if no password was entered it will raise an error.

Returns:The password entered.

PasswordResetRequestForm

class diet_optimizer_website.forms.PasswordResetRequestForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)

Password reset form. Used to allow the user to change is password if he forgot it.

This form will ask the user for:

Parameters:email – The user’s email.
clean_email()

This function will get the email entered and check if it has an email regular expression. If not it will raise an error.

Returns:The email entered.

SettingsForm

class diet_optimizer_website.forms.SettingsForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)

Settings form. Used to allow the user to change his personal settings.

This form will ask the user for:

Parameters:
  • height – The user’s height. (used to calculate bmi)
  • weight – The user’s weight. (used to calculate bmi)
  • birth_date – The user’s birth date. (And thus his age)
  • gender – The user’s gender.

AccountSettingsForm

class diet_optimizer_website.forms.AccountSettingsForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)

Account settings form. Allows the user to change his password simply.

This form will ask the user for:

Parameters:
  • new_password – The user’s new password.
  • new_password2 – The new password is asked twice to verify the user didn’t do any typo.
clean_new_password()

This function verifies if the password entered has at least 6 characters. Else it will be considered too weak and generate an error.

Returns:The new password entered in the first case.
clean_new_password2()

This function verifies if the password entered in new_password and new_password2 are the same. If not the user mistyped and the form will generate an error.

Returns:The new password entered in the second case.

TogglePopUpForm

class diet_optimizer_website.forms.TogglePopUpForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)

Toggle popups form. Allows the user to choose if he wants to receive popups from the website or not.

This form will ask the user for:

Parameters:accept_popup – Boolean representing if the user wants popups (True) or not (False)

GetRecipeForm

class diet_optimizer_website.forms.GetRecipeForm(user, *args, **kwargs)

Get recipe form. This form asks for all the information necessary to ask recipes to the website.

This form will ask the user for:

Parameters:
  • cuisines – List of types of cuisines the user agrees to eat. (ex: mexican, japanese,…)
  • recipeTypes – List of types if dishes the user wants to eat. (ex: deserts, main dish,…)
  • rawGroups – Raw kinds of foods the user agrees to eat. (ex: veal products, sweets,…)
  • objectiveNutrition – What nutrient does the user wants to focus on. (ex: carbs, fat,…)
  • objectiveMinMax – If the user wants to maximize this nutrient or minimize it.
  • calLow – Minimum amount of calories the user wants to have.
  • calUp – Maximum amount of calories the user wants to have.
  • carbLow – Minimum amount of carbohydrates the user wants to have.
  • carbUp – Maximum amount of carbohydrates the user wants to have.
  • protLow – Minimum amount of proteins the user wants to have.
  • protUp – Maximum amount of proteins the user wants to have.
  • fatLow – Minimum amount of fat the user wants to have.
  • fatUp – Maximum amount of fat the user wants to have.
  • time – The Maximum time the user has to cook.
clean_cuisines()

This function verifies if the cuisines field has been properly filled. Else it will generate an error.

Returns:the list of the cuisines that the user asked for.
clean_objectiveMinMax()

This function verifies if the objectiveMinMax field has been properly filled. Else it will generate an error.

Returns:If the user wants to maximize or minimize its objective.
clean_objectiveNutrition()

This function verifies if the objectiveNutrition field has been properly filled. Else it will generate an error.

Returns:The nutrition objective the user wants to focus on.
clean_rawGroups()

This function verifies if the rawGroups field has been properly filled. Else it will generate an error.

Returns:The list of the raw groups of foods the user asked for.
clean_recipeTypes()

This function verifies if the recipeTypes field has been properly filled. Else it will generate an error.

Returns:The list of the recipeTypes the user asked for.

UserProfileForm

class diet_optimizer_website.forms.UserProfileForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)

User profile form. This form allows the user to change all his settings concerning his diet and the recipes he prefers.

This form will ask the user for:

Parameters:
  • activity_level – The user’s activity level.
  • diet – The user’s diet.
  • intolerences – The list of the user’s intolerences.
  • cuisines – The User’s favorite types of cuisines.
  • rawGroups – The user’s favorite types of raw foods.
  • timetoCook – The user’s usual time he has to cook.