initial checkout selected

Result is the same result but:
- auto-select go to javascript
- 1 less request for KPsulCheckoutForm

- delete debug messages
- some PEP8
This commit is contained in:
Aurélien Delobelle 2017-04-06 16:45:44 +02:00
parent 56fa70e495
commit 33cee05884
4 changed files with 22 additions and 20 deletions

View file

@ -322,12 +322,20 @@ class KPsulAccountForm(forms.ModelForm):
}),
}
class KPsulCheckoutForm(forms.Form):
checkout = forms.ModelChoiceField(
queryset=Checkout.objects.filter(
is_protected=False, valid_from__lte=timezone.now(),
valid_to__gte=timezone.now()),
widget=forms.Select(attrs={'id':'id_checkout_select'}))
queryset=(
Checkout.objects
.filter(
is_protected=False,
valid_from__lte=timezone.now(),
valid_to__gte=timezone.now(),
)
),
widget=forms.Select(attrs={'id': 'id_checkout_select'}),
)
class KPsulOperationForm(forms.ModelForm):
article = forms.ModelChoiceField(

View file

@ -16,7 +16,6 @@ class KFetAuthenticationMiddleware(object):
if request.user.is_authenticated():
# avoid multiple db accesses in views and templates
user_pk = request.user.pk
print(user_pk)
request.user = (
User.objects
.select_related('profile__account_kfet')

View file

@ -393,6 +393,11 @@ $(document).ready(function() {
var last_statement_container = $('#last_statement');
var last_statement_html_default = '<b>Dernier relevé: </b><br><span id="checkout-last_statement_balance"></span>€ le <span id="checkout-last_statement_at"></span> par <span id="checkout-last_statement_by_trigramme"></span>';
// If only one checkout is available, select it
var checkout_choices = checkoutInput.find("option[value!='']");
if (checkout_choices.length == 1) {
$(checkout_choices[0]).prop("selected", true);
}
// Display data
function displayCheckoutData() {

View file

@ -883,7 +883,6 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView):
return super(ArticleUpdate, self).form_valid(form)
# -----
# K-Psul
# -----
@ -893,19 +892,13 @@ def kpsul(request):
data = {}
data['operationgroup_form'] = KPsulOperationGroupForm()
data['trigramme_form'] = KPsulAccountForm()
initial = {}
try:
checkout = Checkout.objects.filter(
is_protected=False, valid_from__lte=timezone.now(),
valid_to__gte=timezone.now()).get()
initial['checkout'] = checkout
except (Checkout.DoesNotExist, Checkout.MultipleObjectsReturned):
pass
data['checkout_form'] = KPsulCheckoutForm(initial=initial)
operation_formset = KPsulOperationFormSet(queryset=Operation.objects.none())
data['operation_formset'] = operation_formset
data['checkout_form'] = KPsulCheckoutForm()
data['operation_formset'] = KPsulOperationFormSet(
queryset=Operation.objects.none(),
)
return render(request, 'kfet/kpsul.html', data)
@teamkfet_required
def kpsul_get_settings(request):
addcost_for = Settings.ADDCOST_FOR()
@ -1643,9 +1636,6 @@ def cancel_transfers(request):
if stop:
negative_accounts.append(account.trigramme)
print(required_perms)
print(request.user.get_all_permissions())
if stop_all or not request.user.has_perms(required_perms):
missing_perms = get_missing_perms(required_perms, request.user)
if missing_perms: