announce filtering by category

This commit is contained in:
Serghei Mihai 2015-01-14 15:11:49 +01:00
parent f6b8df5f74
commit 13492ce1ec
6 changed files with 57 additions and 6 deletions

View File

@ -140,7 +140,7 @@ div.user {
}
ul#management {
margin: 0;
margin: 1em 0 .5em 0;
padding: 0;
}
@ -201,4 +201,11 @@ ul#management li {
.announce {
margin-left: 25px;
}
.empty {
text-align: center;
width: 20em;
color: #aaa;
margin: 0 auto;
}

0
corbo/static/js/corbo.js Normal file
View File

4
corbo/static/js/jquery-1.11.2.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,8 @@
<head>
<title>Corbo :: {% block title %}{%trans "Announces" %}{% endblock %}</title>
<link rel='stylesheet' type='text/css' href='{% static "css/corbo.css" %}' />
{% block scripts %}
{% endblock %}
</head>
<body>
<header>
@ -21,5 +23,7 @@
<footer>
Powered by Corbo. &copy 2015 Entr'ouvert
</footer>
{% block extrascripts %}
{% endblock %}
</body>
</html>

View File

@ -1,13 +1,21 @@
{% extends 'base.html' %}
{% load i18n %}
{% load i18n static %}
{% block title %}{% trans "Management" %}{% endblock %}
{% block scripts %}
<script type="text/javascript" src="{% static "js/jquery-1.11.2.min.js" %}"></script>
<script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
<script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
<script type="text/javascript" src="{% static "js/corbo.js" %}"></script>
{% endblock %}
{% block content %}
<div class="category">
<span class="title">{% trans "Category:" %}</span>
<select>
<option value='' selected>{% trans "All" %}</option>
<option value=''>{% trans "All" %}</option>
{% for category in categories %}
<option value='{{ category.id }}'>{{ category }}</option>
<option value='{{ category.id }}'{% if category_id == category.id %} selected{% endif %}>{{ category }}</option>
{% endfor %}
</select>
</div>
@ -34,6 +42,10 @@
<div class="text_preview">{{ obj.text|safe|truncatechars_html:128 }}</div>
</div>
</li>
{% empty %}
<div class="empty">
{% trans "No announces matching this category" %}
</div>
{% endfor %}
</ul>
@ -41,7 +53,7 @@
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="prev">
<a href="?page={{ page_obj.previous_page_number }}" class="icon"></a>
<a href="?{% if category_id %}category={{ category_id}}&{% endif %}page={{ page_obj.previous_page_number }}" class="icon"></a>
</li>
{% endif %}
<li class="current">
@ -49,9 +61,22 @@
</li>
{% if page_obj.has_next %}
<li class="next">
<a href="?page={{ page_obj.next_page_number }}" class="icon"></a>
<a href="?{% if category_id %}category={{ category_id}}&{% endif %}page={{ page_obj.next_page_number }}" class="icon"></a>
</li>
{% endif %}
</ul>
{% endif %}
{% endblock %}
{% block extrascripts %}
<script type="text/javascript">
$(function() {
$('div.category select').on('change', function() {
var category = $(this).val();
if (category)
window.location.replace('{% url "manage" %}?category=' + category);
else
window.location.replace({% url "manage" %});
})
})
</script>
{% endblock %}

View File

@ -57,9 +57,20 @@ class ManageView(ListView, MultipleObjectMixin):
template_name = 'manage.html'
model = models.Announce
def get_queryset(self):
queryset = super(ManageView, self).get_queryset()
if self.request.GET.get('category'):
queryset = queryset.filter(category__id=self.request.GET['category'])
return queryset
def get_context_data(self, **kwargs):
context = super(ManageView, self).get_context_data(**kwargs)
context['categories'] = models.Category.objects.all().order_by('-ctime')
if self.request.GET.get('category'):
try:
context['category_id'] = int(self.request.GET['category'])
except:
pass
return context
manage = ManageView.as_view()