Views

diet_optimizer_website.views.about(request)

About view

This view simply renders the about page, giving information about the website to the users.

diet_optimizer_website.views.about_logged_in(request)

About view

This view simply renders the about page, giving information about the website to the users.

diet_optimizer_website.views.account_settings(request)

Account settings view

This view allows the user to change his password, or the fact that he can receive popups or not. It will first load the user’s data. If the view is accessed via GET method it will simply load both forms and render the page. If the view is accessed via POST method it will fill first check which form has been filled. For each form, if it has been filled it will check if the data has been correctly entered. If the data is valid it will create a confirmation message and change all the entered data to update the user’s information. If the data is not valid however it will create an error message and reload the page and ask the user to enter data properly.

diet_optimizer_website.views.delete_recipes_in_db(request, pk)

“delete recipes in db view.

This view allows the user to delete recipes from his saved recipes whenever he tried them. He will be able to have access to it again using the history page.

Parameters:pk – The primary key of the recipes that should be deleted from the database.

The view will just load the recipes he selected to delete and remove them from the database.

diet_optimizer_website.views.get_recipe(request)

Get recipe view.

This view allows the user to enter all the information necessary to search recipes. It will first gather all possible data concerning the user’s preferences. It will then load all the names of the recipes the user liked.

Finally it will create a form to get recipes and fill it with the user’s preferences. Finally it will simply render the page.

diet_optimizer_website.views.get_recipe_confirm(request)

Get recipe confirmation view.

This view is used to check if the raw foods asked by the user generally corresponds to what he can eat. It will first load the user’s intolerences and diet. It will load the data given in the GetRecipeForm to see what the user asked for. If the data is not valid it will redirect the user to get_recipe to ask him to enter data properly. However if the data is valid, the view will create a list of every types of foods the user would not want to eat according to his diet and intolerences. Once this list is done it will check if the foods the user asked for are in this list. If any of these foods are asked the view will return the variable launch_popup as true (to say a popup should appear to warn the user) It will also return the foods that pose a problem. Else it will send launch_popup as false and an empty list.

Returns:A boolean saying of the user wants to receive popups. And a list fo all the groups of foods that pose a problem with the user’s search.
diet_optimizer_website.views.history_not_tried(request)

History not tried view

This view allows the user to see all the recipes and raw foods the website advised him to try. It will first load all the Feedback objects linked to the user. Then it will load all the data about the recipes and the raw foods in the feedbacks. If the view is accessed via GET method it will simply render the page. If the view is accessed via POST method it will check for each recipe and raw food if its mark changed. If it did change it will update the number of likes and dislikes it currently has. Then it will update accordingly it’s percentage of likes.

diet_optimizer_website.views.history_tried(request)

History of tried recipes view

This view allows the user to see all the recipes and raw foods he tried. It will first load all the Feedback objects linked to the user. Then it will load all the data about the recipes and the raw foods in the feedbacks. If the view is accessed via GET method it will simply render the page. If the view is accessed via POST method it will check for each recipe and raw food if its mark changed. If it did change it will update the number of likes and dislikes it currently has. Then it will update accordingly it’s percentage of likes.

diet_optimizer_website.views.home(request)

Home view.

This view doesn’t do much. However django needs a home view to function properly.

diet_optimizer_website.views.index(request)

Index view.

This view only renders the index template, which corresponds to the first page the user will see on the website.

diet_optimizer_website.views.logout_view(request)

Logout view.

This view simply logs out the user and redirects him to the index page.

diet_optimizer_website.views.maketrans()

Return a translation table usable for str.translate().

If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

view to show the most pupular recipes and foods.

This view allows the user to see what are the most liked recipes and foods. It will simply load the 5 most liked recipes and foods and render the page.

diet_optimizer_website.views.personal_details(request)

User information to create a new user.

This view corresponds to the second part of the sign up process. If it is accessed via GET method, it will simply load the personal details form and render the page. If it is accessed via POST method, it will read the information send via the personal details form and check if it is valid.

If the information is valid, it will read the user details sent by the signup view (above) and create a User with this data. Then it will create a UserDB object linked to the User just created. It will then fill all the necessary informations given concerning both the User and the UserDB. Next it will read the intolerences and for each, create an Intolerence object with the User and the name. Finally it will redirect the user to the login page.

If the information is not valid however it will re-render the page asking to fill the form correctly.

diet_optimizer_website.views.personal_settings(request)

personal settings view

This view allows the user to change his personal settings like gender, birth_date or weight and height, etc. It will first load the user’s data and put them in the settings form. (this allows the form to be initially filled with the user’s data). If the view is accessed via GET method it will simply render the page. If the view is accessed via POST method it will fill the form with the posted data and check if it is valid. If the data is valid it will change all the entered data to update the user’s information. If the data is not valid however it will reload the page and ask the user to enter data properly.

diet_optimizer_website.views.profile(request)

Profile view.

This view will simply load all the information about the user and send them to the page.

diet_optimizer_website.views.results(request, need_verification)

Results view

This view will give the user’s the results found for his research.

Parameters:need_verification – A simple integer (0 or 1) telling if the research should be verified(1) or not(0).

It will start by loading all the user’s data. Includng his daily nutrient needs. Then it will load the data entered in the GetRecipeForm to know what kind of recipes to search for. If this data is not valid it will redirect the user to get recipe to ask him to enter data properly. It will then check if the research needs to be verified. If it does it will launch get_recipe_confirm (above) If launch popup is true it means some asked foods will be a problem and the view will redirect the user on get_recipe to inform him via a popup. It will then search in the kinds of food asked if some raw foods correspond to the user’s demands and, for each of those foods, create a Feedback object for this user. Once it has searched for foods it will gather all the necessary information to prepare for the recipe search. Additionnaly, if the user asked for a peculiar recipe it will gather it’s data first. The view will then search all the potential recipes it could use to optimize the search and use those recipes to calculate the best set of recipes he could propose to the user. For each of those recipes, the view will create a Feedback object for the user. Finally it will render the page to show those recipes and foods.

diet_optimizer_website.views.save_recipes_in_db(request)

Save recipes in d view.

This view allows the user to select a list of recipes proposed by the website and save them so that he can access them later. The recipes are stored by day and it is possible to store several days.

The view will gather the recipes and nutrients in the session data and save those information in the database.

diet_optimizer_website.views.saved_recipes(request)

Saved recipes view.

This view allows the user to see the recipes he has saved. Thus he can have acces to the recipes he intended to try at any moment.

The view will load all the recipes the user saved and their related nutrients. It will then load the page with this data.

diet_optimizer_website.views.signup(request)

User creation view.

This view corresponds to the first part of the sign up process. If it is accessed via GET method it will simply load the first signup form and render the page. If it is accessed via POST method, it will read the information send via the sign up form and check if it is valid. If the information is valid it will create a dictionnary containing the user’s information and send it to the next signup step. If the information is not valid however it will re-render the page asking to fill the form correctly.

diet_optimizer_website.views.user_profile(request)

personal settings view

This view allows the user to change his preferences, objectives and intolerences. It will first load the user’s data, intolerences and favorites and put them in the settings form. (this allows the form to be initially filled with the user’s data). If the view is accessed via GET method it will simply render the page. If the view is accessed via POST method it will fill the form with the posted data and check if it is valid. If the data is valid it will change all the entered data to update the user’s information. If the data is not valid however it will reload the page and ask the user to enter data properly.