Skip to content

Commit

Permalink
Merge pull request #159 from colab/profile_widget
Browse files Browse the repository at this point in the history
Profile widget
  • Loading branch information
msfernandes committed Feb 25, 2016
2 parents b36b805 + 288ede8 commit 3d16a49
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 80 deletions.
195 changes: 118 additions & 77 deletions colab/accounts/templates/accounts/user_update_form.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{% extends "base.html" %}
{% load i18n gravatar plugins widgets_tag %}

{% block html %}
{% import_widgets 'profile' %}
{{ block.super }}
{% endblock %}

{% block head_js %}
{% for widget in widgets_profile %}
{{widget.get_header}}
{% endfor %}
<script>
$(function() {

Expand Down Expand Up @@ -98,6 +106,18 @@
$(this).button('loading');
});

// Active profile bars
active = function (identifier){
$('#navbar li').each(function(index,value){
$(this).removeClass('active');
})
$(identifier).addClass('active');
$('#profile_content .profile_item').each(function(index,value){
$(this).addClass('hidden');
})
$(identifier+'-content').removeClass('hidden');
}
if (location.hash != '') active(location.hash)
});
</script>
{% endblock %}
Expand Down Expand Up @@ -128,87 +148,108 @@ <h3>{% gravatar user_.email 50 %} {{ user_.get_full_name }} ({{ user_.username }
outline: none;
}
</style>
<form method="post">
{% csrf_token %}

<div class="row">
<div class="col-lg-8 col-md-7 col-sm-12 col-xm-12">
{% for field in form %}
<div class="col-lg-6 col-md-6 col-sm-12 col-xm-12">
<div class="form-group{% if field.field.required %} required{% endif %}{% if field.errors %} alert alert-danger has-error{% endif %}">
<label for="{{ field.name }}" class="control-label">
{{ field.label }}
</label>
{{ field }}
{{ field.errors }}
</div>
</div>
{% endfor %}
</div>

<div class="col-lg-4 col-md-5 col-sm-12 col-xm-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Emails" %}</h3>
</div>
<div class="panel-body">
<ul class="unstyled-list emails">
{% for email in user_.emails.iterator %}
<li>
{% gravatar user_.email 30 %}
<span class="email-address">{{ email.address }}</span>
{% if email.address == user_.email %}
<span class="label label-success">{% trans "Primary" %}</span>
{% else %}
<div class="text-right">
<button class="btn btn-default set-primary" data-loading-text="{% trans 'Setting...' %}">{% trans "Set as Primary" %}</button>
<button class="btn btn-danger delete-email" data-loading-text="{% trans 'Deleting...' %}">{% trans "Delete" %}</button>

{% if widgets_profile %}
<ul id='navbar' class="nav nav-tabs">
<li id='colab_profile' class='active' role="presentation"><a href="#colab_profile" onclick="active('#colab_profile')">{% trans 'Colab Profile' %}</a></li>
{% for widget in widgets_profile %}
<li id='{{widget.identifier}}' role="presentation"><a href="#{{widget.identifier}}" onclick="active('#{{widget.identifier}}')">{{widget.name}}</a></li>
{% endfor %}
</ul>
{% endif %}

<div id='profile_content'>
<div class='profile_item' id='colab_profile-content'>
<form method="post">
{% csrf_token %}

<input type='hidden' name='colab_form' value='true'>
<div class="row">
<div class="col-lg-8 col-md-7 col-sm-12 col-xm-12">
{% for field in form %}
<div class="col-lg-6 col-md-6 col-sm-12 col-xm-12">
<div class="form-group{% if field.field.required %} required{% endif %}{% if field.errors %} alert alert-danger has-error{% endif %}">
<label for="{{ field.name }}" class="control-label">
{{ field.label }}
</label>
{{ field }}
{{ field.errors }}
</div>
</div>
{% endfor %}
</div>

<div class="col-lg-4 col-md-5 col-sm-12 col-xm-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Emails" %}</h3>
</div>
<div class="panel-body">
<ul class="unstyled-list emails">
{% for email in user_.emails.iterator %}
<li>
{% gravatar user_.email 30 %}
<span class="email-address">{{ email.address }}</span>
{% if email.address == user_.email %}
<span class="label label-success">{% trans "Primary" %}</span>
{% else %}
<div class="text-right">
<button class="btn btn-default set-primary" data-loading-text="{% trans 'Setting...' %}">{% trans "Set as Primary" %}</button>
<button class="btn btn-danger delete-email" data-loading-text="{% trans 'Deleting...' %}">{% trans "Delete" %}</button>
</div>
{% endif %}
<hr />
</li>
{% endfor %}
{% for email in user_.emails_not_validated.iterator %}
<li>
{% gravatar user_.email 30 %}
<span class="email-address">{{ email.address }}</span>
<div class="text-right">
<button class="btn btn-default verify-email" data-loading-text="{% trans 'Sending verification...' %}"><span class="icon-warning-sign"></span> {% trans "Verify" %}</button>
<button class="btn btn-danger delete-email">{% trans "Delete" %}</button>
</div>
<hr />
</li>
{% endfor %}
</ul>
<div class="form-group">
<label for="new_email">{% trans "Add another email address:" %}</label>
<input id="new_email" name="new_email" class="form-control" autocomplete="off" />
</div>
<button class="btn btn-primary pull-right" id="add-email">{% trans "Add" %}</button>
</div>
{% endif %}
<hr />
</li>
{% endfor %}
{% for email in user_.emails_not_validated.iterator %}
<li>
{% gravatar user_.email 30 %}
<span class="email-address">{{ email.address }}</span>
<div class="text-right">
<button class="btn btn-default verify-email" data-loading-text="{% trans 'Sending verification...' %}"><span class="icon-warning-sign"></span> {% trans "Verify" %}</button>
<button class="btn btn-danger delete-email">{% trans "Delete" %}</button>
</div>
<hr />
</li>
{% endfor %}
</ul>
<div class="form-group">
<label for="new_email">{% trans "Add another email address:" %}</label>
<input id="new_email" name="new_email" class="form-control" autocomplete="off" />
</div>
<div class="col-lg-4 col-md-5 col-sm-12 col-xm-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
{% trans 'Change Password' %}
</h3>
</div>
<div class="panel-body">
<a href="{% url 'password_change' %}" class="btn btn-default btn-primary pull-right btn-block">{% trans "Change Password" %}</a>
</div>
</div>
</div>
</div>
<button class="btn btn-primary pull-right" id="add-email">{% trans "Add" %}</button>
</div>
</div>
</div>
<div class="col-lg-4 col-md-5 col-sm-12 col-xm-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
{% trans 'Change Password' %}
</h3>
</div>
<div class="panel-body">
<a href="{% url 'password_change' %}" class="btn btn-default btn-primary pull-right btn-block">{% trans "Change Password" %}</a>
</div>
<div class="row">
<div class="col-md-12">
<div class="links-group">
<button type="submit" class="btn btn-primary btn-lg" expanded="false">{% trans "Update" %}</button>
<a href="{% url 'user_profile' user %}" class="btn btn-default btn-lg" role="button">{% trans "Go to profile panel" %}</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="links-group">
<button type="submit" class="btn btn-primary btn-lg" expanded="false">{% trans "Update" %}</button>
<a href="{% url 'user_profile' user %}" class="btn btn-default btn-lg" role="button">{% trans "Go to profile panel" %}</a>

{% for widget in widgets_profile %}
<div id='{{widget.identifier}}-content' class='profile_item hidden'>
{{widget.get_body}}
</div>
</div>
</div>
</form>
{% endfor %}
</div>

{% endblock %}
10 changes: 10 additions & 0 deletions colab/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class UserProfileUpdateView(UserProfileBaseMixin, UpdateView):
template_name = 'accounts/user_update_form.html'
form_class = UserUpdateForm

def post(self, request, *args, **kwargs):
if request.GET.get('path', '') and not request.POST.get('colab_form'):
request.method = 'GET'
result = super(UserProfileUpdateView, self).get(request, *args,
**kwargs)
else:
result = super(UserProfileUpdateView, self).post(request, *args,
**kwargs)
return result

def get_success_url(self):
return reverse('user_profile', kwargs={'username':
self.object.username})
Expand Down
7 changes: 4 additions & 3 deletions colab/widgets/widget_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class Widget(object):
template = ''

def get_body(self):
# avoiding regex in favor of performance
start = self.content.find('<body>')
start = self.content.find('<body')
start = self.content.find('>', start)
end = self.content.find('</body>')

if -1 in [start, end]:
return self.content

body = self.content[start + len('<body>'):end]
# 1 correspond to string size of '>'
body = self.content[start + 1:end]
return mark_safe(body)

def get_header(self):
Expand Down

0 comments on commit 3d16a49

Please sign in to comment.