2012-11-20 03:47:19 -06:00
|
|
|
from django.views.generic import TemplateView
|
2012-12-11 13:04:03 -06:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.views.generic import DetailView
|
2012-12-16 08:10:00 -06:00
|
|
|
from django.db.models import Q
|
|
|
|
|
|
|
|
from sesql.shortquery import shortquery
|
2012-11-20 03:47:19 -06:00
|
|
|
|
2012-12-22 13:32:11 -06:00
|
|
|
from leaflet_storage.models import Map
|
2012-11-20 03:47:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
class Home(TemplateView):
|
|
|
|
template_name = "youmap/home.html"
|
2012-12-22 13:32:11 -06:00
|
|
|
list_template_name = "leaflet_storage/map_list.html"
|
2012-11-20 03:47:19 -06:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2012-12-07 18:02:50 -06:00
|
|
|
maps = Map.objects.order_by('-modified_at')[:100]
|
2012-12-12 06:13:14 -06:00
|
|
|
users = User.objects.filter(is_staff=False)[:10]
|
2012-11-20 03:47:19 -06:00
|
|
|
return {
|
2012-12-12 06:13:14 -06:00
|
|
|
"maps": maps,
|
|
|
|
"users": users
|
2012-11-20 03:47:19 -06:00
|
|
|
}
|
|
|
|
|
2012-12-07 06:40:57 -06:00
|
|
|
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 [self.template_name]
|
|
|
|
|
2012-11-20 03:47:19 -06:00
|
|
|
home = Home.as_view()
|
2012-12-11 13:04:03 -06:00
|
|
|
|
|
|
|
|
|
|
|
class UserMaps(DetailView):
|
|
|
|
model = User
|
|
|
|
slug_url_kwarg = 'username'
|
|
|
|
slug_field = 'username'
|
2012-12-22 13:32:11 -06:00
|
|
|
list_template_name = "leaflet_storage/map_list.html"
|
2012-12-11 13:04:03 -06:00
|
|
|
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()
|
2012-12-16 08:10:00 -06:00
|
|
|
|
|
|
|
|
|
|
|
class Search(TemplateView):
|
|
|
|
template_name = "youmap/search.html"
|
2012-12-22 13:32:11 -06:00
|
|
|
list_template_name = "leaflet_storage/map_list.html"
|
2012-12-16 08:10:00 -06:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
q = self.request.GET['q']
|
|
|
|
maps = shortquery(Q(fulltext__containswords=q))
|
|
|
|
kwargs.update({
|
|
|
|
'maps': maps,
|
|
|
|
'q': q
|
|
|
|
})
|
|
|
|
return 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(Search, self).get_template_names()
|
|
|
|
|
|
|
|
search = Search.as_view()
|