Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
e92a73df
Commit
e92a73df
authored
Jul 17, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic account view for user and refactor user tool bar
parent
c099cc48
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
165 additions
and
16 deletions
+165
-16
core/migrations/0004_preferences.py
core/migrations/0004_preferences.py
+23
-0
core/models.py
core/models.py
+8
-0
core/templates/core/user_base.jinja
core/templates/core/user_base.jinja
+29
-0
core/templates/core/user_detail.jinja
core/templates/core/user_detail.jinja
+3
-12
core/urls.py
core/urls.py
+2
-0
core/views/user.py
core/views/user.py
+1
-0
counter/migrations/0005_auto_20160717_1029.py
counter/migrations/0005_auto_20160717_1029.py
+35
-0
counter/migrations/0006_auto_20160717_1033.py
counter/migrations/0006_auto_20160717_1033.py
+19
-0
counter/models.py
counter/models.py
+4
-4
counter/templates/counter/user_account.jinja
counter/templates/counter/user_account.jinja
+16
-0
counter/views.py
counter/views.py
+25
-0
No files found.
core/migrations/0004_preferences.py
0 → 100644
View file @
e92a73df
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
from
django.conf
import
settings
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'core'
,
'0003_auto_20160705_2304'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Preferences'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
serialize
=
False
,
auto_created
=
True
)),
(
'show_my_stats'
,
models
.
BooleanField
(
verbose_name
=
'define if we show a users stats'
,
default
=
False
,
help_text
=
'Show your account statistics to others'
)),
(
'user'
,
models
.
OneToOneField
(
related_name
=
'preferences'
,
to
=
settings
.
AUTH_USER_MODEL
)),
],
),
]
core/models.py
View file @
e92a73df
...
...
@@ -280,6 +280,14 @@ class AnonymousUser(AuthAnonymousUser):
def
get_display_name
(
self
):
return
_
(
"Visitor"
)
class
Preferences
(
models
.
Model
):
user
=
models
.
OneToOneField
(
User
,
related_name
=
"preferences"
)
show_my_stats
=
models
.
BooleanField
(
_
(
'define if we show a users stats'
),
default
=
False
,
help_text
=
_
(
'Show your account statistics to others'
),
)
class
LockError
(
Exception
):
"""There was a lock error on the object"""
pass
...
...
core/templates/core/user_base.jinja
0 → 100644
View file @
e92a73df
{%
extends
"core/base.jinja"
%}
{%
block
content
%}
<div>
{{
profile.get_display_name
()
}}
</div>
<div
class=
"tool-bar"
>
<a
href=
"
{{
url
(
'core:user_profile'
,
user_id
=
profile.id
)
}}
"
>
Infos
</a>
{%
if
can_edit
(
profile
,
request.user
)
or
user.id
==
profile.id
%}
<a
href=
"
{{
url
(
'core:user_edit'
,
user_id
=
profile.id
)
}}
"
>
Edit
</a>
{%
endif
%}
{%
if
can_edit_prop
(
profile
,
request.user
)
%}
<a
href=
"
{{
url
(
'core:user_prop'
,
user_id
=
profile.id
)
}}
"
>
Props
</a>
{%
endif
%}
{%
if
(
profile
==
request.user
or
request.user.is_in_group
(
settings.SITH_GROUPS
[
'accounting-admin'
][
'name'
])
or
request.user.is_in_group
(
settings.SITH_GROUPS
[
'root'
][
'name'
]))
%}
<a
href=
"
{{
url
(
'core:user_account'
,
user_id
=
profile.id
)
}}
"
>
Account
</a>
{%
endif
%}
<hr>
</div>
<div>
{%
block
infos
%}
{%
endblock
%}
</div>
{%
endblock
%}
core/templates/core/user_detail.jinja
View file @
e92a73df
{%
extends
"core/base.jinja"
%}
{%
extends
"core/
user_
base.jinja"
%}
{%
block
title
%}
{{
profile.get_display_name
()
}}
's profile
{%
endblock
%}
{%
block
content
%}
<div
class=
"edit-bar"
>
{%
if
can_edit
(
profile
,
request.user
)
or
user.id
==
profile.id
%}
<a
href=
"
{{
url
(
'core:user_edit'
,
user_id
=
profile.id
)
}}
"
>
Edit
</a>
{%
endif
%}
{%
if
can_edit_prop
(
profile
,
request.user
)
%}
<a
href=
"
{{
url
(
'core:user_prop'
,
user_id
=
profile.id
)
}}
"
>
Props
</a>
{%
endif
%}
</div>
{%
block
infos
%}
<h3>
User Profile
</h3>
<hr>
<div
class=
"user_profile"
>
<h4>
{{
profile.get_full_name
()
}}
</h4>
<p>
{{
profile.nick_name
}}
</p>
...
...
@@ -24,6 +14,7 @@
</div>
{%
if
user.membership.
filter
(
end_date
=
None
)
.
exists
()
%}
{# if the user is member of a club, he can view the subscription state #}
<p>
{%
if
get_subscriber
(
profile
)
.
is_subscribed
()
%}
User is subscriber until
{{
get_subscriber
(
profile
)
.
subscriptions.last
()
.
subscription_end
}}
...
...
core/urls.py
View file @
e92a73df
from
django.conf.urls
import
url
,
include
from
core.views
import
*
from
counter.views
import
UserAccountView
urlpatterns
=
[
url
(
r
'^$'
,
index
,
name
=
'index'
),
...
...
@@ -28,6 +29,7 @@ urlpatterns = [
url
(
r
'^user/(?P<user_id>[0-9]+)/edit$'
,
UserUpdateProfileView
.
as_view
(),
name
=
'user_edit'
),
url
(
r
'^user/(?P<user_id>[0-9]+)/prop$'
,
UserUpdatePropView
.
as_view
(),
name
=
'user_prop'
),
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'
),
# Page views
url
(
r
'^page/$'
,
PageListView
.
as_view
(),
name
=
'page_list'
),
...
...
core/views/user.py
View file @
e92a73df
...
...
@@ -2,6 +2,7 @@
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
django.contrib.auth
import
logout
as
auth_logout
,
views
from
django.core.urlresolvers
import
reverse
from
django.core.exceptions
import
PermissionDenied
,
ObjectDoesNotExist
from
django.views.generic.edit
import
UpdateView
from
django.views.generic
import
ListView
,
DetailView
,
TemplateView
import
logging
...
...
counter/migrations/0005_auto_20160717_1029.py
0 → 100644
View file @
e92a73df
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
from
django.conf
import
settings
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'counter'
,
'0004_auto_20160717_0933'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'refilling'
,
name
=
'customer'
,
field
=
models
.
ForeignKey
(
to
=
'counter.Customer'
,
related_name
=
'refillings'
),
),
migrations
.
AlterField
(
model_name
=
'refilling'
,
name
=
'operator'
,
field
=
models
.
ForeignKey
(
to
=
settings
.
AUTH_USER_MODEL
,
related_name
=
'refillings_as_operator'
),
),
migrations
.
AlterField
(
model_name
=
'selling'
,
name
=
'customer'
,
field
=
models
.
ForeignKey
(
to
=
'counter.Customer'
,
related_name
=
'sellings'
),
),
migrations
.
AlterField
(
model_name
=
'selling'
,
name
=
'seller'
,
field
=
models
.
ForeignKey
(
to
=
settings
.
AUTH_USER_MODEL
,
related_name
=
'sellings_as_operator'
),
),
]
counter/migrations/0006_auto_20160717_1033.py
0 → 100644
View file @
e92a73df
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'counter'
,
'0005_auto_20160717_1029'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'selling'
,
name
=
'customer'
,
field
=
models
.
ForeignKey
(
to
=
'counter.Customer'
,
related_name
=
'buyings'
),
),
]
counter/models.py
View file @
e92a73df
...
...
@@ -119,8 +119,8 @@ class Refilling(models.Model):
"""
counter
=
models
.
ForeignKey
(
Counter
,
related_name
=
"refillings"
,
blank
=
False
)
amount
=
CurrencyField
(
_
(
'amount'
))
operator
=
models
.
ForeignKey
(
User
,
related_name
=
"refill_operator
s
"
,
blank
=
False
)
customer
=
models
.
ForeignKey
(
Customer
,
related_name
=
"refill
_customer
s"
,
blank
=
False
)
operator
=
models
.
ForeignKey
(
User
,
related_name
=
"refill
ings_as
_operator"
,
blank
=
False
)
customer
=
models
.
ForeignKey
(
Customer
,
related_name
=
"refill
ing
s"
,
blank
=
False
)
date
=
models
.
DateTimeField
(
_
(
'date'
),
auto_now
=
True
)
payment_method
=
models
.
CharField
(
_
(
'payment method'
),
max_length
=
255
,
choices
=
settings
.
SITH_COUNTER_PAYMENT_METHOD
,
default
=
'cash'
)
...
...
@@ -147,8 +147,8 @@ class Selling(models.Model):
counter
=
models
.
ForeignKey
(
Counter
,
related_name
=
"sellings"
,
blank
=
False
)
unit_price
=
CurrencyField
(
_
(
'unit price'
))
quantity
=
models
.
IntegerField
(
_
(
'quantity'
))
seller
=
models
.
ForeignKey
(
User
,
related_name
=
"sell
ers
"
,
blank
=
False
)
customer
=
models
.
ForeignKey
(
Customer
,
related_name
=
"
customer
s"
,
blank
=
False
)
seller
=
models
.
ForeignKey
(
User
,
related_name
=
"sell
ings_as_operator
"
,
blank
=
False
)
customer
=
models
.
ForeignKey
(
Customer
,
related_name
=
"
buying
s"
,
blank
=
False
)
date
=
models
.
DateTimeField
(
_
(
'date'
),
auto_now
=
True
)
def
__str__
(
self
):
...
...
counter/templates/counter/user_account.jinja
0 → 100644
View file @
e92a73df
{%
extends
"core/user_base.jinja"
%}
{%
block
title
%}
{{
profile.get_display_name
()
}}
's account
{%
endblock
%}
{%
block
infos
%}
<h3>
User account
</h3>
<p>
{{
customer.refillings.all
()
}}
</p>
<p>
{{
customer.buyings.all
()
}}
</p>
{%
endblock
%}
counter/views.py
View file @
e92a73df
...
...
@@ -9,6 +9,7 @@ from django.http import HttpResponseRedirect
from
django.utils
import
timezone
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.conf
import
settings
import
re
...
...
@@ -345,4 +346,28 @@ class CounterDeleteView(CanEditMixin, DeleteView):
template_name
=
'core/delete_confirm.jinja'
success_url
=
reverse_lazy
(
'counter:admin_list'
)
# User accounting infos
class
UserAccountView
(
DetailView
):
"""
Display a user's account
"""
model
=
Customer
pk_url_kwarg
=
"user_id"
template_name
=
"counter/user_account.jinja"
def
dispatch
(
self
,
request
,
*
arg
,
**
kwargs
):
res
=
super
(
UserAccountView
,
self
).
dispatch
(
request
,
*
arg
,
**
kwargs
)
if
(
self
.
object
.
user
==
request
.
user
or
request
.
user
.
is_in_group
(
settings
.
SITH_GROUPS
[
'accounting-admin'
][
'name'
])
or
request
.
user
.
is_in_group
(
settings
.
SITH_GROUPS
[
'root'
][
'name'
])):
return
res
raise
PermissionDenied
def
get_context_data
(
self
,
**
kwargs
):
kwargs
=
super
(
UserAccountView
,
self
).
get_context_data
(
**
kwargs
)
kwargs
[
'profile'
]
=
self
.
object
.
user
# TODO: add list of month where account has activity
return
kwargs
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