announce filtering by category
This commit is contained in:
parent
f6b8df5f74
commit
13492ce1ec
|
@ -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;
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -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. © 2015 Entr'ouvert
|
||||
</footer>
|
||||
{% block extrascripts %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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()
|
||||
|
|
Reference in New Issue