diff --git a/kfet/forms.py b/kfet/forms.py index 5b7d264e..729ba9e2 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -1,6 +1,6 @@ from django import forms from django.contrib.auth.models import User -from kfet.models import Account, Checkout +from kfet.models import Account, Checkout, Article from gestioncof.models import CofProfile # ----- @@ -84,8 +84,8 @@ class UserRestrictForm(UserForm): class CheckoutForm(forms.ModelForm): class Meta: - model = Checkout - fields = ['name', 'valid_from', 'valid_to', 'balance', 'is_protected'] + model = Checkout + fields = ['name', 'valid_from', 'valid_to', 'balance', 'is_protected'] widgets = { 'valid_from': DateTimeWidget(), 'valid_to' : DateTimeWidget(), @@ -94,3 +94,16 @@ class CheckoutForm(forms.ModelForm): class CheckoutRestrictForm(CheckoutForm): class Meta(CheckoutForm.Meta): fields = ['name', 'valid_from', 'valid_to'] + +# ----- +# Article forms +# ----- + +class ArticleForm(forms.ModelForm): + class Meta: + model = Article + fields = ['name', 'is_sold', 'price', 'stock', 'category'] + +class ArticleRestrictForm(ArticleForm): + class Meta(ArticleForm.Meta): + fields = ['name', 'is_sold', 'price', 'category'] diff --git a/kfet/migrations/0007_auto_20160804_0641.py b/kfet/migrations/0007_auto_20160804_0641.py new file mode 100644 index 00000000..70bff402 --- /dev/null +++ b/kfet/migrations/0007_auto_20160804_0641.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0006_auto_20160804_0600'), + ] + + operations = [ + migrations.AlterField( + model_name='article', + name='price', + field=models.DecimalField(default=0, max_digits=6, decimal_places=2), + ), + ] diff --git a/kfet/models.py b/kfet/models.py index 264abbe5..af5ac686 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -1,7 +1,6 @@ from django.db import models from django.core.urlresolvers import reverse from django.core.exceptions import PermissionDenied -from django.contrib.auth.models import User, AnonymousUser from django.core.validators import RegexValidator from gestioncof.models import CofProfile from django.utils.six.moves import reduce @@ -215,15 +214,26 @@ class Statement(models.Model): class ArticleCategory(models.Model): name = models.CharField(max_length = 45) + def __str__(self): + return self.name + class Article(models.Model): - name = models.CharField(max_length = 45) - is_sold = models.BooleanField(default = True) - price = models.DecimalField(max_digits = 6, decimal_places = 2) - stock = models.IntegerField(default = 0) + name = models.CharField(max_length = 45) + is_sold = models.BooleanField(default = True) + price = models.DecimalField( + max_digits = 6, decimal_places = 2, + default = 0) + stock = models.IntegerField(default = 0) category = models.ForeignKey( ArticleCategory, on_delete = models.PROTECT, related_name = "articles") + def __str__(self): + return '%s - %s' % (self.category.name, self.name) + + def get_absolute_url(self): + return reverse('kfet.article.read', kwargs={'pk': self.pk}) + class ArticleRule(models.Model): article_on = models.OneToOneField( Article, on_delete = models.PROTECT, diff --git a/kfet/templates/kfet/article.html b/kfet/templates/kfet/article.html new file mode 100644 index 00000000..31484c96 --- /dev/null +++ b/kfet/templates/kfet/article.html @@ -0,0 +1,17 @@ +{% extends 'kfet/base.html' %} + +{% block title %}Liste des articles{% endblock %} + +{% block content %} + +
+ +Nom: {{ article.name }}
+Catégorie: {{ article.category }}
+Prix (hors réduction): {{ article.price }} €
+Stock: {{ article.stock }}
+En vente: {{ article.is_sold }}
+ +{% endblock %} diff --git a/kfet/templates/kfet/article_update.html b/kfet/templates/kfet/article_update.html new file mode 100644 index 00000000..608bac87 --- /dev/null +++ b/kfet/templates/kfet/article_update.html @@ -0,0 +1,13 @@ +{% extends 'kfet/base.html' %} + +{% block title %}Édition de l'article {{ article }}{% endblock %} + +{% block content %} + + + +{% endblock %} diff --git a/kfet/templates/kfet/base_nav.html b/kfet/templates/kfet/base_nav.html index d18ac9d8..da05ab77 100644 --- a/kfet/templates/kfet/base_nav.html +++ b/kfet/templates/kfet/base_nav.html @@ -15,6 +15,7 @@ {% endif %} diff --git a/kfet/urls.py b/kfet/urls.py index 4d66ae8d..e32f7119 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -57,4 +57,25 @@ urlpatterns = [ url('^checkout/(?P