Commit 12a9f7a1 authored by Gabriel Detraz's avatar Gabriel Detraz

Cree une application panier-commande

parent 295e6f4f
......@@ -40,6 +40,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles',
'bootstrap3',
'users',
'panier',
'amap',
'reversion'
)
......
......@@ -24,5 +24,6 @@ urlpatterns = [
url('^', include('django.contrib.auth.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^users/', include('users.urls', namespace='users')),
url(r'^panier/', include('panier.urls', namespace='panier')),
#url(r'^logs/', include('logs.urls', namespace='logs')),
]
from django.contrib import admin
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from reversion.admin import VersionAdmin
from .models import Panier, Commande, Credit, Paiement, Livraison
class PanierAdmin(VersionAdmin):
list_display = ('prix','quantite','nom')
class CommandeAdmin(admin.ModelAdmin):
list_display = ('user', 'quantite', 'prix', 'livre', 'date')
class CreditAdmin(VersionAdmin):
list_display = ('user','montant','moyen','validite')
class PaiementAdmin(VersionAdmin):
list_display = ('moyen',)
class LivraisonAdmin(VersionAdmin):
list_display = ('date',)
admin.site.register(Panier, PanierAdmin)
admin.site.register(Commande, CommandeAdmin)
admin.site.register(Credit, CreditAdmin)
admin.site.register(Paiement, PaiementAdmin)
admin.site.register(Livraison, LivraisonAdmin)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Commande',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, primary_key=True, auto_created=True)),
('quantite', models.IntegerField()),
('prix', models.DecimalField(max_digits=5, decimal_places=2)),
('livre', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='Credit',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, primary_key=True, auto_created=True)),
('montant', models.DecimalField(max_digits=5, decimal_places=2)),
('validite', models.BooleanField()),
],
),
migrations.CreateModel(
name='Livraison',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, primary_key=True, auto_created=True)),
('date', models.DateTimeField()),
],
),
migrations.CreateModel(
name='Paiement',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, primary_key=True, auto_created=True)),
('moyen', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Panier',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, primary_key=True, auto_created=True)),
('prix', models.DecimalField(max_digits=5, decimal_places=2)),
('quantite', models.IntegerField()),
('nom', models.CharField(max_length=255)),
],
),
migrations.AddField(
model_name='credit',
name='moyen',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='panier.Paiement'),
),
migrations.AddField(
model_name='credit',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='commande',
name='date',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='panier.Livraison'),
),
migrations.AddField(
model_name='commande',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
),
]
from django.db import models
from django.forms import ModelForm, Form
from django.db.models.signals import post_save, post_delete
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)
class Commande(models.Model):
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
quantite = models.IntegerField()
prix = models.DecimalField(max_digits=5, decimal_places=2)
livre = models.BooleanField(default=False)
date = models.ForeignKey('Livraison', on_delete=models.PROTECT)
class Credit(models.Model):
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
montant = models.DecimalField(max_digits=5, decimal_places=2)
moyen = models.ForeignKey('Paiement', on_delete=models.PROTECT)
validite = models.BooleanField()
def __str__(self):
return self.montant
class Paiement(models.Model):
moyen = models.CharField(max_length=255)
def __str__(self):
return self.moyen
class Livraison(models.Model):
date = models.DateTimeField()
{% if paniers_list.paginator %}
<ul class="pagination nav navbar-nav">
{% if paniers_list.has_previous %}
<li><a href="?page={{ paniers_list.previous_page_number }}">Suivants</a></li>
{% endif %}
{% for page in paniers_list.paginator.page_range %}
<li class="{% if paniers_list.number == page %}active{% endif %}"><a href="?page={{page }}">{{ page }}</a></li>
{% endfor %}
{% if paniers_list.has_next %}
<li> <a href="?page={{ paniers_list.next_page_number }}">Précédents</a></li>
{% endif %}
</ul>
{% endif %}
<table class="table table-striped">
<thead>
<tr>
<th>Nom</th>
<th>Prenom</th>
<th>Quantité</th>
<th>Prix</th>
<th>Livré</th>
<th>Date de livraison</th>
</tr>
</thead>
{% for panier in paniers_list %}
<tr>
<td>{{ panier.user.name }}</td>
<td>{{ panier.user.surname }}</td>
<td>{{ panier.quantite }}</td>
<td>{{ panier.prix }}</td>
<td>{{ panier.livre }}</td>
<td>{{ panier.date }}</td>
</tr>
{% endfor %}
</table>
{% extends "panier/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Commandes{% endblock %}
{% block content %}
<h2>Commandes</h2>
{% include "panier/aff_paniers.html" with paniers_list=paniers_list %}
<br />
<br />
<br />
{% endblock %}
{% extends "panier/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Création et modification d'utilisateur{% endblock %}
{% block content %}
{% bootstrap_form_errors userform %}
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form userform %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<br />
<br />
<br />
{% endblock %}
{% extends "base.html" %}
{% block sidebar %}
{% if is_cableur %}
<p><a href="{% url "users:new-user" %}">Créer un adhérent</a></p>
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
<p><a href="{% url "users:index-listright" %}">Liste des droits</a></p>
{% if is_bureau %}
<p><a href="{% url "users:del-right" %}">Retirer un droit</a></p>
{% endif %}
{% endif %}
{% endblock %}
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
# App de gestion des paniers pour Amap
# Gabriel Détraz
# Gplv2
from django.shortcuts import render_to_response, get_object_or_404, render, redirect
from django.core.context_processors import csrf
from django.template import Context, RequestContext, loader
from django.contrib import messages
from django.db import IntegrityError
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib.auth.decorators import login_required, permission_required
from .models import Panier, Paiement, Commande, Credit, Livraison
from amap.settings import PAGINATION_NUMBER
def form(ctx, template, request):
c = ctx
c.update(csrf(request))
return render_to_response(
template,
c,
context_instance=RequestContext(request)
)
@login_required
def index(request):
paniers_list = Panier.objects.order_by('pk')
if not request.user.has_perms(('bureau',)):
paniers_list = paniers_list.filter(user=request.user)
paginator = Paginator(paniers_list, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
paniers_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
paniers_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
paniers_list = paginator.page(paginator.num_pages)
return render(request, 'panier/index.html', {'paniers_list': paniers_list})
......@@ -30,6 +30,7 @@
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="{% url "users:mon-profil" %}">Mon profil</a></li>
<li><a href="{% url "panier:index" %}">Les commandes</a></li>
{% if is_cableur %}
<li><a href="{% url "users:index" %}">Gérer les utilisateurs</a></li>
{% endif %}
......
......@@ -12,6 +12,8 @@ class UserAdmin(admin.ModelAdmin):
'name',
'surname',
'pseudo',
'telephone',
'is_ens',
'email',
'state'
)
......@@ -39,7 +41,7 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
list_filter = ()
fieldsets = (
(None, {'fields': ('pseudo', 'password')}),
('Personal info', {'fields': ('name', 'surname', 'email', 'shell')}),
('Personal info', {'fields': ('name', 'surname', 'email', 'telephone', 'is_ens')}),
('Permissions', {'fields': ('is_admin', )}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0002_remove_listright_gid'),
]
operations = [
migrations.AddField(
model_name='user',
name='telephone',
field=models.CharField(max_length=15, default=1),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0003_user_telephone'),
]
operations = [
migrations.AddField(
model_name='user',
name='is_ens',
field=models.BooleanField(default=True),
),
]
......@@ -75,12 +75,14 @@ class User(AbstractBaseUser):
surname = models.CharField(max_length=255)
pseudo = models.CharField(max_length=32, unique=True, help_text="Doit contenir uniquement des lettres, chiffres, ou tirets. ")
email = models.EmailField()
telephone = models.CharField(max_length=15)
comment = models.CharField(help_text="Commentaire, promo", max_length=255, blank=True)
is_ens = models.BooleanField(default=True)
state = models.IntegerField(choices=STATES, default=STATE_ACTIVE)
registered = models.DateTimeField(auto_now_add=True)
USERNAME_FIELD = 'pseudo'
REQUIRED_FIELDS = ['name', 'surname', 'email']
REQUIRED_FIELDS = ['name', 'surname', 'email', 'telephone']
objects = UserManager()
......@@ -196,6 +198,7 @@ class BaseInfoForm(ModelForm):
self.fields['name'].label = 'Prénom'
self.fields['surname'].label = 'Nom'
self.fields['comment'].label = 'Commentaire'
self.fields['is_ens'].label = 'Eleve ou personnel ENS Paris-Saclay'
class Meta:
model = User
......@@ -204,7 +207,9 @@ class BaseInfoForm(ModelForm):
'surname',
'pseudo',
'email',
'telephone',
'comment',
'is_ens',
]
class EditInfoForm(BaseInfoForm):
......@@ -214,7 +219,9 @@ class EditInfoForm(BaseInfoForm):
'surname',
'pseudo',
'email',
'telephone',
'comment',
'is_ens',
]
class UserForm(BaseInfoForm):
......@@ -247,13 +254,12 @@ class NewListRightForm(ListRightForm):
def __init__(self, *args, **kwargs):
super(NewListRightForm, self).__init__(*args, **kwargs)
self.fields['gid'].label = 'Gid, attention, cet attribut ne doit pas être modifié après création'
class DelListRightForm(ModelForm):
listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
class Meta:
exclude = ['listright','gid']
exclude = ['listright']
model = ListRight
class RightForm(ModelForm):
......
......@@ -2,7 +2,6 @@
<thead>
<tr>
<th>Droit</th>
<th>Gid</th>
<th></th>
<th></th>
</tr>
......@@ -10,7 +9,6 @@
{% for listright in listright_list %}
<tr>
<td>{{ listright.listright }}</td>
<td>{{ listright.gid }}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-listright' listright.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a></td>
<td><a class="btn btn-info btn-sm" role="button" href="{% url 'users:history' 'listright' listright.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
......
......@@ -20,7 +20,7 @@
<th>Nom</th>
<th>Pseudo</th>
<th>Statut</th>
<th>Uid</th>
<th>Telephone</th>
<th>Mail</th>
<th>Profil</th>
</tr>
......@@ -36,7 +36,7 @@
<font color="red">Désactivée</font>
{% endif %}
</td>
<td>{{ user.uid_number }}</td>
<td>{{ user.telephone }}</td>
<td>{{ user.email }}</td>
<td><a href="{% url "users:profil" user.id%}" class="btn btn-primary btn-sm" role="button"><i class="glyphicon glyphicon-user"></i></a>
</td>
......
......@@ -25,12 +25,28 @@
<th>E-mail</th>
<td>{{ user.email }}</td>
</tr>
<tr>
<th>Telephone</th>
<td>{{ user.telephone }}</td>
<th>Solde</th>
<td></td>
</tr>
<tr>
<th>Commentaire</th>
<td>{{ user.comment }}</td>
<th>Date d'inscription</th>
<td>{{ user.registered }}</td>
</tr>
<tr>
<th>ENS</th>
{% if user.is_ens %}
<td><font color="green">Oui</font></td>
{% else %}
<td><font color="red">Non</font></td>
{% endif %}
<th>Solde</th>
<td></td>
</tr>
<tr>
<th>Statut</th>
{% if user.state == 0 %}
......
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