Add user's maps page

This commit is contained in:
Yohan Boniface 2012-12-11 20:04:03 +01:00
parent d8df14faf9
commit 2e287d23cf
6 changed files with 95 additions and 29 deletions

View file

@ -0,0 +1,33 @@
{% extends "youmap/home.html" %}
{% block content %}
<div class="row">
<div class="twelve columns">
<!-- Navigation -->
{% include 'youmap/navigation.html' %}
<!-- End Navigation -->
</div>
</div>
<div class="row">
<div class="twelve columns">
<h2>Browse {{ current_user }}'s maps</h2>
</div>
</div>
<div class="row">
<div class="twelve columns">
<div class="row map_list">
{% if maps %}
{% include "chickpea/map_list.html" %}
{% else %}
<div class="twelve mobile-six columns">
{{ current_user }} has not map yet.
</div>
{% endif %}
</div>
</div>
</div>
{% endblock content %}

View file

@ -5,7 +5,7 @@
{% for map_inst in maps %} {% for map_inst in maps %}
<div class="twelve mobile-six columns"> <div class="twelve mobile-six columns">
{% map_fragment map_inst %} {% map_fragment map_inst %}
<div class="panel"><strong>{{ map_inst.name }}</strong> — {{ map_inst.description }} <a href="{{ map_inst.get_absolute_url }}">See this map!</a></div> <div class="panel"><strong>{{ map_inst.name }}</strong>«{{ map_inst.description }}» <em>Cured by <a href="{% url user_maps user.username %}">{{ map_inst.owner }}</a></em> <a href="{{ map_inst.get_absolute_url }}">See this map!</a></div>
</div> </div>
{% endfor %} {% endfor %}

View file

@ -13,32 +13,7 @@
<!-- Navigation --> <!-- Navigation -->
<nav class="top-bar contain-to-grid"> {% include 'youmap/navigation.html' %}
<ul>
<li class="name"><h1><a href="#">YouMap <em>alpha</em></a></h1></li>
<li class="toggle-topbar"><a href="#"></a></li>
</ul>
<section>
<ul class="left">
<li><a href="#">My maps</a></li>
<li><a href="#">Log in</a></li>
</ul>
<ul class="right">
<li class="search">
<form>
<input type="search">
</form>
</li>
<li class="has-button">
<a class="small button" href="#">Search</a>
</li>
</ul>
</section>
</nav>
<!-- End Navigation --> <!-- End Navigation -->
</div> </div>
@ -56,8 +31,8 @@
<div class="row"> <div class="row">
<div class="six mobile-two columns"> <div class="six mobile-two columns">
<h4>YouMap <em>alpha</em></h4><hr/> <h4>u{Map} <em>alpha</em></h4><hr/>
<h5 class="subheader">YouMap let you create maps with OpenStreetMap layers in a minute and embed them in your site.<br /> This is a demo instance, you can host your own, it's <strong>open source</strong>! <h5 class="subheader">u{Map} let you create maps with OpenStreetMap layers in a minute and embed them in your site.<br /> This is a demo instance, you can host your own, it's <strong>open source</strong>!
</h5> </h5>
</div> </div>
<div class="six mobile-two columns"> <div class="six mobile-two columns">

View file

@ -0,0 +1,29 @@
<nav class="top-bar contain-to-grid">
<ul>
<li class="name"><h1><a href="/">u{Map} <em>alpha</em></a></h1></li>
<li class="toggle-topbar"><a href="#"></a></li>
</ul>
<section>
<ul class="left">
{% if user.is_authenticated %}
<li><a href="{% url user_maps user.username %}">My maps</a></li>
<li><a href="#">Log out</a></li>
{% else %}
<li><a href="#">Log in</a></li>
{% endif %}
</ul>
<ul class="right">
<li class="search">
<form>
<input type="search">
</form>
</li>
<li class="has-button">
<a class="small button" href="#">Search</a>
</li>
</ul>
</section>
</nav>

View file

@ -14,6 +14,7 @@ urlpatterns = patterns('',
(r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)), (r'^admin/', include(admin.site.urls)),
url(r'^$', views.home, name="home"), url(r'^$', views.home, name="home"),
url(r'^user/(?P<username>[-_\w]+)/$', views.user_maps, name='user_maps'),
(r'', include('chickpea.urls')), (r'', include('chickpea.urls')),
) )

View file

@ -1,4 +1,6 @@
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django.contrib.auth.models import User
from django.views.generic import DetailView
from chickpea.models import Map from chickpea.models import Map
@ -23,3 +25,29 @@ class Home(TemplateView):
return [self.template_name] return [self.template_name]
home = Home.as_view() home = Home.as_view()
class UserMaps(DetailView):
model = User
slug_url_kwarg = 'username'
slug_field = 'username'
list_template_name = "chickpea/map_list.html"
context_object_name = "current_user"
def get_context_data(self, **kwargs):
maps = Map.objects.filter(owner=self.object).order_by('-modified_at')[:30]
kwargs.update({
"maps": maps
})
return super(UserMaps, self).get_context_data(**kwargs)
def get_template_names(self):
"""
Dispatch template according to the kind of request: ajax or normal.
"""
if self.request.is_ajax():
return [self.list_template_name]
else:
return super(UserMaps, self).get_template_names()
user_maps = UserMaps.as_view()