Skip to content

Commit c8649b7

Browse files
jfunezGustavo Fonseca
authored and
Gustavo Fonseca
committed
#1063 - datetime no manager deve ser timezone-aware
FIXES: #1066 - migração para adicionar o campo tz (timezone) no perfil de usuário - melhora na view do perfil do usuário - ajustes em todos os templastes que tinham o filtro: ``|date:`` para aplicar a conversão para a timezone do usuário. - fix template_tag: ``user_avatar_url`` na url do gravatar passava o email no lugar do hash.
1 parent 4b47cee commit c8649b7

17 files changed

+593
-62
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,148 @@
11
{% extends "base_lv1.html" %}
22
{% load i18n %}
3+
{% load user_avatar %}
4+
{% block content %}
5+
<style>
6+
#accountTabContent { min-height: 470px; }
7+
.avatar-rounded{ border-radius: 6px 6px 0 0; }
8+
</style>
39

4-
{% block breadcrumb %}
5-
<ul class="breadcrumb">
6-
<li><a href="{% url index %}">{% trans 'Home' %}</a> <span class="divider">/</span></li>
7-
<li class="active">{% trans 'My Account' %}</li>
8-
</ul>
10+
<div class="row-fluid">
11+
<div class="span9 offset2">
12+
<div class="row-fluid">
13+
<div class="span12">
14+
<h4>{% trans "User information" %}:</h4>
15+
<div class="span8 well">
16+
<dl>
17+
<dt>{% trans "First name" %}:</dt>
18+
<dd>{{ user.first_name }}</dd>
19+
<dt>{% trans "Last name" %}:</dt>
20+
<dd>{{ user.last_name }}</dd>
21+
<dt>{% trans "Username" %}:</dt>
22+
<dd>{{ user.username }}</dd>
23+
<dt>{% trans "Email" %}:</dt>
24+
<dd>{{ user.email }}</dd>
25+
</dl>
26+
<br>
27+
</div>
28+
<div class="span3">
29+
<img class="avatar-rounded" src="{% user_avatar_url request.user '192' %}" alt="">
30+
<div class="alert alert-info">
31+
<small>
32+
<em>
33+
Change your avatar at:
34+
<a href="https://secure.gravatar.com">
35+
https://secure.gravatar.com
36+
</a>
37+
</em>
38+
</small>
39+
</div>
40+
</div>
41+
</div>
42+
</div>
43+
<div class="row">
44+
<ul class="nav nav-tabs" id="accountTab">
45+
<li class="active">
46+
<a data-toggle="tab" href="#profile">
47+
<i class="icon icon-user"></i> {% trans "Profile" %}:
48+
</a>
49+
</li>
50+
<li>
51+
<a data-toggle="tab" href="#collections">
52+
<i class="icon icon-book"></i> {% trans "My Collections" %}:
53+
</a>
54+
</li>
55+
<li>
56+
<a data-toggle="tab" href="#api_keys">
57+
<i class="icon icon-lock"></i> {% trans "API token" %}:
58+
</a>
59+
</li>
60+
</ul>
61+
<div class="tab-content" id="accountTabContent">
62+
<div id="profile" class="tab-pane in active">
63+
<div class="span6">
64+
<h4>{% trans "Change Password" %}:</h4>
65+
<div class="well">
66+
<form id="change_password_form" action="{% url journalmanager.password_change %}" method="POST">
67+
{% with password_form as form %}
68+
{% include "articletrack/includes/form_snippet.html" %}
69+
{% endwith %}
70+
</form>
71+
<br>
72+
</div>
73+
</div>
74+
<div class="span6">
75+
<h4>{% trans "Notifications & Other preferences" %}:</h4>
76+
<div class="well">
77+
<form id="profile_form" action="." method="POST">
78+
{% with profile_form as form %}
79+
{% include "articletrack/includes/form_snippet.html" %}
80+
{% endwith %}
81+
</form>
82+
<br>
83+
</div>
84+
</div>
85+
</div>
86+
<div id="collections" class="tab-pane">
87+
<div class="span12">
88+
<h4>{% trans "My collections" %}:</h4>
89+
<div class="well">
90+
<table class="table table-condensed table-hover">
91+
<thead>
92+
<tr>
93+
<th class="span1">#</th>
94+
<th>{% trans "Collection" %}:</th>
95+
<th class="span2">{% trans "Am I manager?" %}</th>
96+
</tr>
97+
</thead>
98+
<tbody>
99+
{% for collection in my_collecttions %}
100+
<tr>
101+
<td>{{ forloop.counter }}</td>
102+
<td>{{ collection.name }}</td>
103+
<td>
104+
{% if collection.is_manager %}
105+
<i class="icon icon-ok"></i>
106+
{% else %}
107+
<i class="icon icon-remove"></i>
108+
{% endif %}
109+
</td>
110+
</tr>
111+
{% empty %}
112+
<tr>
113+
<td colspan="2">{% trans "No collections related yet!" %}</td>
114+
</tr>
115+
{% endfor %}
116+
</tbody>
117+
</table>
118+
</div>
119+
</div>
120+
</div>
121+
<div id="api_keys" class="tab-pane">
122+
<div class="span12">
123+
<h4>{% trans "API Token" %}:</h4>
124+
<div class="well">
125+
<p>{% trans "This is your token" %}: <code>{{user.api_key.key}}</code></p>
126+
<p>
127+
<a href="http://docs.scielo.org/projects/scielo-manager/en/latest/dev/api.html" target="_blank">
128+
{% trans 'Read more about the API usage' %}
129+
</a>
130+
</p>
131+
</div>
132+
</div>
133+
</div>
134+
</div>
135+
</div>
136+
</div>
137+
</div>
9138
{% endblock %}
10139

11-
{% block content %}
12-
<div class="span8">
13-
<ul>
14-
<li><a href="{% url journalmanager.password_change %}">Change my password</a></li>
15-
<li>Update my personal information</li>
16-
</ul>
17-
</div>
18-
<div class="span4 alert alert-info">
19-
<h4>API Token</h4>
20-
<p>{{user.api_key.key}}</p>
21-
<p>
22-
<a href="http://docs.scielo.org/projects/scielo-manager/en/latest/dev/api.html"
23-
target="_blank">
24-
{% trans 'Read more about the API usage' %}
25-
</a>
26-
</p>
27-
</div>
140+
{% block extrafooter %}
141+
{{ block.super }}
142+
<script>
143+
$(document).ready(function() {
144+
$('input', '#change_password_form').removeClass('span3').addClass('span12');
145+
$('select', '#profile_form').addClass('span12').chosen();
146+
});
147+
</script>
28148
{% endblock %}

scielomanager/accounts/views.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,32 @@
88
from django.utils.translation import ugettext as _
99
from django.contrib.auth import authenticate
1010
from django.conf import settings
11+
from journalmanager.forms import UserProfileForm
1112

1213
from . import forms
1314

1415

1516
@login_required
1617
def my_account(request):
17-
return render_to_response('accounts/my_account.html', {},
18+
profile_form = UserProfileForm(instance=request.user.get_profile())
19+
password_form = forms.PasswordChangeForm()
20+
# password_form faz post na view: password_change, então não deve ser tratado aqui
21+
if request.method == "POST":
22+
profile_form = UserProfileForm(request.POST, instance=request.user.get_profile())
23+
if profile_form.is_valid():
24+
profile_form.save()
25+
messages.success(request, _('Saved successfully'))
26+
else:
27+
messages.error(request, _('There are some errors or missing data.'))
28+
29+
my_collecttions = [{'name': c.name, 'is_manager': c.is_managed_by_user(request.user)} for c in request.user.user_collection.all()]
30+
31+
context = {
32+
'profile_form': profile_form,
33+
'password_form': password_form,
34+
'my_collecttions': my_collecttions,
35+
}
36+
return render_to_response('accounts/my_account.html', context,
1837
context_instance=RequestContext(request))
1938

2039

scielomanager/articletrack/templates/articletrack/includes/article_and_checkin_information.html

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load i18n %}
2+
{% load tz %}
23
<div class="row-fluid show-grid">
34
<div class="span12">
45

@@ -51,7 +52,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
5152
<dt>{% trans "Package name" %}:</dt>
5253
<dd>{{ checkin.package_name }}</dd>
5354
<dt>{% trans "Updated at" %}:</dt>
54-
<dd>{{ checkin.created_at|date:"d/m/Y - H:i" }}</dd>
55+
<dd>{{ checkin.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</dd>
5556
<dt>{% trans "Submitted by" %}:</dt>
5657
{% if checkin.submitted_by %}
5758
<dd>
@@ -75,7 +76,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
7576
{% endwith %}
7677
</dd>
7778
<dt>{% trans "Reviewed at" %}:</dt>
78-
<dd>{{ checkin.reviewed_at|date:"d/m/Y - H:i" }}</dd>
79+
<dd>{{ checkin.reviewed_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</dd>
7980
{% endif %}
8081

8182
{%if checkin.scielo_reviewed_by %}
@@ -88,7 +89,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
8889
{% endwith %}
8990
</dd>
9091
<dt>{% trans "Reviewed at" %}:</dt>
91-
<dd>{{ checkin.scielo_reviewed_at|date:"d/m/Y - H:i" }}</dd>
92+
<dd>{{ checkin.scielo_reviewed_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</dd>
9293
{% endif %}
9394

9495
{% endif %}
@@ -103,7 +104,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
103104
{% endwith %}
104105
</dd>
105106
<dt>{% trans "Accepted at" %}:</dt>
106-
<dd>{{ checkin.accepted_at|date:"d/m/Y - H:i" }}</dd>
107+
<dd>{{ checkin.accepted_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</dd>
107108

108109
{% elif checkin.is_rejected %}
109110
<dt style="text-align: left;"><em>{% trans "Rejection info" %}:</em></dt>
@@ -115,7 +116,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
115116
{% endwith %}
116117
</dd>
117118
<dt>{% trans "Rejected at" %}:</dt>
118-
<dd>{{ checkin.rejected_at|date:"d/m/Y - H:i" }}</dd>
119+
<dd>{{ checkin.rejected_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</dd>
119120
<dt>{% trans "Rejected reason" %}:</dt>
120121
<dd>{{ checkin.rejected_cause }}</dd>
121122

@@ -125,7 +126,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
125126
<dt>{% trans "Will Expire at" %}:</dt>
126127
<dd>
127128
<span class="label label-important">
128-
{{ checkin.expiration_at|date:"d/m/Y - H:i" }}
129+
{{ checkin.expiration_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
129130
</span>
130131
</dd>
131132
{% endif %}

scielomanager/articletrack/templates/articletrack/includes/checkin_list_and_filterform.html

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load i18n %}
2+
{% load tz %}
23
{% load pagination_tags %}
34
{% load trans_status %}
45

@@ -43,7 +44,7 @@
4344
<td>{{ checkin.article.article_title }}</td>
4445
<td>{{ checkin.article.journal_title }}</td>
4546
<td>{{ checkin.article.issue_label }}</td>
46-
<td>{{ checkin.created_at|date:"d/m/Y - H:i" }}</td>
47+
<td>{{ checkin.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</td>
4748
<td>
4849
{% if checkin.get_error_level == 'in progress' %}
4950
<span class="label label-info">
@@ -55,13 +56,13 @@
5556
</td>
5657
{% if status == "review" %}
5758
<td>{{ checkin.reviewed_by.get_full_name|default:"--" }}</td>
58-
<td>{{ checkin.reviewed_at|date:"d/m/Y - H:i"|default:"--" }}</td>
59+
<td>{{ checkin.reviewed_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i"|default:"--" }}</td>
5960
{% elif status == "accepted" %}
6061
<td>{{ checkin.accepted_by.get_full_name|default:"--" }}</td>
61-
<td>{{ checkin.accepted_at|date:"d/m/Y - H:i"|default:"--" }}</td>
62+
<td>{{ checkin.accepted_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i"|default:"--" }}</td>
6263
{% elif status == "rejected" %}
6364
<td>{{ checkin.rejected_by.get_full_name|default:"--" }}</td>
64-
<td>{{ checkin.rejected_at|date:"d/m/Y - H:i"|default:"--" }}</td>
65+
<td>{{ checkin.rejected_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i"|default:"--" }}</td>
6566
{% endif %}
6667
<td>
6768
<div class="btn-group">

scielomanager/articletrack/templates/articletrack/includes/checkin_status_notice_block.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load i18n %}
2+
{% load tz %}
23
<div class="row-fluid show-grid">
34
<div class="span12">
45

@@ -11,7 +12,7 @@ <h4><i class="icon-warning-sign"></i> {% trans "REJECTED" %}:</h4>
1112
{% with checkin.rejected_by as user %}
1213
{% include "articletrack/includes/gravatar_tooltip.html" %}
1314
{% endwith %}
14-
{% trans "at" %} {{ checkin.rejected_at|date:"d/m/Y - H:i" }}
15+
{% trans "at" %} {{ checkin.rejected_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
1516
</p>
1617
</div>
1718

@@ -24,7 +25,7 @@ <h4><i class="icon-ok-circle"></i> {% trans "ACCEPTED" %}:</h4>
2425
{% with checkin.accepted_by as user %}
2526
{% include "articletrack/includes/gravatar_tooltip.html" %}
2627
{% endwith %}
27-
{% trans "at" %} {{ checkin.accepted_at|date:"d/m/Y - H:i" }}
28+
{% trans "at" %} {{ checkin.accepted_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
2829
</p>
2930
</div>
3031

@@ -53,7 +54,7 @@ <h4><i class="icon-ok"></i> {% trans "CHECKED-OUT" %}:</h4>
5354
<h4><i class="icon-ok-circle"></i> {% trans "THIS CHECKIN WILL EXPIRE TODAY" %}:</h4>
5455
<p>
5556
{% trans "This checkin will expire at: " %}
56-
{% trans "at" %} {{ checkin.expiration_at|date:"d/m/Y - H:i" }}
57+
{% trans "at" %} {{ checkin.expiration_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
5758
</p>
5859
<p>
5960
{% trans "After that date, the checkin will be unreachable." %}

scielomanager/articletrack/templates/articletrack/notice_detail.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends "base_list_lv0.html" %}
22
{% load i18n %}
3+
{% load tz %}
34
{% load static %}
45
{% load trans_status %}
56
{% load user_avatar %}
@@ -192,7 +193,7 @@ <h3>{% trans 'Notices' %}:</h3>
192193
{{ notice.message }}
193194
</td>
194195
<td>
195-
{{ notice.created_at|date:"d/m/Y - H:i" }}
196+
{{ notice.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
196197
</td>
197198
</tr>
198199
{% empty %}
@@ -356,7 +357,7 @@ <h3>{% trans 'Previous attempts' %}:</h3>
356357
<tr {% if check.pk == checkin.pk %}class="current_attempt"{% endif %}>
357358
<td>{{ forloop.revcounter }}</td>
358359
<td>
359-
{{ check.created_at|date:"d/m/Y - H:i" }}
360+
{{ check.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
360361
{% if check.pk == checkin.pk %}
361362
<span class="label">{% trans "current" %}</span>
362363
{% endif %}

scielomanager/articletrack/templates/articletrack/ticket_add.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends "base_list_lv0.html" %}
22
{% load i18n %}
3+
{% load tz %}
34

45
{% block page_title %}{% trans "Add a Ticket" %}{% endblock %}
56

@@ -19,7 +20,7 @@ <h2>{% trans "Checking" %}:</h2>
1920
<tr>
2021
<td>{{ checkin.package_name }}</td>
2122
<td>{{ checkin.attempt_ref }}</td>
22-
<td>{{ checkin.created_at|date:"d/m/Y - H:i" }}</td>
23+
<td>{{ checkin.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</td>
2324
</tr>
2425
</table>
2526
</div>
@@ -45,4 +46,4 @@ <h2>{% trans "New Ticket" %}:</h2>
4546
</div>
4647

4748

48-
{% endblock %}
49+
{% endblock %}

0 commit comments

Comments
 (0)