Skip to content

Commit

Permalink
#1063 - datetime no manager deve ser timezone-aware
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jfunez authored and Gustavo Fonseca committed Feb 23, 2015
1 parent 4b47cee commit c8649b7
Show file tree
Hide file tree
Showing 17 changed files with 593 additions and 62 deletions.
164 changes: 142 additions & 22 deletions scielomanager/accounts/templates/accounts/my_account.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,148 @@
{% extends "base_lv1.html" %}
{% load i18n %}
{% load user_avatar %}
{% block content %}
<style>
#accountTabContent { min-height: 470px; }
.avatar-rounded{ border-radius: 6px 6px 0 0; }
</style>

{% block breadcrumb %}
<ul class="breadcrumb">
<li><a href="{% url index %}">{% trans 'Home' %}</a> <span class="divider">/</span></li>
<li class="active">{% trans 'My Account' %}</li>
</ul>
<div class="row-fluid">
<div class="span9 offset2">
<div class="row-fluid">
<div class="span12">
<h4>{% trans "User information" %}:</h4>
<div class="span8 well">
<dl>
<dt>{% trans "First name" %}:</dt>
<dd>{{ user.first_name }}</dd>
<dt>{% trans "Last name" %}:</dt>
<dd>{{ user.last_name }}</dd>
<dt>{% trans "Username" %}:</dt>
<dd>{{ user.username }}</dd>
<dt>{% trans "Email" %}:</dt>
<dd>{{ user.email }}</dd>
</dl>
<br>
</div>
<div class="span3">
<img class="avatar-rounded" src="{% user_avatar_url request.user '192' %}" alt="">
<div class="alert alert-info">
<small>
<em>
Change your avatar at:
<a href="https://secure.gravatar.com">
https://secure.gravatar.com
</a>
</em>
</small>
</div>
</div>
</div>
</div>
<div class="row">
<ul class="nav nav-tabs" id="accountTab">
<li class="active">
<a data-toggle="tab" href="#profile">
<i class="icon icon-user"></i> {% trans "Profile" %}:
</a>
</li>
<li>
<a data-toggle="tab" href="#collections">
<i class="icon icon-book"></i> {% trans "My Collections" %}:
</a>
</li>
<li>
<a data-toggle="tab" href="#api_keys">
<i class="icon icon-lock"></i> {% trans "API token" %}:
</a>
</li>
</ul>
<div class="tab-content" id="accountTabContent">
<div id="profile" class="tab-pane in active">
<div class="span6">
<h4>{% trans "Change Password" %}:</h4>
<div class="well">
<form id="change_password_form" action="{% url journalmanager.password_change %}" method="POST">
{% with password_form as form %}
{% include "articletrack/includes/form_snippet.html" %}
{% endwith %}
</form>
<br>
</div>
</div>
<div class="span6">
<h4>{% trans "Notifications & Other preferences" %}:</h4>
<div class="well">
<form id="profile_form" action="." method="POST">
{% with profile_form as form %}
{% include "articletrack/includes/form_snippet.html" %}
{% endwith %}
</form>
<br>
</div>
</div>
</div>
<div id="collections" class="tab-pane">
<div class="span12">
<h4>{% trans "My collections" %}:</h4>
<div class="well">
<table class="table table-condensed table-hover">
<thead>
<tr>
<th class="span1">#</th>
<th>{% trans "Collection" %}:</th>
<th class="span2">{% trans "Am I manager?" %}</th>
</tr>
</thead>
<tbody>
{% for collection in my_collecttions %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ collection.name }}</td>
<td>
{% if collection.is_manager %}
<i class="icon icon-ok"></i>
{% else %}
<i class="icon icon-remove"></i>
{% endif %}
</td>
</tr>
{% empty %}
<tr>
<td colspan="2">{% trans "No collections related yet!" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div id="api_keys" class="tab-pane">
<div class="span12">
<h4>{% trans "API Token" %}:</h4>
<div class="well">
<p>{% trans "This is your token" %}: <code>{{user.api_key.key}}</code></p>
<p>
<a href="http://docs.scielo.org/projects/scielo-manager/en/latest/dev/api.html" target="_blank">
{% trans 'Read more about the API usage' %}
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

{% block content %}
<div class="span8">
<ul>
<li><a href="{% url journalmanager.password_change %}">Change my password</a></li>
<li>Update my personal information</li>
</ul>
</div>
<div class="span4 alert alert-info">
<h4>API Token</h4>
<p>{{user.api_key.key}}</p>
<p>
<a href="http://docs.scielo.org/projects/scielo-manager/en/latest/dev/api.html"
target="_blank">
{% trans 'Read more about the API usage' %}
</a>
</p>
</div>
{% block extrafooter %}
{{ block.super }}
<script>
$(document).ready(function() {
$('input', '#change_password_form').removeClass('span3').addClass('span12');
$('select', '#profile_form').addClass('span12').chosen();
});
</script>
{% endblock %}
21 changes: 20 additions & 1 deletion scielomanager/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,32 @@
from django.utils.translation import ugettext as _
from django.contrib.auth import authenticate
from django.conf import settings
from journalmanager.forms import UserProfileForm

from . import forms


@login_required
def my_account(request):
return render_to_response('accounts/my_account.html', {},
profile_form = UserProfileForm(instance=request.user.get_profile())
password_form = forms.PasswordChangeForm()
# password_form faz post na view: password_change, então não deve ser tratado aqui
if request.method == "POST":
profile_form = UserProfileForm(request.POST, instance=request.user.get_profile())
if profile_form.is_valid():
profile_form.save()
messages.success(request, _('Saved successfully'))
else:
messages.error(request, _('There are some errors or missing data.'))

my_collecttions = [{'name': c.name, 'is_manager': c.is_managed_by_user(request.user)} for c in request.user.user_collection.all()]

context = {
'profile_form': profile_form,
'password_form': password_form,
'my_collecttions': my_collecttions,
}
return render_to_response('accounts/my_account.html', context,
context_instance=RequestContext(request))


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load tz %}
<div class="row-fluid show-grid">
<div class="span12">

Expand Down Expand Up @@ -51,7 +52,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
<dt>{% trans "Package name" %}:</dt>
<dd>{{ checkin.package_name }}</dd>
<dt>{% trans "Updated at" %}:</dt>
<dd>{{ checkin.created_at|date:"d/m/Y - H:i" }}</dd>
<dd>{{ checkin.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</dd>
<dt>{% trans "Submitted by" %}:</dt>
{% if checkin.submitted_by %}
<dd>
Expand All @@ -75,7 +76,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
{% endwith %}
</dd>
<dt>{% trans "Reviewed at" %}:</dt>
<dd>{{ checkin.reviewed_at|date:"d/m/Y - H:i" }}</dd>
<dd>{{ checkin.reviewed_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</dd>
{% endif %}

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

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

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

Expand All @@ -125,7 +126,7 @@ <h4>{% trans "Check-in Information" %}:</h4>
<dt>{% trans "Will Expire at" %}:</dt>
<dd>
<span class="label label-important">
{{ checkin.expiration_at|date:"d/m/Y - H:i" }}
{{ checkin.expiration_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
</span>
</dd>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load tz %}
{% load pagination_tags %}
{% load trans_status %}

Expand Down Expand Up @@ -43,7 +44,7 @@
<td>{{ checkin.article.article_title }}</td>
<td>{{ checkin.article.journal_title }}</td>
<td>{{ checkin.article.issue_label }}</td>
<td>{{ checkin.created_at|date:"d/m/Y - H:i" }}</td>
<td>{{ checkin.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</td>
<td>
{% if checkin.get_error_level == 'in progress' %}
<span class="label label-info">
Expand All @@ -55,13 +56,13 @@
</td>
{% if status == "review" %}
<td>{{ checkin.reviewed_by.get_full_name|default:"--" }}</td>
<td>{{ checkin.reviewed_at|date:"d/m/Y - H:i"|default:"--" }}</td>
<td>{{ checkin.reviewed_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i"|default:"--" }}</td>
{% elif status == "accepted" %}
<td>{{ checkin.accepted_by.get_full_name|default:"--" }}</td>
<td>{{ checkin.accepted_at|date:"d/m/Y - H:i"|default:"--" }}</td>
<td>{{ checkin.accepted_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i"|default:"--" }}</td>
{% elif status == "rejected" %}
<td>{{ checkin.rejected_by.get_full_name|default:"--" }}</td>
<td>{{ checkin.rejected_at|date:"d/m/Y - H:i"|default:"--" }}</td>
<td>{{ checkin.rejected_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i"|default:"--" }}</td>
{% endif %}
<td>
<div class="btn-group">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load tz %}
<div class="row-fluid show-grid">
<div class="span12">

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

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

Expand Down Expand Up @@ -53,7 +54,7 @@ <h4><i class="icon-ok"></i> {% trans "CHECKED-OUT" %}:</h4>
<h4><i class="icon-ok-circle"></i> {% trans "THIS CHECKIN WILL EXPIRE TODAY" %}:</h4>
<p>
{% trans "This checkin will expire at: " %}
{% trans "at" %} {{ checkin.expiration_at|date:"d/m/Y - H:i" }}
{% trans "at" %} {{ checkin.expiration_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
</p>
<p>
{% trans "After that date, the checkin will be unreachable." %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "base_list_lv0.html" %}
{% load i18n %}
{% load tz %}
{% load static %}
{% load trans_status %}
{% load user_avatar %}
Expand Down Expand Up @@ -192,7 +193,7 @@ <h3>{% trans 'Notices' %}:</h3>
{{ notice.message }}
</td>
<td>
{{ notice.created_at|date:"d/m/Y - H:i" }}
{{ notice.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
</td>
</tr>
{% empty %}
Expand Down Expand Up @@ -356,7 +357,7 @@ <h3>{% trans 'Previous attempts' %}:</h3>
<tr {% if check.pk == checkin.pk %}class="current_attempt"{% endif %}>
<td>{{ forloop.revcounter }}</td>
<td>
{{ check.created_at|date:"d/m/Y - H:i" }}
{{ check.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}
{% if check.pk == checkin.pk %}
<span class="label">{% trans "current" %}</span>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "base_list_lv0.html" %}
{% load i18n %}
{% load tz %}

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

Expand All @@ -19,7 +20,7 @@ <h2>{% trans "Checking" %}:</h2>
<tr>
<td>{{ checkin.package_name }}</td>
<td>{{ checkin.attempt_ref }}</td>
<td>{{ checkin.created_at|date:"d/m/Y - H:i" }}</td>
<td>{{ checkin.created_at|timezone:user.get_profile.tz|date:"d/m/Y - H:i" }}</td>
</tr>
</table>
</div>
Expand All @@ -45,4 +46,4 @@ <h2>{% trans "New Ticket" %}:</h2>
</div>


{% endblock %}
{% endblock %}
Loading

0 comments on commit c8649b7

Please sign in to comment.