8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Passage d'un coup de pylint

This commit is contained in:
chirac 2017-10-13 22:47:32 +02:00
parent 9ab06207bd
commit 0f47ab79eb
3 changed files with 79 additions and 84 deletions

View file

@ -28,23 +28,30 @@ from reversion.admin import VersionAdmin
from .models import Facture, Article, Banque, Paiement, Cotisation, Vente
class FactureAdmin(VersionAdmin):
list_display = ('user','paiement','date','valid','control')
pass
class VenteAdmin(VersionAdmin):
list_display = ('facture','name','prix','number','iscotisation','duration')
pass
class ArticleAdmin(VersionAdmin):
list_display = ('name','prix','iscotisation','duration')
pass
class BanqueAdmin(VersionAdmin):
list_display = ('name',)
pass
class PaiementAdmin(VersionAdmin):
list_display = ('moyen','type_paiement')
pass
class CotisationAdmin(VersionAdmin):
list_display = ('vente','date_start','date_end')
pass
admin.site.register(Facture, FactureAdmin)
admin.site.register(Article, ArticleAdmin)

View file

@ -24,40 +24,29 @@
# Goulven Kermarec, Gabriel Détraz
# Gplv2
from __future__ import unicode_literals
import os
from django.shortcuts import render, redirect
from django.shortcuts import get_object_or_404
from django.template.context_processors import csrf
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template import Context, RequestContext, loader
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib import messages
from django.db.models import Max, ProtectedError
from django.db.models import ProtectedError
from django.db import transaction
from django.forms import modelformset_factory, formset_factory
import os
from django.utils import timezone
from reversion import revisions as reversion
from reversion.models import Version
from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
# Import des models, forms et fonctions re2o
from users.models import User
from re2o.settings import LOGO_PATH
from re2o import settings
from re2o.views import form
from preferences.models import OptionalUser, AssoOption, GeneralOption
from .models import Facture, Article, Vente, Paiement, Banque
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm
from .forms import ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm
from .forms import BanqueForm, DelBanqueForm, NewFactureFormPdf
from .forms import SelectArticleForm, CreditSoldeForm
from users.models import User
from .tex import render_tex
from re2o.settings import LOGO_PATH
from re2o import settings
from preferences.models import OptionalUser, AssoOption, GeneralOption
from dateutil.relativedelta import relativedelta
from django.utils import timezone
def form(ctx, template, request):
c = ctx
c.update(csrf(request))
return render(request, template, c)
@login_required
@ -82,17 +71,17 @@ def new_facture(request, userid):
facture_form = NewFactureForm(request.POST or None, instance=facture)
article_formset = formset_factory(SelectArticleForm)(request.POST or None)
if facture_form.is_valid() and article_formset.is_valid():
new_facture = facture_form.save(commit=False)
new_facture_instance = facture_form.save(commit=False)
articles = article_formset
# Si au moins un article est rempli
if any(art.cleaned_data for art in articles):
options, created = OptionalUser.objects.get_or_create()
options, _created = OptionalUser.objects.get_or_create()
user_solde = options.user_solde
solde_negatif = options.solde_negatif
# Si on paye par solde, que l'option est activée,
# on vérifie que le négatif n'est pas atteint
if user_solde:
if new_facture.paiement == Paiement.objects.get_or_create(
if new_facture_instance.paiement == Paiement.objects.get_or_create(
moyen='solde'
)[0]:
prix_total = 0
@ -105,7 +94,7 @@ def new_facture(request, userid):
effectuer l'opération")
return redirect("/users/profil/" + userid)
with transaction.atomic(), reversion.create_revision():
new_facture.save()
new_facture_instance.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
for art_item in articles:
@ -113,7 +102,7 @@ def new_facture(request, userid):
article = art_item.cleaned_data['article']
quantity = art_item.cleaned_data['quantity']
new_vente = Vente.objects.create(
facture=new_facture,
facture=new_facture_instance,
name=article.name,
prix=article.prix,
iscotisation=article.iscotisation,
@ -155,7 +144,7 @@ def new_facture_pdf(request):
Vente ou Facture correspondant en bdd"""
facture_form = NewFactureFormPdf(request.POST or None)
if facture_form.is_valid():
options, created = AssoOption.objects.get_or_create()
options, _created = AssoOption.objects.get_or_create()
tbl = []
article = facture_form.cleaned_data['article']
quantite = facture_form.cleaned_data['number']
@ -163,8 +152,8 @@ def new_facture_pdf(request):
destinataire = facture_form.cleaned_data['dest']
chambre = facture_form.cleaned_data['chambre']
fid = facture_form.cleaned_data['fid']
for a in article:
tbl.append([a, quantite, a.prix * quantite])
for art in article:
tbl.append([art, quantite, art.prix * quantite])
prix_total = sum(a[2] for a in tbl)
user = {'name': destinataire, 'room': chambre}
return render_tex(request, 'cotisations/factures.tex', {
@ -207,11 +196,11 @@ def facture_pdf(request, factureid):
messages.error(request, "Vous ne pouvez pas afficher\
une facture non valide")
return redirect("/users/profil/" + str(request.user.id))
vente = Vente.objects.all().filter(facture=facture)
ventes_objects = Vente.objects.all().filter(facture=facture)
ventes = []
options, created = AssoOption.objects.get_or_create()
for v in vente:
ventes.append([v, v.number, v.prix_total])
options, _created = AssoOption.objects.get_or_create()
for vente in ventes_objects:
ventes.append([vente, vente.number, vente.prix_total])
return render_tex(request, 'cotisations/factures.tex', {
'paid': True,
'fid': facture.id,
@ -266,8 +255,7 @@ def edit_facture(request, factureid):
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
field for form in vente_form for field
in facture_form.changed_data + form.changed_data)
)
in facture_form.changed_data + form.changed_data))
messages.success(request, "La facture a bien été modifiée")
return redirect("/cotisations/")
return form({
@ -286,7 +274,7 @@ def del_facture(request, factureid):
except Facture.DoesNotExist:
messages.error(request, u"Facture inexistante")
return redirect("/cotisations/")
if (facture.control or not facture.valid):
if facture.control or not facture.valid:
messages.error(request, "Vous ne pouvez pas editer une facture\
controlée ou invalidée par le trésorier")
return redirect("/cotisations/")
@ -529,7 +517,7 @@ def del_banque(request):
def control(request):
"""Pour le trésorier, vue pour controler en masse les
factures.Case à cocher, pratique"""
options, created = GeneralOption.objects.get_or_create()
options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number
facture_list = Facture.objects.order_by('date').reverse()
controlform_set = modelformset_factory(
@ -595,7 +583,7 @@ def index_banque(request):
@permission_required('cableur')
def index(request):
"""Affiche l'ensemble des factures, pour les cableurs et +"""
options, created = GeneralOption.objects.get_or_create()
options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number
facture_list = Facture.objects.order_by('date').select_related('user')\
.select_related('paiement').prefetch_related('vente_set').reverse()
@ -615,11 +603,11 @@ def index(request):
@login_required
def history(request, object, id):
def history(request, object, object_id):
"""Affiche l'historique de chaque objet"""
if object == 'facture':
try:
object_instance = Facture.objects.get(pk=id)
object_instance = Facture.objects.get(pk=object_id)
except Facture.DoesNotExist:
messages.error(request, "Facture inexistante")
return redirect("/cotisations/")
@ -630,26 +618,26 @@ def history(request, object, id):
return redirect("/users/profil/" + str(request.user.id))
elif object == 'paiement' and request.user.has_perms(('cableur',)):
try:
object_instance = Paiement.objects.get(pk=id)
object_instance = Paiement.objects.get(pk=object_id)
except Paiement.DoesNotExist:
messages.error(request, "Paiement inexistant")
return redirect("/cotisations/")
elif object == 'article' and request.user.has_perms(('cableur',)):
try:
object_instance = Article.objects.get(pk=id)
object_instance = Article.objects.get(pk=object_id)
except Article.DoesNotExist:
messages.error(request, "Article inexistante")
return redirect("/cotisations/")
elif object == 'banque' and request.user.has_perms(('cableur',)):
try:
object_instance = Banque.objects.get(pk=id)
object_instance = Banque.objects.get(pk=object_id)
except Banque.DoesNotExist:
messages.error(request, "Banque inexistante")
return redirect("/cotisations/")
else:
messages.error(request, "Objet inconnu")
return redirect("/cotisations/")
options, created = GeneralOption.objects.get_or_create()
options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number
reversions = Version.objects.get_for_object(object_instance)
paginator = Paginator(reversions, pagination_number)

View file

@ -29,9 +29,9 @@ from django.template import Context, RequestContext, loader
from preferences.models import Service
def form(ctx, template, request):
c = ctx
c.update(csrf(request))
return render(request, template, c)
context = ctx
context.update(csrf(request))
return render(request, template, context)
def index(request):