Commit 1ddf120a authored by Floréal Cabanettes's avatar Floréal Cabanettes

Refactor: add a django form besides panel recipe form

parent 57c39dc3
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-01-07 19:17+0100\n"
"PO-Revision-Date: 2018-01-07 19:18+0100\n"
"POT-Creation-Date: 2018-04-22 16:05+0200\n"
"PO-Revision-Date: 2018-04-22 16:05+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
......@@ -35,8 +35,8 @@ msgid "Unexpected error: "
msgstr "Erreur inattendue :"
#. Translators: recipe is the parent tag of a recipe
#: api/views/RecipeById.py:49 api/views/RecipeList.py:39 panel/urls.py:47
#: templates/website/index.html:18 website/urls.py:22
#: api/views/RecipeById.py:49 api/views/RecipeList.py:39 panel/urls.py:50
#: templates/website/index.html:18 website/urls.py:25
msgid "recipe"
msgstr "recette"
......@@ -83,15 +83,15 @@ msgstr "Préparation :"
msgid "Proposals:"
msgstr "Conseils :"
#: main/config/RecipeConfig.py:17 templates/panel/recipe.html:68
#: main/config/RecipeConfig.py:17
msgid "Prep:"
msgstr "Temps de préparation :"
#: main/config/RecipeConfig.py:18 templates/panel/recipe.html:92
#: main/config/RecipeConfig.py:18
msgid "Cook:"
msgstr "Temps de cuisson :"
#: main/config/RecipeConfig.py:19 templates/panel/recipe.html:79
#: main/config/RecipeConfig.py:19
msgid "Break:"
msgstr "Temps de repos :"
......@@ -112,7 +112,7 @@ msgstr "ordre"
msgid "Category"
msgstr "Catégorie"
#: main/models/Category.py:16 templates/panel/recipe.html:52
#: main/models/Category.py:16 panel/forms.py:23 templates/panel/recipe.html:52
#: templates/panel/recipes.html:93 templates/panel/recipes.html:176
#: templates/panel/sidebar.html:31 templates/website/sidebar.html:9
msgid "Categories"
......@@ -189,7 +189,7 @@ msgstr "activer les commentaires"
msgid "published"
msgstr "publié"
#: main/models/Recipe.py:39 panel/urls.py:22 panel/urls.py:24
#: main/models/Recipe.py:39 panel/urls.py:25 panel/urls.py:27
msgid "trash"
msgstr "corbeille"
......@@ -207,23 +207,60 @@ msgstr "Recette"
msgid "Recipes"
msgstr "Recettes"
#: panel/urls.py:18 panel/urls.py:19 panel/urls.py:22 panel/urls.py:24
#: panel/urls.py:28 panel/urls.py:30 panel/urls.py:34 panel/urls.py:36
#: panel/urls.py:40
#: panel/forms.py:20 templates/panel/recipes.html:87
#: templates/panel/recipes.html:170
msgid "Title"
msgstr "Titre"
#: panel/forms.py:21
msgid "Slug"
msgstr "Permalien"
#: panel/forms.py:27 panel/forms.py:30 panel/forms.py:32
msgid "hours"
msgstr "heures"
#: panel/forms.py:28 panel/forms.py:31 panel/forms.py:33
msgid "minutes"
msgstr "minutes"
#: panel/forms.py:29
msgid "days"
msgstr "jours"
#: panel/forms.py:34
msgid "Description"
msgstr "Description"
#: panel/forms.py:35
msgid "Publication date"
msgstr "Date de publication"
#: panel/forms.py:38
msgid "Status"
msgstr "Statut"
#: panel/forms.py:39 templates/panel/recipes.html:154
msgid "Draft"
msgstr "Brouillon"
#: panel/urls.py:21 panel/urls.py:22 panel/urls.py:25 panel/urls.py:27
#: panel/urls.py:31 panel/urls.py:33 panel/urls.py:37 panel/urls.py:39
#: panel/urls.py:43
msgid "recipes"
msgstr "recettes"
#: panel/urls.py:19 panel/urls.py:24 panel/urls.py:30 panel/urls.py:36
#: website/urls.py:14 website/urls.py:16 website/urls.py:19
#: panel/urls.py:22 panel/urls.py:27 panel/urls.py:33 panel/urls.py:39
#: website/urls.py:17 website/urls.py:19 website/urls.py:22
msgid "page"
msgstr "page"
#: panel/urls.py:28 panel/urls.py:30
#: panel/urls.py:31 panel/urls.py:33
msgctxt "url"
msgid "mine"
msgstr "moi"
#: panel/urls.py:34 panel/urls.py:36
#: panel/urls.py:37 panel/urls.py:39
msgctxt "url"
msgid "published"
msgstr "publie"
......@@ -233,7 +270,7 @@ msgstr "publie"
msgid "User panel"
msgstr "Panel utilisateur"
#: panel/views/RecipeView.py:37
#: panel/views/RecipeView.py:56
msgid "Edit"
msgstr "Éditer"
......@@ -295,71 +332,39 @@ msgstr "Derniers commentaires"
msgid "Show recipe"
msgstr "Afficher la recette"
#: templates/panel/recipe.html:36 templates/panel/recipes.html:87
#: templates/panel/recipes.html:170
msgid "Title"
msgstr "Titre"
#: templates/panel/recipe.html:44
msgid "Slug"
msgstr "Permalien"
#: templates/panel/recipe.html:72 templates/panel/recipe.html:85
#: templates/panel/recipe.html:96
msgid "hours"
msgstr "heures"
#: templates/panel/recipe.html:74 templates/panel/recipe.html:87
#: templates/panel/recipe.html:98
msgid "minutes"
msgstr "minutes"
#: templates/panel/recipe.html:83
msgid "days"
msgstr "jours"
#: templates/panel/recipe.html:103
msgid "Description"
msgstr "Description"
#: templates/panel/recipe.html:111
msgid "Publication date"
msgstr "Date de publication"
#: templates/panel/recipe.html:66
msgid "Prep"
msgstr "Temps de préparation"
#: templates/panel/recipe.html:124
msgid "Status"
msgstr "Statut"
#: templates/panel/recipe.html:75
msgid "Break"
msgstr "Temps de repos"
#: templates/panel/recipe.html:128
msgctxt "singular"
msgid "Published"
msgstr "Publié"
#: templates/panel/recipe.html:129 templates/panel/recipes.html:154
msgid "Draft"
msgstr "Brouillon"
#: templates/panel/recipe.html:85
msgid "Cook"
msgstr "Temps de cuisson"
#: templates/panel/recipe.html:135
#: templates/panel/recipe.html:123
msgid "Save & Quit"
msgstr "Enregistrer & Quitter"
#: templates/panel/recipe.html:136
#: templates/panel/recipe.html:124
msgid "Save"
msgstr "Enregistrer"
#: templates/panel/recipe.html:137
#: templates/panel/recipe.html:125
msgid "Cancel"
msgstr "Annuler"
#: templates/panel/recipe.html:139
#: templates/panel/recipe.html:127
msgid "Want to edit the full recipe? Please use the"
msgstr "Vous souhaitez éditer la recette complète ? Veuillez utiliser le"
#: templates/panel/recipe.html:140
#: templates/panel/recipe.html:128
msgid "QRecipeWriter software"
msgstr "logiciel QRecipeWriter"
#: templates/panel/recipe.html:141
#: templates/panel/recipe.html:129
msgid "(available for Windows and Linux)"
msgstr "(disponible pour Windows et Linux)"
......@@ -615,8 +620,8 @@ msgid "header-categories.png"
msgstr "header-categories-fr.png"
#. Translators: category url
#: templates/website/sidebar.html:11 website/urls.py:15 website/urls.py:16
#: website/views/RecipeView.py:87
#: templates/website/sidebar.html:11 website/urls.py:18 website/urls.py:19
#: website/views/RecipeView.py:88
msgctxt "category url"
msgid "category"
msgstr "categorie"
......@@ -641,7 +646,7 @@ msgstr "Site web"
msgid "Comment"
msgstr "Commentaire"
#: website/urls.py:18 website/urls.py:19
#: website/urls.py:21 website/urls.py:22
msgctxt "author url"
msgid "author"
msgstr "auteur"
......@@ -650,6 +655,10 @@ msgstr "auteur"
msgid "Author:"
msgstr "Auteur :"
#~ msgctxt "singular"
#~ msgid "Published"
#~ msgstr "Publié"
#~ msgid "Online"
#~ msgstr "En ligne"
......
from django import forms
from django.utils.translation import ugettext as _, pgettext as __
from main.models.Category import Category
class BaseForm(forms.Form):
def __init__(self, *args, **kwargs):
super(BaseForm, self).__init__(*args, **kwargs)
for bound_field in self:
if hasattr(bound_field, "field") and bound_field.field.required:
bound_field.field.widget.attrs["required"] = "required"
if isinstance(bound_field.field, forms.CharField) or isinstance(bound_field.field, forms.IntegerField) or \
isinstance(bound_field.field.widget, forms.Select):
bound_field.field.widget.attrs["class"] = ((bound_field.field.widget.attrs["class"] + " ")
if "class" in bound_field.field.widget.attrs else "") + \
"form-control"
class RecipeForm(BaseForm):
title = forms.CharField(label=_('Title'), max_length=255, required=True)
slug = forms.CharField(label=_("Slug"), max_length=255, required=True)
categories = forms.MultipleChoiceField(
label=_('Categories'),
choices=[(cat.id, cat.name) for cat in Category.objects.order_by('order')],
widget=forms.CheckboxSelectMultiple
)
tps_prep_hr = forms.IntegerField(label=_("hours"), min_value=0)
tps_prep_min = forms.IntegerField(label=_("minutes"), min_value=0, max_value=59, required=True)
tps_break_j = forms.IntegerField(label=_("days"), min_value=0)
tps_break_hr = forms.IntegerField(label=_("hours"), min_value=0, max_value=23)
tps_break_min = forms.IntegerField(label=_("minutes"), min_value=0, max_value=59)
tps_cook_hr = forms.IntegerField(label=_("hours"), min_value=0)
tps_cook_min = forms.IntegerField(label=_("minutes"), min_value=0, max_value=59, required=True)
description = forms.CharField(label=_("Description"), widget=forms.Textarea())
pub_date = forms.CharField(label=_("Publication date"),
widget=forms.TextInput(attrs={"class": "datemask datepicker"}))
status = forms.MultipleChoiceField(
label=_('Status'),
choices=[(1, __("singular", "Published")), (0, _("Draft"))],
widget=forms.Select
)
......@@ -197,15 +197,21 @@ form#recipe-form textarea {
resize: vertical;
}
form#recipe-form label.category {
form#recipe-form div.categories label {
font-weight: normal;
}
form#recipe-form input.time-details {
form#recipe-form td.time input {
width: 100px;
display: inline-block;
}
form#recipe-form td.time label {
min-width: 60px;
text-align: center;
font-weight: normal;
}
form#recipe-form span.label-time {
display: inline-block;
min-width: 60px;
......
......@@ -5,6 +5,8 @@ from pywebcooking import settings
from main.models.Recipe import Recipe
from main.models.Category import Category
from panel.forms import RecipeForm
from django_gravatar.helpers import get_gravatar_url
from django.utils.translation import ugettext as _
......@@ -25,22 +27,30 @@ class RecipeView(View):
r_cats = []
for cat in recipe.category.all():
r_cats.append(cat.url)
form = RecipeForm({"title": recipe,
"slug": recipe.slug,
"categories": [cat.id for cat in recipe.category.all()],
"tps_prep_hr": int(recipe.tps_prep / 60),
"tps_prep_min": recipe.tps_prep % 60,
"tps_break_j": int(recipe.tps_rep / 1440),
"tps_break_hr": int((recipe.tps_rep % 1440) / 60),
"tps_break_min": recipe.tps_rep % 60,
"tps_cook_hr": int(recipe.tps_cuis / 60),
"tps_cook_min": recipe.tps_cuis % 60,
"description": recipe.description,
"pub_date": recipe.pub_date.strftime("%d/%m/%y %H:%M"),
"status": int(recipe.published)})
context = {
"recipe": recipe,
"categories": self.categories(),
"r_cats": r_cats,
"staff": request.user.is_staff,
"user_name": request.user.first_name + " " + request.user.last_name,
"avatar": get_gravatar_url(request.user.email, size=160),
"page": "recipe",
"lang": settings.LANGUAGE_CODE,
"title": _("Edit") + " \"" + recipe.title + "\" | " + settings.SITE_NAME,
"tps_prep_h": int(recipe.tps_prep / 60),
"tps_prep_min": recipe.tps_prep % 60,
"tps_break_j": int(recipe.tps_rep / 1440),
"tps_break_h": int((recipe.tps_rep % 1440) / 60),
"tps_break_min": recipe.tps_rep % 60,
"tps_cook_h": int(recipe.tps_cuis / 60),
"tps_cook_min": recipe.tps_cuis % 60,
"form": form
}
return render(request, 'panel/recipe.html', context)
......@@ -31,105 +31,93 @@
<form id="recipe-form" action="">
<table>
<tbody>
<tr>
<td>
<label for="recipe-title">{% trans "Title" %}</label>
</td>
<td>
<input type="text" id="recipe-title" class="form-control" value="{{ recipe.title }}" />
</td>
</tr>
<tr>
<td>
<label for="recipe-slug">{% trans "Slug" %}</label>
</td>
<td>
<input type="text" id="recipe-slug" class="form-control" value="{{ recipe.slug }}">
</td>
</tr>
<tr>
<td class="align-top">
<label>{% trans "Categories" %}</label>
</td>
<td class="align-top">
<div class="categories">
{% for category in categories %}
<div>
<label class="category">
<input type="checkbox" value="{{ category.url }}" {% if category.url in r_cats %}checked{% endif %}/> {{ category.name }}
</label>
</div>
{% endfor %}
</div>
</td>
</tr>
<tr>
<td>
<label for="recipe-prep-time-hr">{% trans "Prep:" %}</label>
</td>
<td>
<input type="number" class="form-control time-details" id="recipe-prep-time-hr" min="0" max="24" value="{{ tps_prep_h }}" />
<span class="label-time">{% trans "hours" %}</span>
<input type="number" class="form-control time-details" id="recipe-prep-time-min" min="0" max="59" value="{{ tps_prep_min }}" />
<span class="label-time">{% trans "minutes" %}</span>
</td>
</tr>
<tr>
<td>
<label for="recipe-prep-time-hr">{% trans "Break:" %}</label>
</td>
<td>
<input type="number" class="form-control time-details" id="recipe-break-time-d" min="0" max="7" value="{{ tps_break_j }}" />
<span class="label-time">{% trans "days" %}</span>
<input type="number" class="form-control time-details" id="recipe-break-time-hr" min="0" max="23" value="{{ tps_break_h }}" />
<span class="label-time">{% trans "hours" %}</span>
<input type="number" class="form-control time-details" id="recipe-break-time-min" min="0" max="59" value="{{ tps_break_min }}" />
<span class="label-time">{% trans "minutes" %}</span>
</td>
</tr>
<tr>
<td>
<label for="recipe-prep-time-hr">{% trans "Cook:" %}</label>
</td>
<td>
<input type="number" class="form-control time-details" id="recipe-cook-time-hr" min="0" max="24" value="{{ tps_cook_h }}" />
<span class="label-time">{% trans "hours" %}</span>
<input type="number" class="form-control time-details" id="recipe-cook-time-min" min="0" max="59" value="{{ tps_cook_min }}" />
<span class="label-time">{% trans "minutes" %}</span>
</td>
</tr>
<tr>
<td class="align-top">
<label for="recipe-desc">{% trans "Description" %}</label>
</td>
<td class="align-top">
<textarea id="recipe-desc" class="form-control">{{ recipe.description }}</textarea>
</td>
</tr>
<tr>
<td>
<label for="recipe-pub-date">{% trans "Publication date" %}</label>
</td>
<td>
<div class="input-group input-with-icon-group">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
<tr>
<td>
<label for="{{ form.title.id_for_label }}">{{ form.title.label }}</label>
</td>
<td>
{{ form.title }}
</td>
</tr>
<tr>
<td>
<label for="{{ form.slug.id_for_label }}">{{ form.slug.label }}</label>
</td>
<td>
{{ form.slug }}
</td>
</tr>
<tr>
<td>
<label>{% trans "Categories" %}</label>
</td>
<td>
<div class="categories">
{% for item in form.categories %}
<div>
{{ item }}
</div>
<input type="text" id="recipe-pub-date" class="form-control datemask datepicker" value="{{ recipe.pub_date | date:"d/m/y h:i" }}" />
{% endfor %}
</div>
</td>
</tr>
<tr>
<td>
<label>{% trans "Prep" %}</label>
</td>
<td class="time">
{{ form.tps_prep_hr }} <label for="{{ form.tps_prep_hr.id_for_label }}">{{ form.tps_prep_hr.label }}</label>
{{ form.tps_prep_min }} <label for="{{ form.tps_prep_min.id_for_label }}">{{ form.tps_prep_min.label }}</label>
</td>
</tr>
<tr>
<td>
<label>{% trans "Break" %}</label>
</td>
<td class="time">
{{ form.tps_break_j }} <label for="{{ form.tps_break_j.id_for_label }}">{{ form.tps_break_j.label }}</label>
{{ form.tps_break_hr }} <label for="{{ form.tps_break_hr.id_for_label }}">{{ form.tps_break_hr.label }}</label>
{{ form.tps_break_min }} <label for="{{ form.tps_break_min.id_for_label }}">{{ form.tps_break_min.label }}</label>
</td>
</tr>
<tr>
<td>
<label>{% trans "Cook" %}</label>
</td>
<td class="time">
{{ form.tps_cook_hr }} <label for="{{ form.tps_cook_hr.id_for_label }}">{{ form.tps_cook_hr.label }}</label>
{{ form.tps_cook_min }} <label for="{{ form.tps_cook_min.id_for_label }}">{{ form.tps_cook_min.label }}</label>
</td>
</tr>
<tr>
<td class="align-top">
<label for="{{ form.description.id_for_label }}">{{ form.description.label }}</label>
</td>
<td>
{{ form.description }}
</td>
</tr>
<tr>
<td>
<label for="{{ form.pub_date.id_for_label }}">{{ form.pub_date.label }}</label>
</td>
<td>
<div class="input-group input-with-icon-group">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
</td>
</tr>
<tr>
<td>
<label for="recipe-status">{% trans "Status" %}</label>
</td>
<td>
<select id="recipe-status" class="form-control">
<option value="published" {% if recipe.published %}selected{% endif %}>{% trans "Published" context "singular" %}</option>
<option value="draft" {% if not recipe.published %}selected{% endif %}>{% trans "Draft" %}</option>
</select>
</td>
</tr>
{{ form.pub_date }}
</div>
</td>
</tr>
<tr>
<td>
<label for="{{ form.status.id_for_label }}">{{ form.status.label }}</label>
</td>
<td>
{{ form.status }}
</td>
</tr>
</tbody>
</table>
<input type="button" id="save-and-quit" value="{% trans "Save & Quit" %}">
......
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