Py3 allows to shorten super()

This commit is contained in:
Aurélien Delobelle 2018-01-16 16:22:52 +01:00
parent 5a5b60ec4d
commit 42e762bc4a
11 changed files with 57 additions and 57 deletions

View file

@ -42,7 +42,7 @@ class AccountForm(forms.ModelForm):
# Surcharge pour passer data à Account.save()
def save(self, data = {}, *args, **kwargs):
obj = super(AccountForm, self).save(commit = False, *args, **kwargs)
obj = super().save(commit = False, *args, **kwargs)
obj.save(data = data)
return obj
@ -91,7 +91,7 @@ class AccountPwdForm(forms.Form):
raise ValidationError("Mot de passe trop court")
if pwd1 != pwd2:
raise ValidationError("Les mots de passes sont différents")
super(AccountPwdForm, self).clean()
super().clean()
class CofForm(forms.ModelForm):
def clean_is_cof(self):
@ -195,7 +195,7 @@ class CheckoutStatementCreateForm(forms.ModelForm):
or self.cleaned_data['balance_200'] is None
or self.cleaned_data['balance_500'] is None):
raise ValidationError("Y'a un problème. Si tu comptes la caisse, mets au moins des 0 stp (et t'as pas idée de comment c'est long de vérifier que t'as mis des valeurs de partout...)")
super(CheckoutStatementCreateForm, self).clean()
super().clean()
class CheckoutStatementUpdateForm(forms.ModelForm):
class Meta:
@ -236,7 +236,7 @@ class ArticleForm(forms.ModelForm):
required = False)
def __init__(self, *args, **kwargs):
super(ArticleForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if self.instance.pk:
self.initial['suppliers'] = self.instance.suppliers.values_list('pk', flat=True)
@ -250,7 +250,7 @@ class ArticleForm(forms.ModelForm):
category, _ = ArticleCategory.objects.get_or_create(name=category_new)
self.cleaned_data['category'] = category
super(ArticleForm, self).clean()
super().clean()
class Meta:
model = Article
@ -321,7 +321,7 @@ class KPsulOperationForm(forms.ModelForm):
}
def clean(self):
super(KPsulOperationForm, self).clean()
super().clean()
type_ope = self.cleaned_data.get('type')
amount = self.cleaned_data.get('amount')
article = self.cleaned_data.get('article')
@ -364,7 +364,7 @@ class AddcostForm(forms.Form):
raise ValidationError('Compte invalide')
else:
self.cleaned_data['amount'] = 0
super(AddcostForm, self).clean()
super().clean()
# -----
@ -462,7 +462,7 @@ class InventoryArticleForm(forms.Form):
stock_new = forms.IntegerField(required=False)
def __init__(self, *args, **kwargs):
super(InventoryArticleForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if 'initial' in kwargs:
self.name = kwargs['initial']['name']
self.stock_old = kwargs['initial']['stock_old']
@ -484,7 +484,7 @@ class OrderArticleForm(forms.Form):
quantity_ordered = forms.IntegerField(required=False)
def __init__(self, *args, **kwargs):
super(OrderArticleForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if 'initial' in kwargs:
self.name = kwargs['initial']['name']
self.stock = kwargs['initial']['stock']
@ -514,7 +514,7 @@ class OrderArticleToInventoryForm(forms.Form):
quantity_received = forms.IntegerField()
def __init__(self, *args, **kwargs):
super(OrderArticleToInventoryForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if 'initial' in kwargs:
self.name = kwargs['initial']['name']
self.category = kwargs['initial']['category']

View file

@ -255,7 +255,7 @@ class Account(models.Model):
cof.save()
if data:
self.cofprofile = cof
super(Account, self).save(*args, **kwargs)
super().save(*args, **kwargs)
def change_pwd(self, clear_password):
from .auth.utils import hash_password
@ -423,7 +423,7 @@ class CheckoutStatement(models.Model):
self.balance_new + self.amount_taken - self.balance_old)
with transaction.atomic():
Checkout.objects.filter(pk=checkout_id).update(balance=self.balance_new)
super(CheckoutStatement, self).save(*args, **kwargs)
super().save(*args, **kwargs)
else:
self.amount_error = (
self.balance_new + self.amount_taken - self.balance_old)
@ -437,7 +437,7 @@ class CheckoutStatement(models.Model):
and last_statement.balance_new != self.balance_new):
Checkout.objects.filter(pk=self.checkout_id).update(
balance=F('balance') - last_statement.balance_new + self.balance_new)
super(CheckoutStatement, self).save(*args, **kwargs)
super().save(*args, **kwargs)
class ArticleCategory(models.Model):
@ -538,7 +538,7 @@ class InventoryArticle(models.Model):
# d'erreur
if not self.inventory.order:
self.stock_error = self.stock_new - self.stock_old
super(InventoryArticle, self).save(*args, **kwargs)
super().save(*args, **kwargs)
class Supplier(models.Model):

View file

@ -493,7 +493,7 @@ class AccountNegativeList(ListView):
context_object_name = 'negatives'
def get_context_data(self, **kwargs):
context = super(AccountNegativeList, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
real_balances = (neg.account.real_balance for neg in self.object_list)
context['negatives_sum'] = sum(real_balances)
return context
@ -536,7 +536,7 @@ class CheckoutCreate(SuccessMessageMixin, CreateView):
balance_new = checkout.balance,
amount_taken = 0)
return super(CheckoutCreate, self).form_valid(form)
return super().form_valid(form)
# Checkout - Read
@ -546,7 +546,7 @@ class CheckoutRead(DetailView):
context_object_name = 'checkout'
def get_context_data(self, **kwargs):
context = super(CheckoutRead, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['statements'] = context['checkout'].statements.order_by('-at')
return context
@ -565,7 +565,7 @@ class CheckoutUpdate(SuccessMessageMixin, UpdateView):
form.add_error(None, 'Permission refusée')
return self.form_invalid(form)
# Updating
return super(CheckoutUpdate, self).form_valid(form)
return super().form_valid(form)
# -----
# Checkout Statement views
@ -617,7 +617,7 @@ class CheckoutStatementCreate(SuccessMessageMixin, CreateView):
at = self.object.at)
def get_context_data(self, **kwargs):
context = super(CheckoutStatementCreate, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
checkout = Checkout.objects.get(pk=self.kwargs['pk_checkout'])
context['checkout'] = checkout
return context
@ -633,7 +633,7 @@ class CheckoutStatementCreate(SuccessMessageMixin, CreateView):
form.instance.balance_new = getAmountBalance(form.cleaned_data)
form.instance.checkout_id = self.kwargs['pk_checkout']
form.instance.by = self.request.user.profile.account_kfet
return super(CheckoutStatementCreate, self).form_valid(form)
return super().form_valid(form)
class CheckoutStatementUpdate(SuccessMessageMixin, UpdateView):
model = CheckoutStatement
@ -645,7 +645,7 @@ class CheckoutStatementUpdate(SuccessMessageMixin, UpdateView):
return reverse_lazy('kfet.checkout.read', kwargs={'pk':self.kwargs['pk_checkout']})
def get_context_data(self, **kwargs):
context = super(CheckoutStatementUpdate, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
checkout = Checkout.objects.get(pk=self.kwargs['pk_checkout'])
context['checkout'] = checkout
return context
@ -657,7 +657,7 @@ class CheckoutStatementUpdate(SuccessMessageMixin, UpdateView):
return self.form_invalid(form)
# Updating
form.instance.amount_taken = getAmountTaken(form.instance)
return super(CheckoutStatementUpdate, self).form_valid(form)
return super().form_valid(form)
# -----
# Category views
@ -689,7 +689,7 @@ class CategoryUpdate(SuccessMessageMixin, UpdateView):
return self.form_invalid(form)
# Updating
return super(CategoryUpdate, self).form_valid(form)
return super().form_valid(form)
# -----
# Article views
@ -756,7 +756,7 @@ class ArticleCreate(SuccessMessageMixin, CreateView):
)
# Creating
return super(ArticleCreate, self).form_valid(form)
return super().form_valid(form)
# Article - Read
@ -766,7 +766,7 @@ class ArticleRead(DetailView):
context_object_name = 'article'
def get_context_data(self, **kwargs):
context = super(ArticleRead, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
inventoryarts = (InventoryArticle.objects
.filter(article=self.object)
.select_related('inventory')
@ -818,7 +818,7 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView):
article=article, supplier=supplier)
# Updating
return super(ArticleUpdate, self).form_valid(form)
return super().form_valid(form)
# -----
@ -1709,7 +1709,7 @@ class InventoryRead(DetailView):
context_object_name = 'inventory'
def get_context_data(self, **kwargs):
context = super(InventoryRead, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
inventoryarticles = (InventoryArticle.objects
.select_related('article', 'article__category')
.filter(inventory = self.object)
@ -1727,7 +1727,7 @@ class OrderList(ListView):
context_object_name = 'orders'
def get_context_data(self, **kwargs):
context = super(OrderList, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['suppliers'] = Supplier.objects.order_by('name')
return context
@ -1856,7 +1856,7 @@ class OrderRead(DetailView):
context_object_name = 'order'
def get_context_data(self, **kwargs):
context = super(OrderRead, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
orderarticles = (OrderArticle.objects
.select_related('article', 'article__category')
.filter(order=self.object)
@ -2010,7 +2010,7 @@ class SupplierUpdate(SuccessMessageMixin, UpdateView):
form.add_error(None, 'Permission refusée')
return self.form_invalid(form)
# Updating
return super(SupplierUpdate, self).form_valid(form)
return super().form_valid(form)
# ==========
@ -2274,7 +2274,7 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(AccountStatBalance, self).dispatch(*args, **kwargs)
return super().dispatch(*args, **kwargs)
# ------------------------