mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 09:58:23 +02:00
Merge branch 'l_eveil_du_nanax' into 'beta'
More linting See merge request bde/nk20!163
This commit is contained in:
@ -74,7 +74,7 @@ class AliasViewSet(ReadProtectedModelViewSet):
|
||||
serializer_class = self.serializer_class
|
||||
if self.request.method in ['PUT', 'PATCH']:
|
||||
# alias owner cannot be change once establish
|
||||
setattr(serializer_class.Meta, 'read_only_fields', ('note',))
|
||||
serializer_class.Meta.read_only_fields = ('note',)
|
||||
return serializer_class
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
@ -82,7 +82,7 @@ class AliasViewSet(ReadProtectedModelViewSet):
|
||||
try:
|
||||
self.perform_destroy(instance)
|
||||
except ValidationError as e:
|
||||
return Response({e.code: e.message}, status.HTTP_400_BAD_REQUEST)
|
||||
return Response({e.code: str(e)}, status.HTTP_400_BAD_REQUEST)
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
def get_queryset(self):
|
||||
|
@ -333,6 +333,36 @@ class SpecialTransaction(Transaction):
|
||||
self.clean()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def validate_payment_form(form):
|
||||
"""
|
||||
Ensure that last name and first name are filled for a form that creates a SpecialTransaction,
|
||||
and check that if the user pays with a check, then the bank field is filled.
|
||||
|
||||
Return True iff there is no error.
|
||||
Whenever there is an error, they are inserted in the form errors.
|
||||
"""
|
||||
|
||||
credit_type = form.cleaned_data["credit_type"]
|
||||
last_name = form.cleaned_data["last_name"]
|
||||
first_name = form.cleaned_data["first_name"]
|
||||
bank = form.cleaned_data["bank"]
|
||||
|
||||
error = False
|
||||
|
||||
if not last_name or not first_name or (not bank and credit_type.special_type == "Chèque"):
|
||||
if not last_name:
|
||||
form.add_error('last_name', _("This field is required."))
|
||||
error = True
|
||||
if not first_name:
|
||||
form.add_error('first_name', _("This field is required."))
|
||||
error = True
|
||||
if not bank and credit_type.special_type == "Chèque":
|
||||
form.add_error('bank', _("This field is required."))
|
||||
error = True
|
||||
|
||||
return not error
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Special transaction")
|
||||
verbose_name_plural = _("Special transactions")
|
||||
|
@ -28,7 +28,7 @@ $(document).ready(function () {
|
||||
|
||||
// Switching in double consumptions mode should update the layout
|
||||
$('#double_conso').change(function () {
|
||||
$('#consos_list_div').removeClass('d-none')
|
||||
document.getElementById('consos_list_div').classList.remove('d-none')
|
||||
$('#infos_div').attr('class', 'col-sm-5 col-xl-6')
|
||||
|
||||
const note_list_obj = $('#note_list')
|
||||
@ -37,7 +37,7 @@ $(document).ready(function () {
|
||||
note_list_obj.html('')
|
||||
|
||||
buttons.forEach(function (button) {
|
||||
$('#conso_button_' + button.id).click(function () {
|
||||
document.getElementById(`conso_button_${button.id}`).addEventListener('click', () => {
|
||||
if (LOCK) { return }
|
||||
removeNote(button, 'conso_button', buttons, 'consos_list')()
|
||||
})
|
||||
@ -46,7 +46,7 @@ $(document).ready(function () {
|
||||
})
|
||||
|
||||
$('#single_conso').change(function () {
|
||||
$('#consos_list_div').addClass('d-none')
|
||||
document.getElementById('consos_list_div').classList.add('d-none')
|
||||
$('#infos_div').attr('class', 'col-sm-5 col-md-4')
|
||||
|
||||
const consos_list_obj = $('#consos_list')
|
||||
@ -68,9 +68,9 @@ $(document).ready(function () {
|
||||
})
|
||||
|
||||
// Ensure we begin in single consumption. Fix issue with TurboLinks and BootstrapJS
|
||||
$("label[for='double_conso']").removeClass('active')
|
||||
document.querySelector("label[for='double_conso']").classList.remove('active')
|
||||
|
||||
$('#consume_all').click(consumeAll)
|
||||
document.getElementById("consume_all").addEventListener('click', consumeAll)
|
||||
})
|
||||
|
||||
notes = []
|
||||
@ -127,11 +127,10 @@ function addConso (dest, amount, type, category_id, category_name, template_id,
|
||||
html += li('conso_button_' + button.id, button.name +
|
||||
'<span class="badge badge-dark badge-pill">' + button.quantity + '</span>')
|
||||
})
|
||||
document.getElementById(list).innerHTML = html
|
||||
|
||||
$('#' + list).html(html)
|
||||
|
||||
buttons.forEach(function (button) {
|
||||
$('#conso_button_' + button.id).click(function () {
|
||||
buttons.forEach((button) => {
|
||||
document.getElementById(`conso_button_${button.id}`).addEventListener('click', () => {
|
||||
if (LOCK) { return }
|
||||
removeNote(button, 'conso_button', buttons, list)()
|
||||
})
|
||||
@ -146,12 +145,13 @@ function reset () {
|
||||
notes_display.length = 0
|
||||
notes.length = 0
|
||||
buttons.length = 0
|
||||
$('#note_list').html('')
|
||||
$('#consos_list').html('')
|
||||
$('#note').val('')
|
||||
$('#note').attr('data-original-title', '').tooltip('hide')
|
||||
$('#profile_pic').attr('src', '/static/member/img/default_picture.png')
|
||||
$('#profile_pic_link').attr('href', '#')
|
||||
document.getElementById('note_list').innerHTML = ''
|
||||
document.getElementById('consos_list').innerHTML = ''
|
||||
document.getElementById('note').value = ''
|
||||
document.getElementById('note').dataset.originTitle = ''
|
||||
$('#note').tooltip('hide')
|
||||
document.getElementById('profile_pic').src = '/static/member/img/default_picture.png'
|
||||
document.getElementById('profile_pic_link').href = '#'
|
||||
refreshHistory()
|
||||
refreshBalance()
|
||||
LOCK = false
|
||||
@ -168,7 +168,7 @@ function consumeAll () {
|
||||
let error = false
|
||||
|
||||
if (notes_display.length === 0) {
|
||||
$('#note').addClass('is-invalid')
|
||||
document.getElementById('note').classList.add('is-invalid')
|
||||
$('#note_list').html(li('', '<strong>Ajoutez des émetteurs.</strong>', 'text-danger'))
|
||||
error = true
|
||||
}
|
||||
|
Reference in New Issue
Block a user