Commit 507432f4 authored by Floréal Cabanettes's avatar Floréal Cabanettes

Rename text_cons -> text_prop

parent bb1b73e4
......@@ -97,8 +97,8 @@ def add_instruction():
def add_proposal():
global nb_proposal, recipe
nb_proposal += 1
text_cons = input("Text: ")
CProposal.add_new_to_recipe(text_cons, nb_proposal, recipe)
text_prop = input("Text: ")
CProposal.add_new_to_recipe(text_prop, nb_proposal, recipe)
what_to_do_next()
choice = int(input("Choice: "))
......
......@@ -4,12 +4,12 @@ from main.functions.exceptions import RequiredParameterException, MissingKeyExce
class CProposal:
@staticmethod
def add_new_to_recipe(text_cons: str, nb: int, recipe: Recipe) -> Proposal:
def add_new_to_recipe(text_prop: str, nb: int, recipe: Recipe) -> Proposal:
# Test parameters:
if text_cons is not None and (not isinstance(text_cons, str)):
raise TypeError("text_cons must be a string")
if text_cons is None or len(text_cons) == 0:
raise RequiredParameterException("text_cons is required and must be not empty")
if text_prop is not None and (not isinstance(text_prop, str)):
raise TypeError("text_prop must be a string")
if text_prop is None or len(text_prop) == 0:
raise RequiredParameterException("text_prop is required and must be not empty")
if nb is not None and (not isinstance(nb, int)):
raise TypeError("nb must be an integer")
if nb is None:
......@@ -20,7 +20,7 @@ class CProposal:
raise RequiredParameterException("recipe is required")
# Do the add:
p = Proposal(text_cons=text_cons, nb=nb, recipe=recipe)
p = Proposal(text_prop=text_prop, nb=nb, recipe=recipe)
p.save()
return p
......@@ -35,17 +35,17 @@ class CProposal:
else:
for proposal in proposals:
req_keys = {
"text_cons": False,
"text_prop": False,
"nb": False
}
for key, value in proposal.items():
if key in req_keys:
req_keys[key] = True
if key == "text_cons":
if key == "text_prop":
if value is not None and (not isinstance(value, str)):
raise TypeError("proposal: text_cons must be a string")
raise TypeError("proposal: text_prop must be a string")
if value is None or len(value) == 0:
raise RequiredParameterException("proposal: text_cons must be not none or empty")
raise RequiredParameterException("proposal: text_prop must be not none or empty")
elif key == "nb":
if value is not None and (not isinstance(value, int)):
raise TypeError("proposal: nb must be an integer")
......@@ -64,7 +64,7 @@ class CProposal:
# Do the add:
p_list = []
for proposal in proposals:
p_list.append(CProposal.add_new_to_recipe(proposal["text_cons"], proposal["nb"], recipe))
p_list.append(CProposal.add_new_to_recipe(proposal["text_prop"], proposal["nb"], recipe))
return p_list
......@@ -84,7 +84,7 @@ class CProposal:
html = "<ul>"
for p in proposals:
html += "<li>" + p.text_cons + "</li>"
html += "<li>" + p.text_prop + "</li>"
html += "</ul>"
return html
......@@ -193,7 +193,7 @@ class CRecipe:
proposals = []
for prop in recipe.proposal_set.all():
proposal = {
"text_prop": prop.text_cons,
"text_prop": prop.text_prop,
"nb": prop.nb
}
proposals.append(proposal)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('main', '0008_auto_20170115_1549'),
]
operations = [
migrations.RenameField(
model_name='proposal',
old_name='text_cons',
new_name='text_prop',
),
]
......@@ -4,7 +4,7 @@ from .Recipe import Recipe
class Proposal(models.Model):
nb = models.IntegerField()
text_cons = models.TextField()
text_prop = models.TextField()
recipe = models.ForeignKey(Recipe)
class Meta:
......
......@@ -149,7 +149,7 @@ class TModels(TestCase):
def test_add_new_proposal(self):
r = self.add_new_recipe_minimalist()
p = CProposal.add_new_to_recipe("My proposal 1", 0, r)
p_get = Proposal.objects.get(text_cons="My proposal 1")
p_get = Proposal.objects.get(text_prop="My proposal 1")
self.assertIs(p_get.id is None, False)
vars_orig = vars(p)
vars_get = vars(p_get)
......@@ -160,16 +160,16 @@ class TModels(TestCase):
def test_ann_new_proposal_list_to_recipe(self):
proposals = [{
"text_cons": "My proposal 2",
"text_prop": "My proposal 2",
"nb": 1
}, {
"text_cons": "My proposal 3",
"text_prop": "My proposal 3",
"nb": 2
}]
r = self.add_new_recipe_minimalist()
p_list = CProposal.add_new_list_to_recipe(proposals, r)
for p in p_list:
p_get = Proposal.objects.get(text_cons=p.text_cons)
p_get = Proposal.objects.get(text_prop=p.text_prop)
self.assertIs(p_get.id is None, False)
vars_orig = vars(p)
vars_get = vars(p_get)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment