Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nk20
Manage
Activity
Members
Labels
Plan
Issues
32
Issue boards
Milestones
Wiki
Code
Merge requests
6
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BDE
nk20
Commits
cc5185b3
Commit
cc5185b3
authored
5 years ago
by
ynerant
Committed by
Maxime Bombar
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
(Un)validate transactions
parent
c43e8c2d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!57
Page de consommations
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/note/tables.py
+19
-2
19 additions, 2 deletions
apps/note/tables.py
static/js/base.js
+1
-6
1 addition, 6 deletions
static/js/base.js
templates/note/conso_form.html
+27
-3
27 additions, 3 deletions
templates/note/conso_form.html
with
47 additions
and
11 deletions
apps/note/tables.py
+
19
−
2
View file @
cc5185b3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import
html
import
django_tables2
as
tables
from
django.db.models
import
F
from
django_tables2.utils
import
A
...
...
@@ -19,23 +21,38 @@ class HistoryTable(tables.Table):
model
=
Transaction
exclude
=
(
"
id
"
,
"
polymorphic_ctype
"
,
)
template_name
=
'
django_tables2/bootstrap4.html
'
sequence
=
(
'
...
'
,
'
total
'
,
'
valid
'
)
sequence
=
(
'
...
'
,
'
total
'
,
'
valid
'
,
)
orderable
=
False
total
=
tables
.
Column
()
# will use Transaction.total() !!
valid
=
tables
.
Column
(
attrs
=
{
"
td
"
:
{
"
id
"
:
lambda
record
:
"
validate_
"
+
str
(
record
.
id
),
"
class
"
:
lambda
record
:
str
(
record
.
valid
).
lower
()
+
'
validate
'
}})
def
order_total
(
self
,
queryset
,
is_descending
):
# needed for rendering
queryset
=
queryset
.
annotate
(
total
=
F
(
'
amount
'
)
*
F
(
'
quantity
'
))
\
.
order_by
((
'
-
'
if
is_descending
else
''
)
+
'
total
'
)
return
(
queryset
,
True
)
return
queryset
,
True
def
render_amount
(
self
,
value
):
return
pretty_money
(
value
)
def
render_total
(
self
,
value
):
return
pretty_money
(
value
)
# Django-tables escape strings. That's a wrong thing.
def
render_reason
(
self
,
value
):
return
html
.
unescape
(
value
)
def
render_valid
(
self
,
value
):
return
"
✔
"
if
value
else
"
✖
"
class
AliasTable
(
tables
.
Table
):
class
Meta
:
attrs
=
{
...
...
This diff is collapsed.
Click to expand it.
static/js/base.js
+
1
−
6
View file @
cc5185b3
...
...
@@ -139,7 +139,7 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
let
pattern
=
field
.
val
();
// If the pattern is not modified, we don't query the API
if
(
pattern
===
old_pattern
)
if
(
pattern
===
old_pattern
||
pattern
===
""
)
return
;
old_pattern
=
pattern
;
...
...
@@ -150,11 +150,6 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
let
aliases_matched_obj
=
$
(
"
#
"
+
alias_matched_id
);
let
aliases_matched_html
=
""
;
if
(
pattern
===
""
)
{
aliases_matched_obj
.
html
(
""
);
return
;
}
// Get matched notes with the given pattern
getMatchedNotes
(
pattern
,
function
(
aliases
)
{
// The response arrived too late, we stop the request
...
...
This diff is collapsed.
Click to expand it.
templates/note/conso_form.html
+
27
−
3
View file @
cc5185b3
...
...
@@ -133,9 +133,9 @@
{% block extracss %}
<style>
.
select2-contain
er
{
max-width
:
100%
;
min-width
:
100%
;
.
validate
:hov
er
{
cursor
:
pointer
;
text-decoration
:
underline
;
}
</style>
{% endblock %}
...
...
@@ -143,6 +143,7 @@
{% block extrajavascript %}
<script
type=
"text/javascript"
src=
"/static/js/consos.js"
></script>
<script
type=
"text/javascript"
>
// Switching in double consumptions mode should update the layout
$
(
"
#double_conso
"
).
click
(
function
()
{
$
(
"
#consos_list_div
"
).
show
();
$
(
"
#infos_div
"
).
attr
(
'
class
'
,
'
col-sm-5 col-xl-6
'
);
...
...
@@ -190,5 +191,28 @@
});
{
%
endif
%
}
{
%
endfor
%
}
// When we click on the validate button, the validation status is switched
$
(
"
.validate
"
).
click
(
function
(
e
)
{
let
id
=
e
.
target
.
id
.
substring
(
9
);
let
validated
=
e
.
target
.
classList
.
contains
(
"
true
"
);
// Perform a PATCH request to the API in order to update the transaction
// If the user has insuffisent rights, an error message will appear
// TODO: Add this error message
$
.
ajax
({
"
url
"
:
"
/api/note/transaction/transaction/
"
+
id
+
"
/
"
,
type
:
"
PATCH
"
,
dataType
:
"
json
"
,
headers
:
{
"
X-CSRFTOKEN
"
:
CSRF_TOKEN
},
data
:
{
"
resourcetype
"
:
"
TemplateTransaction
"
,
valid
:
!
validated
},
success
:
refreshHistory
});
});
</script>
{% endblock %}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment