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
5
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
cebbe65e
Commit
cebbe65e
authored
5 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
Button create a transaction through the API
parent
7f432f5b
No related branches found
No related tags found
1 merge request
!57
Page de consommations
Pipeline
#7927
passed with stages
Stage: test
Stage: quality-assurance
in 4 minutes and 3 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/note/tables.py
+1
-0
1 addition, 0 deletions
apps/note/tables.py
apps/note/views.py
+3
-1
3 additions, 1 deletion
apps/note/views.py
templates/note/conso_form.html
+44
-2
44 additions, 2 deletions
templates/note/conso_form.html
with
48 additions
and
3 deletions
apps/note/tables.py
+
1
−
0
View file @
cebbe65e
...
...
@@ -18,6 +18,7 @@ class HistoryTable(tables.Table):
}
model
=
Transaction
exclude
=
(
"
polymorphic_ctype
"
,
)
order_by
=
(
'
-created_at
'
,
)
template_name
=
'
django_tables2/bootstrap4.html
'
sequence
=
(
'
...
'
,
'
total
'
,
'
valid
'
)
...
...
This diff is collapsed.
Click to expand it.
apps/note/views.py
+
3
−
1
View file @
cebbe65e
...
...
@@ -3,6 +3,7 @@
from
dal
import
autocomplete
from
django.contrib.auth.mixins
import
LoginRequiredMixin
from
django.contrib.contenttypes.models
import
ContentType
from
django.db.models
import
Q
from
django.urls
import
reverse
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -10,7 +11,7 @@ from django.views.generic import CreateView, ListView, UpdateView
from
django_tables2
import
SingleTableView
from
.forms
import
TransactionForm
,
TransactionTemplateForm
from
.models
import
Transaction
,
TransactionTemplate
,
Alias
from
.models
import
Transaction
,
TransactionTemplate
,
Alias
,
TemplateTransaction
from
.tables
import
HistoryTable
...
...
@@ -142,6 +143,7 @@ class ConsoView(LoginRequiredMixin, SingleTableView):
context
[
'
transaction_templates
'
]
=
TransactionTemplate
.
objects
.
filter
(
display
=
True
)
\
.
order_by
(
'
category
'
)
context
[
'
title
'
]
=
_
(
"
Consumptions
"
)
context
[
'
polymorphic_ctype
'
]
=
ContentType
.
objects
.
get_for_model
(
TemplateTransaction
).
pk
# select2 compatibility
context
[
'
no_cache
'
]
=
True
...
...
This diff is collapsed.
Click to expand it.
templates/note/conso_form.html
+
44
−
2
View file @
cebbe65e
...
...
@@ -15,7 +15,9 @@
<img
src=
"https://perso.crans.org/erdnaxe/site-crans/img/logo.svg"
alt=
""
class=
"img-fluid rounded mx-auto d-block"
>
<div
class=
"card-body text-center"
>
Paquito (aka. PAC) : -230 €
<span
id=
"user_note"
>
Paquito (aka. PAC) : -230 €
</span>
</div>
</div>
</div>
...
...
@@ -82,7 +84,7 @@
<div
class=
"d-inline-flex flex-wrap justify-content-center"
>
{% for button in category.list %}
<button
class=
"btn btn-outline-dark rounded-0 flex-fill"
name=
"button"
value=
"{{ button.name }}"
>
id=
"button{{ button.id }}"
name=
"button"
value=
"{{ button.name }}"
>
{{ button.name }} ({{ button.amount | pretty_money }})
</button>
{% endfor %}
...
...
@@ -146,6 +148,46 @@
$
(
document
.
body
).
on
(
"
click
"
,
"
a[data-toggle='tab']
"
,
function
(
event
)
{
location
.
hash
=
this
.
getAttribute
(
"
href
"
);
});
{
%
for
button
in
transaction_templates
%
}
$
(
"
#button{{ button.id }}
"
).
click
(
function
()
{
$
.
post
(
"
/api/note/transaction/transaction/
"
,
{
"
csrfmiddlewaretoken
"
:
"
{{ csrf_token }}
"
,
"
quantity
"
:
1
,
"
amount
"
:
{{
button
.
amount
}},
"
reason
"
:
"
{{ button.name }} ({{ button.category.name }})
"
,
"
valid
"
:
true
,
"
polymorphic_ctype
"
:
{{
polymorphic_ctype
}},
"
resourcetype
"
:
"
TemplateTransaction
"
,
"
source
"
:
6
,
"
destination
"
:
7
,
"
category
"
:
{{
button
.
category
.
id
}},
"
template
"
:
{{
button
.
id
}}
},
function
(
data
,
status
)
{
reloadWithTurbolinks
();
});
});
{
%
endfor
%
}
});
var
reloadWithTurbolinks
=
(
function
()
{
var
scrollPosition
;
function
reload
()
{
scrollPosition
=
[
window
.
scrollX
,
window
.
scrollY
];
Turbolinks
.
visit
(
window
.
location
.
toString
(),
{
action
:
'
replace
'
})
}
document
.
addEventListener
(
'
turbolinks:load
'
,
function
()
{
if
(
scrollPosition
)
{
window
.
scrollTo
.
apply
(
window
,
scrollPosition
);
scrollPosition
=
null
;
}
});
return
reload
;
})();
</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