diff --git a/cards/templatetags/inclusion_tags.py b/cards/templatetags/inclusion_tags.py index 3dab0c9..531eff6 100644 --- a/cards/templatetags/inclusion_tags.py +++ b/cards/templatetags/inclusion_tags.py @@ -7,5 +7,9 @@ register = template.Library() def nav_menu(): countries = Country.objects.all().order_by('label') return { 'countries' : countries } + +def cards_list_partial(cardslist): + return { 'cards_list': cardslist } register.inclusion_tag('nav_menu.html')(nav_menu) +register.inclusion_tag('cards_list.html')(cards_list_partial) diff --git a/cards/views.py b/cards/views.py index 2d0b077..6e7b5fe 100644 --- a/cards/views.py +++ b/cards/views.py @@ -17,7 +17,7 @@ def index(request): nbr_of_cards = Card.objects.count() - tags_list = Tag.objects.annotate(occurence=Count('tags')) + tags_list = Tag.objects.order_by('?').annotate(occurences=Count('tags'))[:15] cards_list = Card.objects.order_by('-created_at')[:25] @@ -25,6 +25,18 @@ def index(request): return render_to_response('cards/index.html', RequestContext(request, context)) +def about(request): + return render_to_response('cards/about.html', RequestContext(request, {})) + +def tags(request): + from django.db.models import Count + + tags_list = Tag.objects.annotate(occurences=Count('tags')) + + context = { 'tags_list' : tags_list } + + return render_to_response('cards/tags.html', RequestContext(request, context)) + def details(request, card_id): a = get_object_or_404(Card, pk=card_id) @@ -41,22 +53,6 @@ def charts(request): return render_to_response('cards/charts.html', RequestContext(request, context)) -def pagination(cards_list, request): - paginator = Paginator(cards_list, 20) - - page = request.GET.get('page') - - try: - cards = paginator.page(page) - except PageNotAnInteger: - cards = paginator.page(1) - except EmptyPage: - cards = paginator.page(paginator.num_pages) - except: - cards = paginator.page(1) - - return cards - def query(request): if request.method == "POST": @@ -79,7 +75,7 @@ def query(request): cards_list = Card.objects.filter(q) - cards = pagination(cards_list, request) + cards = cards_list context = { 'tags_list': tags_list, 'cards' : cards, 'title' : 'Recherche sur les termes : ' + terms } @@ -132,7 +128,7 @@ def advanced_query(request): def search_by_country(request, country_id): country = get_object_or_404(Country, pk=country_id) - cards = pagination(country.card_set.all(), request) + cards = country.card_set.all() context = { 'cards' : cards, 'title' : country.label } @@ -143,31 +139,9 @@ def search_by_tag(request, tag_id): cards_list = tag.tags.all() - cards = pagination(cards_list, request) + cards = cards_list context = { 'cards' : cards, 'title' : tag.label } return render_to_response('cards/list.html', RequestContext(request, context)) -def search_by_category(request, category_id): - category = get_object_or_404(Category, pk=category_id) - - cards_list = list() - - for subcat in category.subcategory_set.all(): - cards_list.extend(subcat.card_set.all()) - - cards = pagination(cards_list, request) - - context = { 'cards' : cards, 'title' : category.label } - - return render_to_response('cards/list.html', RequestContext(request, context)) - -def search_by_subcategory(request, subcategory_id): - subcategory = get_object_or_404(SubCategory, pk=subcategory_id) - - cards = pagination(subcategory.card_set.all(), request) - - context = { 'cards' : cards, 'title' : subcategory.label } - - return render_to_response('cards/list.html', RequestContext(request, context)) diff --git a/static/img/header_pic.png b/static/img/header_pic.png new file mode 100644 index 0000000..e2b23b8 Binary files /dev/null and b/static/img/header_pic.png differ diff --git a/templates/base.html b/templates/base.html index 92140b8..b567cb1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -18,9 +18,9 @@
-
-
- {% block main_container %}{% endblock %} -
+ {% block main_container %}{% endblock %} + diff --git a/templates/cards/Copie de charts.html b/templates/cards/Copie de charts.html deleted file mode 100644 index e9a8869..0000000 --- a/templates/cards/Copie de charts.html +++ /dev/null @@ -1,139 +0,0 @@ -{% extends 'base.html' %} - -{% load image_tags %} - -{% block main_container %} - - - - - - -

Stats, tout ça

- -
- -
- -
- -
- -{% endblock %} diff --git a/templates/cards/about.html b/templates/cards/about.html new file mode 100644 index 0000000..91bc973 --- /dev/null +++ b/templates/cards/about.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} + +{% load image_tags %} + +{% block main_container %} + + + +

A propos

+

Bon bah faut ajouter du texte ici hein :)

+{% endblock %} diff --git a/templates/cards/charts.html b/templates/cards/charts.html index ca2fa98..1e1805e 100644 --- a/templates/cards/charts.html +++ b/templates/cards/charts.html @@ -8,59 +8,19 @@ -

Stats, tout ça

+

-
- -
- -
+
diff --git a/templates/cards/details.html b/templates/cards/details.html index 91128ad..81dc198 100644 --- a/templates/cards/details.html +++ b/templates/cards/details.html @@ -1,5 +1,17 @@ {% load image_tags %} + + diff --git a/templates/cards/index.html b/templates/cards/index.html index accad09..f1d4045 100644 --- a/templates/cards/index.html +++ b/templates/cards/index.html @@ -1,6 +1,7 @@ {% extends 'base.html' %} {% load image_tags %} +{% load inclusion_tags %} {% block main_container %} @@ -13,7 +14,7 @@ */ var word_array = [ {% for tag in tags_list %} - {text: "{{ tag.label }}", weight: {{ tag.occurence }}, link: "{% url list-by-tag tag.id %}"}, + {text: "{{ tag.label }}", weight: {{ tag.occurences }}, link: "{% url list-by-tag tag.id %}"}, {% endfor %} ]; @@ -23,22 +24,21 @@ }); -

Nuage de tags

+
-
+
+
+ +
+
+
+
+
+ +

Derniers ajouts

- +{% cards_list_partial cards_list %} {% endblock %} diff --git a/templates/cards/list.html b/templates/cards/list.html index e897476..d2deddd 100644 --- a/templates/cards/list.html +++ b/templates/cards/list.html @@ -1,46 +1,14 @@ {% extends 'base.html' %} -{% load image_tags %} +{% load inclusion_tags %} {% load filter_tags %} {% block main_container %} - - -

{{ title }}

+{% if tags_list %}
Tags @@ -50,51 +18,13 @@ {% endfor %}
+{% endif %} +{% if cards %}
Cartes - + {% cards_list_partial cards %}
- - +{% endif %} {% endblock %} diff --git a/templates/cards/tags.html b/templates/cards/tags.html new file mode 100644 index 0000000..c141367 --- /dev/null +++ b/templates/cards/tags.html @@ -0,0 +1,57 @@ +{% extends 'base.html' %} + +{% block main_container %} + + + + + +
+ +
+ +{% endblock %} diff --git a/templates/cards_list.html b/templates/cards_list.html new file mode 100644 index 0000000..c911868 --- /dev/null +++ b/templates/cards_list.html @@ -0,0 +1,48 @@ +{% load image_tags %} + + + + + + + diff --git a/urls.py b/urls.py index dd114bf..80a13c6 100644 --- a/urls.py +++ b/urls.py @@ -14,10 +14,10 @@ urlpatterns = patterns('cards.views', url(r'^query/$', 'query'), url(r'^advanced-query/$', 'advanced_query', name='advanced-query'), url(r'^list/country/(?P\d+)/$', 'search_by_country', name='list-by-country'), - url(r'^list/category/(?P\d+)/$', 'search_by_category', name='list-by-category'), - url(r'^list/subcategory/(?P\d+)/$', 'search_by_subcategory', name='list-by-subcategory'), url(r'^list/tag/(?P\d+)/$', 'search_by_tag', name='list-by-tag'), url(r'^charts/$', 'charts', name='charts'), + url(r'^tags/$', 'tags', name='tags'), + url(r'^about/$', 'about', name='about'), url(r'^$', 'index', name='index'), )