Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Sith
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AE
Sith
Commits
0689f864
Commit
0689f864
authored
Aug 18, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate permanencies and add user stats view
parent
b69c3a67
Pipeline
#121
failed with stage
in 3 minutes and 51 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
5 deletions
+65
-5
core/templates/core/user_base.jinja
core/templates/core/user_base.jinja
+1
-0
core/templates/core/user_stats.jinja
core/templates/core/user_stats.jinja
+18
-0
core/urls.py
core/urls.py
+1
-0
core/views/user.py
core/views/user.py
+16
-0
counter/admin.py
counter/admin.py
+1
-0
migrate.py
migrate.py
+28
-5
No files found.
core/templates/core/user_base.jinja
View file @
0689f864
...
...
@@ -5,6 +5,7 @@
<div>
{{
profile.get_display_name
()
}}
</div>
<div
class=
"tools"
>
<a
href=
"
{{
url
(
'core:user_profile'
,
user_id
=
profile.id
)
}}
"
>
{%
trans
%}
Infos
{%
endtrans
%}
</a>
<a
href=
"
{{
url
(
'core:user_stats'
,
user_id
=
profile.id
)
}}
"
>
{%
trans
%}
Stats
{%
endtrans
%}
</a>
{%
if
can_edit
(
profile
,
request.user
)
or
user.id
==
profile.id
%}
<a
href=
"
{{
url
(
'core:user_edit'
,
user_id
=
profile.id
)
}}
"
>
{%
trans
%}
Edit
{%
endtrans
%}
</a>
{%
endif
%}
...
...
core/templates/core/user_stats.jinja
0 → 100644
View file @
0689f864
{%
extends
"core/user_base.jinja"
%}
{%
block
title
%}
{%
trans
user_name
=
profile.get_display_name
()
%}{{
user_name
}}
's stats
{%
endtrans
%}
{%
endblock
%}
{%
block
infos
%}
{%
if
profile.permanencies
%}
<div>
<h3>
Permanencies
</h3>
<p>
{{
total_time
}}
</p>
</div>
{%
endif
%}
{%
endblock
%}
core/urls.py
View file @
0689f864
...
...
@@ -31,6 +31,7 @@ urlpatterns = [
url
(
r
'^user/(?P<user_id>[0-9]+)/groups$'
,
UserUpdateGroupView
.
as_view
(),
name
=
'user_groups'
),
url
(
r
'^user/tools/$'
,
UserToolsView
.
as_view
(),
name
=
'user_tools'
),
url
(
r
'^user/(?P<user_id>[0-9]+)/account$'
,
UserAccountView
.
as_view
(),
name
=
'user_account'
),
url
(
r
'^user/(?P<user_id>[0-9]+)/stats$'
,
UserStatsView
.
as_view
(),
name
=
'user_stats'
),
# File views
# url(r'^file/add/(?P<popup>popup)?$', FileCreateView.as_view(), name='file_new'),
...
...
core/views/user.py
View file @
0689f864
...
...
@@ -10,6 +10,8 @@ from django.forms.models import modelform_factory
from
django.forms
import
CheckboxSelectMultiple
from
django.template.response
import
TemplateResponse
from
django.conf
import
settings
from
datetime
import
timedelta
import
logging
from
core.views
import
CanViewMixin
,
CanEditMixin
,
CanEditPropMixin
...
...
@@ -121,6 +123,20 @@ class UserView(CanViewMixin, DetailView):
context_object_name
=
"profile"
template_name
=
"core/user_detail.jinja"
class
UserStatsView
(
CanViewMixin
,
DetailView
):
"""
Display a user's stats
"""
model
=
User
pk_url_kwarg
=
"user_id"
context_object_name
=
"profile"
template_name
=
"core/user_stats.jinja"
def
get_context_data
(
self
,
**
kwargs
):
kwargs
=
super
(
UserStatsView
,
self
).
get_context_data
(
**
kwargs
)
kwargs
[
'total_time'
]
=
sum
([
p
.
end
-
p
.
start
for
p
in
self
.
object
.
permanencies
.
all
()],
timedelta
())
return
kwargs
class
UserMiniView
(
CanViewMixin
,
DetailView
):
"""
Display a user's profile
...
...
counter/admin.py
View file @
0689f864
...
...
@@ -9,4 +9,5 @@ admin.site.register(Product)
admin
.
site
.
register
(
Counter
)
admin
.
site
.
register
(
Refilling
)
admin
.
site
.
register
(
Selling
)
admin
.
site
.
register
(
Permanency
)
migrate.py
View file @
0689f864
...
...
@@ -18,7 +18,7 @@ from django.forms import ValidationError
from
core.models
import
User
,
SithFile
from
club.models
import
Club
,
Membership
from
counter.models
import
Customer
,
Counter
,
Selling
,
Refilling
,
Product
,
ProductType
from
counter.models
import
Customer
,
Counter
,
Selling
,
Refilling
,
Product
,
ProductType
,
Permanency
from
subscription.models
import
Subscription
,
Subscriber
from
eboutic.models
import
Invoice
,
InvoiceItem
...
...
@@ -539,6 +539,28 @@ def migrate_sellings():
print
(
"FAIL to migrate selling %s: %s"
%
(
r
[
'id_facture'
],
repr
(
e
)))
cur
.
close
()
def
migrate_permanencies
():
cur
=
db
.
cursor
(
MySQLdb
.
cursors
.
SSDictCursor
)
cur
.
execute
(
"""
SELECT *
FROM cpt_tracking
"""
)
Permanency
.
objects
.
all
().
delete
()
print
(
"Permanencies deleted"
)
for
r
in
cur
:
try
:
counter
=
Counter
.
objects
.
filter
(
id
=
r
[
'id_comptoir'
]).
first
()
user
=
User
.
objects
.
filter
(
id
=
r
[
'id_utilisateur'
]).
first
()
new
=
Permanency
(
user
=
user
,
counter
=
counter
,
start
=
r
[
'logged_time'
].
replace
(
tzinfo
=
timezone
(
'Europe/Paris'
)),
end
=
r
[
'closed_time'
].
replace
(
tzinfo
=
timezone
(
'Europe/Paris'
)),
)
new
.
save
()
except
Exception
as
e
:
print
(
"FAIL to migrate permanency: %s"
%
(
repr
(
e
)))
cur
.
close
()
def
main
():
# migrate_users()
...
...
@@ -551,10 +573,11 @@ def main():
# migrate_typeproducts()
# migrate_products()
# migrate_products_to_counter()
reset_customer_amount
()
migrate_invoices
()
migrate_refillings
()
migrate_sellings
()
# reset_customer_amount()
# migrate_invoices()
# migrate_refillings()
# migrate_sellings()
# migrate_permanencies()
reset_index
(
'core'
,
'counter'
)
if
__name__
==
"__main__"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment