Commit 72a43bdc authored by Gabriel Detraz's avatar Gabriel Detraz

Ajoute les articles en vente

parent 7a34a672
......@@ -6,7 +6,7 @@ from reversion.admin import VersionAdmin
from .models import Panier, Commande, Credit, Paiement, Livraison
class PanierAdmin(VersionAdmin):
list_display = ('prix','quantite','nom')
list_display = ('prix','nom')
class CommandeAdmin(admin.ModelAdmin):
list_display = ('user', 'quantite', 'prix', 'livre', 'date')
......
......@@ -36,6 +36,18 @@ class DelPaiementForm(ModelForm):
exclude = ['moyen']
model = Paiement
class PanierForm(ModelForm):
class Meta:
model = Panier
fields = ['nom','prix']
class DelPanierForm(ModelForm):
paniers = forms.ModelMultipleChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement", widget=forms.CheckboxSelectMultiple)
class Meta:
exclude = ['nom','prix']
model = Panier
class CreditForm(ModelForm):
class Meta:
model = Credit
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('panier', '0003_auto_20160904_1822'),
]
operations = [
migrations.RemoveField(
model_name='panier',
name='quantite',
),
]
......@@ -7,9 +7,11 @@ from django.dispatch import receiver
class Panier(models.Model):
prix = models.DecimalField(max_digits=5, decimal_places=2)
quantite = models.IntegerField()
nom = models.CharField(max_length=255)
def __str__(self):
return self.nom
class Commande(models.Model):
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
quantite = models.IntegerField()
......
<table class="table table-striped">
<thead>
<tr>
<th>Nom de l'article</th>
<th>Prix unitaire</th>
<th></th>
</tr>
</thead>
{% for article in article_list %}
<tr>
<td>{{ article.nom }}</td>
<td>{{ article.prix }}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:edit-article' article.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>
<a class="btn btn-info btn-sm" role="button" href="{% url 'panier:history' 'article' article.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>
{% extends "panier/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Articles{% endblock %}
{% block content %}
<h2>Liste des types d'articles</h2>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-article' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type d'articles</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'panier:del-article' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types d'articles</a>
{% include "panier/aff_article.html" with article_list=article_list %}
<br />
<br />
<br />
{% endblock %}
......@@ -4,5 +4,6 @@
{% if is_bureau %}
<p><a href="{% url "panier:index-paiement" %}">Liste des moyens de paiement</a></p>
<p><a href="{% url "panier:index-livraison" %}">Liste des dates de livraison</a></p>
<p><a href="{% url "panier:index-article" %}">Liste des paniers en vente</a></p>
{% endif %}
{% endblock %}
......@@ -14,9 +14,14 @@ urlpatterns = [
url(r'^add_credit/(?P<userid>[0-9]+)$', views.add_credit, name='add-credit'),
url(r'^edit_credit/(?P<creditid>[0-9]+)$', views.edit_credit, name='edit-credit'),
url(r'^del_credit/(?P<creditid>[0-9]+)$', views.del_credit, name='del-credit'),
url(r'^add_article/$', views.add_article, name='add-article'),
url(r'^edit_article/(?P<articleid>[0-9]+)$', views.edit_article, name='edit-article'),
url(r'^del_article/$', views.del_article, name='del-article'),
url(r'^index_article/$', views.index_article, name='index-article'),
url(r'^history/(?P<object>paiement)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>livraison)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>credit)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>article)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^$', views.index, name='index'),
]
......
......@@ -15,6 +15,7 @@ from django.db import transaction
from reversion import revisions as reversion
from .models import Panier, Paiement, Commande, Credit, Livraison
from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, LivraisonForm, DelLivraisonForm
from .forms import PanierForm, DelPanierForm
from users.views import User
......@@ -183,6 +184,50 @@ def del_credit(request, creditid):
return redirect("/panier/")
return form({'objet': credit, 'objet_name': 'credit'}, 'panier/delete.html', request)
@login_required
@permission_required('bureau')
def add_article(request):
article = PanierForm(request.POST or None)
if article.is_valid():
with transaction.atomic(), reversion.create_revision():
article.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "L'article a été ajouté")
return redirect("/panier/index_article/")
return form({'panierform': article}, 'panier/panier.html', request)
@login_required
@permission_required('bureau')
def edit_article(request, articleid):
try:
article_instance = Panier.objects.get(pk=articleid)
except Article.DoesNotExist:
messages.error(request, u"Entrée inexistante" )
return redirect("/panier/index_article/")
article = PanierForm(request.POST or None, instance=article_instance)
if article.is_valid():
with transaction.atomic(), reversion.create_revision():
article.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in article.changed_data))
messages.success(request, "Type d'article modifié")
return redirect("/panier/index_article/")
return form({'panierform': article}, 'panier/panier.html', request)
@login_required
@permission_required('bureau')
def del_article(request):
article = DelPanierForm(request.POST or None)
if article.is_valid():
article_del = article.cleaned_data['paniers']
with transaction.atomic(), reversion.create_revision():
article_del.delete()
reversion.set_user(request.user)
messages.success(request, "Le/les articles ont été supprimé")
return redirect("/panier/index_article")
return form({'panierform': article}, 'panier/panier.html', request)
@login_required
def history(request, object, id):
if object == 'credit':
......@@ -200,6 +245,12 @@ def history(request, object, id):
except Paiement.DoesNotExist:
messages.error(request, "Paiement inexistant")
return redirect("/panier/")
elif object == 'article' and request.user.has_perms(('bureau',)):
try:
object_instance = Panier.objects.get(pk=id)
except Panier.DoesNotExist:
messages.error(request, "Paiement inexistant")
return redirect("/panier/")
elif object == 'livraison' and request.user.has_perms(('cableur',)):
try:
object_instance = Livraison.objects.get(pk=id)
......@@ -252,6 +303,12 @@ def index(request):
return render(request, 'panier/index.html', {'paniers_list': paniers_list, 'credit_list': credit_list})
@login_required
@permission_required('bureau')
def index_article(request):
article_list = Panier.objects.order_by('nom')
return render(request, 'panier/index_article.html', {'article_list':article_list})
@login_required
@permission_required('bureau')
def index_paiement(request):
......
......@@ -20,6 +20,8 @@ from users.models import DelRightForm, DelListRightForm, NewListRightForm
from users.models import EditInfoForm, BaseInfoForm, StateForm, RightForm, ListRightForm
from users.forms import PassForm, ResetPasswordForm
from panier.models import Panier, Credit
from amap.settings import REQ_EXPIRE_STR, EMAIL_FROM, ASSO_NAME, ASSO_EMAIL, SITE_NAME, PAGINATION_NUMBER
......@@ -293,12 +295,39 @@ def profil(request, userid):
messages.error(request, "Vous ne pouvez pas afficher un autre user que vous sans droit bureau")
return redirect("/users/profil/" + str(request.user.id))
list_droits = Right.objects.filter(user=users)
paniers_list = Panier.objects.order_by('pk')
credit_list = Credit.objects.order_by('pk')
if not request.user.has_perms(('bureau',)):
paniers_list = paniers_list.filter(user=request.user)
credit_list = credit_list.filter(user=request.user)
paginator_paniers = Paginator(paniers_list, PAGINATION_NUMBER)
paginator_credit = Paginator(credit_list, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
paniers_list = paginator_paniers.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
paniers_list = paginator_paniers.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
paniers_list = paginator_paniers.page(paginator_paniers.num_pages)
try:
credit_list = paginator_credit.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
credit_list = paginator_credit.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
credit_list = paginator_credit.page(paginator_credit.num_pages)
return render(
request,
'users/profil.html',
{
'user': users,
'list_droits': list_droits,
'credit_list': credit_list,
'paniers_list': paniers_list,
}
)
......
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