fmartingr
/
shelfzilla
Archived
1
0
Fork 0

Added base profile views

This commit is contained in:
Felipe Martin 2014-04-03 18:55:07 +02:00
parent 07ce16f50f
commit e97aee4feb
11 changed files with 181 additions and 10 deletions

View File

@ -1 +1,15 @@
# Django, be happy.
from hashlib import md5
from django.contrib.auth.models import User as UserModel
class User(UserModel):
@property
def avatar(self):
avatar = '{}{}?s=300'.format(
'http://www.gravatar.com/avatar/',
md5(self.email.lower()).hexdigest()
)
return avatar
class Meta:
proxy = True

View File

@ -1,9 +1,17 @@
from django.conf.urls import patterns, url
from .views import LoginView, LogoutView
from .views import LoginView, LogoutView, ProfileView
urlpatterns = patterns(
'',
url(r'^login/$', LoginView.as_view(), name="login"),
url(r'^logout/$', LogoutView.as_view(), name="logout"),
url(
r'^profile/$',
ProfileView.as_view(),
name="profile"),
url(
r'^profile/(?P<section>\w+)/$',
ProfileView.as_view(),
name="profile"),
)

View File

@ -3,11 +3,12 @@ from django.template import RequestContext
from django.shortcuts import render_to_response
from django.contrib.auth import logout
from django.utils.translation import ugettext as _
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, Http404
from django.contrib import messages
from django.contrib.auth import login
from .forms import LoginForm
from .models import User
class LoginView(View):
@ -59,3 +60,33 @@ class LogoutView(View):
)
return HttpResponseRedirect('/')
class ProfileView(View):
template = 'users/profile/{}.html'
def get(self, request, section='summary'):
if request.user.is_authenticated():
data = {
'item': User.objects.get(pk=request.user.pk)
}
template = self.template.format(section)
data = self.get_context_from_section(request, section, data)
ctx = RequestContext(request, data)
return render_to_response(template, context_instance=ctx)
else:
raise Http404
def get_summary(self, request, context):
context['SUMMARY'] = 'Y'
return context
def get_context_from_section(self, request, section, context):
method = getattr(self, 'get_{}'.format(section), None)
if method:
context = method(request, context)
return context

View File

@ -24,9 +24,22 @@ body {
}
.max-width-80 { max-width: 80%; }
.max-width-100 { max-width: 100%; }
.navbar-alternative {
.navbar-alternative {
background-color: rgba(51, 51, 51, 0.75);
a { font-weight: bold; color: white; }
}
}
.profile-sidebar {
.avatar {
position: relative;
.badges {
bottom: 8px;
position: absolute;
right: 8px;
}
}
}

View File

@ -2,6 +2,7 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/css/style.css" />
{% block extra_css %}{% endblock %}
<title>{% block page_title %}ShelfZilla{% endblock %}</title>
@ -36,16 +37,30 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ user.username }} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{% url 'profile' %}" data-pjax>{% trans "Profile" %}</a></li>
<li class="divider"></li>
<li><a href="#">{% trans "My collection" %}</a></li>
<li><a href="#">{% trans "Profile" %}</a></li>
</li>
<li><a href="#">{% trans "My wishlist" %}</a></li>
<li class="divider"></li>
<li><a href="{% url "logout" %}">{% trans "Logout" %}</a></li>
</ul>
<li><a href="{% url "logout" %}"><i class="glyphicon glyphicon-log-out"></i> {% trans "Logout" %}</a>
</li>
{% else %}
<li><a href="{% url "login" %}"><i class="glyphicon glyphicon-log-in"></i> {% trans "Log in" %}</a>
<li>
<a href="{% url "login" %}">
<i class="glyphicon glyphicon-log-in"></i> {% trans "Log in" %}
</a>
</li>
{% endif %}
</ul>
<!--
<form class="navbar-form navbar-right" role="search">
<div class="form-search search-only">
<i class="search-icon glyphicon glyphicon-search"></i>
<input type="text" class="form-control search-query" placeholder="{% trans 'Search' %}">
</div>
</form>
-->
</div>
</div>
</nav>
@ -57,7 +72,7 @@
<div id="main_content" data-pjax-container="main">
{% block main_content %}{% endblock %}
</div>
<script src="/static/js/site.js"></script>
{% block extra_js %}{% endblock %}
</body>

View File

@ -0,0 +1,8 @@
{% extends '_layout.html'|pjax:request %}
{% load i18n %}
{% block page_title %}{{ block.super }} | {% trans "Profile" %}{% endblock %}
{% block main_content %}
{% block profile_content %}{% endblock %}
{% endblock %}

View File

@ -0,0 +1,42 @@
{% extends '_layout.html'|pjax:request %}
{% load i18n %}
{% block page_title %}{{ block.super }} | {% trans "Profile" %}{% endblock %}
{% block main_content %}
<div class="container">
<div class="row">
<div class="col-sm-3 profile-sidebar">
<div class="panel panel-primary">
<div class="panel-heading text-center">
<h1 class="panel-title">{{ item.username }}</h1>
</div>
<div class="avatar">
<div class="badges">
{% if item.is_staff %}
<span class="label label-warning">
<i class="glyphicon glyphicon-star"></i>
STAFF
</span>
{% endif %}
</div>
<img src="{{ item.avatar }}" class="max-width-100" />
</div>
<div class="list-group">
<a href="{% url 'profile' %}" data-pjax="profile" class="list-group-item active">
{% trans "Summary" %}</a>
<a href="{% url 'profile' 'collection' %}" data-pjax="profile" class="list-group-item">
{% trans "Collection" %}</a>
<a href="{% url 'profile' 'wishlist' %}" data-pjax="profile" class="list-group-item">
{% trans "Wishlist" %}</a>
<a href="{% url 'profile' 'achievements' %}" data-pjax="profile" class="list-group-item">
{% trans "Achievements" %}</a>
</div>
</div>
</div>
<div class="col-sm-9" data-pjax-container="profile">
{% block profile_content %}{% endblock %}
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,10 @@
{% extends 'users/profile.html'|pjax:request %}
{% load i18n %}
{% block page_title %}{{ block.super }} | {% trans "Achievements" %}{% endblock %}
{% block profile_content %}
<div class="well">
Achievements
</div>
{% endblock %}

View File

@ -0,0 +1,10 @@
{% extends 'users/profile.html'|pjax:request %}
{% load i18n %}
{% block page_title %}{{ block.super }} | {% trans "Collection" %}{% endblock %}
{% block profile_content %}
<div class="well">
Collection
</div>
{% endblock %}

View File

@ -0,0 +1,10 @@
{% extends 'users/profile.html'|pjax:request %}
{% load i18n %}
{% block page_title %}{{ block.super }}{% endblock %}
{% block profile_content %}
<div class="well">
Bio
</div>
{% endblock %}

View File

@ -0,0 +1,10 @@
{% extends 'users/profile.html'|pjax:request %}
{% load i18n %}
{% block page_title %}{{ block.super }} | {% trans "Wishlist" %}{% endblock %}
{% block profile_content %}
<div class="well">
Wishlist
</div>
{% endblock %}