forked from DGNum/gestioCOF
Gestion primitive des articles
- Gestion CRU des articles
This commit is contained in:
parent
22ccf02393
commit
5b3613b6f6
|
@ -1,6 +1,6 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.models import User
|
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
|
from gestioncof.models import CofProfile
|
||||||
|
|
||||||
# -----
|
# -----
|
||||||
|
@ -94,3 +94,16 @@ class CheckoutForm(forms.ModelForm):
|
||||||
class CheckoutRestrictForm(CheckoutForm):
|
class CheckoutRestrictForm(CheckoutForm):
|
||||||
class Meta(CheckoutForm.Meta):
|
class Meta(CheckoutForm.Meta):
|
||||||
fields = ['name', 'valid_from', 'valid_to']
|
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']
|
||||||
|
|
19
kfet/migrations/0007_auto_20160804_0641.py
Normal file
19
kfet/migrations/0007_auto_20160804_0641.py
Normal file
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,7 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.contrib.auth.models import User, AnonymousUser
|
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
from gestioncof.models import CofProfile
|
from gestioncof.models import CofProfile
|
||||||
from django.utils.six.moves import reduce
|
from django.utils.six.moves import reduce
|
||||||
|
@ -215,15 +214,26 @@ class Statement(models.Model):
|
||||||
class ArticleCategory(models.Model):
|
class ArticleCategory(models.Model):
|
||||||
name = models.CharField(max_length = 45)
|
name = models.CharField(max_length = 45)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
name = models.CharField(max_length = 45)
|
name = models.CharField(max_length = 45)
|
||||||
is_sold = models.BooleanField(default = True)
|
is_sold = models.BooleanField(default = True)
|
||||||
price = models.DecimalField(max_digits = 6, decimal_places = 2)
|
price = models.DecimalField(
|
||||||
|
max_digits = 6, decimal_places = 2,
|
||||||
|
default = 0)
|
||||||
stock = models.IntegerField(default = 0)
|
stock = models.IntegerField(default = 0)
|
||||||
category = models.ForeignKey(
|
category = models.ForeignKey(
|
||||||
ArticleCategory, on_delete = models.PROTECT,
|
ArticleCategory, on_delete = models.PROTECT,
|
||||||
related_name = "articles")
|
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):
|
class ArticleRule(models.Model):
|
||||||
article_on = models.OneToOneField(
|
article_on = models.OneToOneField(
|
||||||
Article, on_delete = models.PROTECT,
|
Article, on_delete = models.PROTECT,
|
||||||
|
|
17
kfet/templates/kfet/article.html
Normal file
17
kfet/templates/kfet/article.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{% extends 'kfet/base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Liste des articles{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<p><a href="{% url 'kfet.article.create' %}">Créer un article</a></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for article in articles %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'kfet.article.read' article.pk %}">{{ article }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{% endblock %}
|
13
kfet/templates/kfet/article_create.html
Normal file
13
kfet/templates/kfet/article_create.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{% extends 'kfet/base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Création d'un article{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form submit="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<input type="submit" value="Enregistrer">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
15
kfet/templates/kfet/article_read.html
Normal file
15
kfet/templates/kfet/article_read.html
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{% extends 'kfet/base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Informations sur l'article {{ article }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<p><a href="{% url 'kfet.article.update' article.pk %}">Editer les informations</a></p>
|
||||||
|
|
||||||
|
<p>Nom: {{ article.name }}</p>
|
||||||
|
<p>Catégorie: {{ article.category }}</p>
|
||||||
|
<p>Prix (hors réduction): {{ article.price }} €</p>
|
||||||
|
<p>Stock: {{ article.stock }}</p>
|
||||||
|
<p>En vente: {{ article.is_sold }}</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
13
kfet/templates/kfet/article_update.html
Normal file
13
kfet/templates/kfet/article_update.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{% extends 'kfet/base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Édition de l'article {{ article }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<input type="submit" value="Mettre à jour">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -15,6 +15,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{% url "kfet.account" %}">Comptes</a></li>
|
<li><a href="{% url "kfet.account" %}">Comptes</a></li>
|
||||||
<li><a href="{% url "kfet.checkout" %}">Caisses</a></li>
|
<li><a href="{% url "kfet.checkout" %}">Caisses</a></li>
|
||||||
|
<li><a href="{% url "kfet.article" %}">Articles</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
21
kfet/urls.py
21
kfet/urls.py
|
@ -57,4 +57,25 @@ urlpatterns = [
|
||||||
url('^checkout/(?P<pk>\d+)/edit$',
|
url('^checkout/(?P<pk>\d+)/edit$',
|
||||||
permission_required('kfet.is_team')(views.CheckoutUpdate.as_view()),
|
permission_required('kfet.is_team')(views.CheckoutUpdate.as_view()),
|
||||||
name = 'kfet.checkout.update'),
|
name = 'kfet.checkout.update'),
|
||||||
|
|
||||||
|
# -----
|
||||||
|
# Article urls
|
||||||
|
# -----
|
||||||
|
|
||||||
|
# Article - General
|
||||||
|
url('^article/$',
|
||||||
|
permission_required('kfet.is_team')(views.ArticleList.as_view()),
|
||||||
|
name = 'kfet.article'),
|
||||||
|
# Article - Create
|
||||||
|
url('^article/new$',
|
||||||
|
permission_required('kfet.is_team')(views.ArticleCreate.as_view()),
|
||||||
|
name = 'kfet.article.create'),
|
||||||
|
# Article - Read
|
||||||
|
url('^article/(?P<pk>\d+)$',
|
||||||
|
permission_required('kfet.is_team')(views.ArticleRead.as_view()),
|
||||||
|
name = 'kfet.article.read'),
|
||||||
|
# Article - Update
|
||||||
|
url('^article/(?P<pk>\d+)/edit$',
|
||||||
|
permission_required('kfet.is_team')(views.ArticleUpdate.as_view()),
|
||||||
|
name = 'kfet.article.update'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.contrib.auth.models import User
|
||||||
from django.http import HttpResponse, Http404
|
from django.http import HttpResponse, Http404
|
||||||
import json
|
import json
|
||||||
from gestioncof.models import CofProfile, Clipper
|
from gestioncof.models import CofProfile, Clipper
|
||||||
from kfet.models import Account, Checkout
|
from kfet.models import Account, Checkout, Article
|
||||||
from kfet.forms import *
|
from kfet.forms import *
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -298,3 +298,54 @@ class CheckoutUpdate(SuccessMessageMixin, UpdateView):
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
# Updating
|
# Updating
|
||||||
return super(CheckoutUpdate, self).form_valid(form)
|
return super(CheckoutUpdate, self).form_valid(form)
|
||||||
|
|
||||||
|
# -----
|
||||||
|
# Article views
|
||||||
|
# -----
|
||||||
|
|
||||||
|
# Article - General
|
||||||
|
|
||||||
|
class ArticleList(ListView):
|
||||||
|
model = Article
|
||||||
|
queryset = Article.objects.order_by('category', '-is_sold', 'name')
|
||||||
|
template_name = 'kfet/article.html'
|
||||||
|
context_object_name = 'articles'
|
||||||
|
|
||||||
|
# Article - Create
|
||||||
|
|
||||||
|
class ArticleCreate(SuccessMessageMixin, CreateView):
|
||||||
|
model = Article
|
||||||
|
template_name = 'kfet/article_create.html'
|
||||||
|
form_class = ArticleForm
|
||||||
|
success_message = 'Nouvel item : %(category)s - %(name)s'
|
||||||
|
|
||||||
|
# Surcharge de la validation
|
||||||
|
def form_valid(self, form):
|
||||||
|
# Checking permission
|
||||||
|
if not self.request.user.has_perm('add_article'):
|
||||||
|
raise PermissionDenied
|
||||||
|
# Creating
|
||||||
|
return super(ArticleCreate, self).form_valid(form)
|
||||||
|
|
||||||
|
# Article - Read
|
||||||
|
|
||||||
|
class ArticleRead(DetailView):
|
||||||
|
model = Article
|
||||||
|
template_name = 'kfet/article_read.html'
|
||||||
|
context_object_name = 'article'
|
||||||
|
|
||||||
|
# Article - Update
|
||||||
|
|
||||||
|
class ArticleUpdate(UpdateView):
|
||||||
|
model = Article
|
||||||
|
template_name = 'kfet/article_update.html'
|
||||||
|
form_class = ArticleRestrictForm
|
||||||
|
success_message = "Informations mises à jour pour l'article : %(name)s"
|
||||||
|
|
||||||
|
# Surcharge de la validation
|
||||||
|
def form_valid(self, form):
|
||||||
|
# Checking permission
|
||||||
|
if not self.request.user.has_perm('change_article'):
|
||||||
|
raise PermissionDenied
|
||||||
|
# Updating
|
||||||
|
return super(ArticleUpdate, self).form_valid(form)
|
||||||
|
|
Loading…
Reference in a new issue