Skip to content

Commit

Permalink
Update example project.
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesfabio committed Jan 14, 2016
1 parent d074afa commit bd7d896
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 172 deletions.
3 changes: 3 additions & 0 deletions example/management/commands/create_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# -*- coding: utf-8 -*-
import logging
import random

from optparse import make_option

from django.core import management
from django.core.management.base import BaseCommand
from django.db import DEFAULT_DB_ALIAS, IntegrityError
from django.utils.text import slugify

from random_words import RandomNicknames

from badgify.models import Badge, Award

from example.models import User
Expand Down
26 changes: 20 additions & 6 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
PROJECT_DIR = os.path.dirname(__file__)

SECRET_KEY = 'l8h=t&zq%7f_vv8ge3@0jw^qgvedz*82j2$2rkbr^)i*y0p&x('

DEBUG = True
TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = (
Expand All @@ -17,9 +18,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'badgify',

'example',
)

Expand Down Expand Up @@ -56,9 +55,24 @@

AUTH_USER_MODEL = 'example.User'

TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates'),
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]

LOGGING = {
'version': 1,
Expand Down
24 changes: 12 additions & 12 deletions example/templates/_pagination.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% if is_paginated %}
<ul class="pagination pagination-centered">
{% if page_obj.has_previous %}
<li><a href="?page=1">⟪⟪</a></li>
<li><a href="?page={{ page_obj.previous_page_number }}"></a></li>
{% endif %}
{% for i in paginator.page_range %}
<li {% if page_obj.number == i %} class="active" {% endif %}><a href="?page={{i}}">{{i}}</a></li>
{% endfor %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}"></a></li>
<li><a href="?page={{ page_obj.paginator.num_pages }}">⟫⟫</a></li>
{% endif %}
<ul class="pagination">
{% if page_obj.has_previous %}
<li><a href="?page=1">⟪⟪</a></li>
<li><a href="?page={{ page_obj.previous_page_number }}"></a></li>
{% endif %}
{% for i in paginator.page_range %}
<li {% if page_obj.number == i %} class="active" {% endif %}><a href="?page={{i}}">{{i}}</a></li>
{% endfor %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}"></a></li>
<li><a href="?page={{ page_obj.paginator.num_pages }}">⟫⟫</a></li>
{% endif %}
</ul>
{% endif %}
34 changes: 8 additions & 26 deletions example/templates/badgify/badge_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,13 @@
{% endblock %}

{% block content %}
<div class="row">
<div class="col-md-9">
<div class="row">
{% for user in awarded_users %}
<div class="col-md-2">
<div class="user text-center">
<a href="{% url 'home' %}">
<img src="http://placehold.it/80x80" alt="{{ user.username }}" class="img-circle">
</a>
<div class="caption">
<h5 class="text-center">{{ user.username }}</h5>
</div>
</div>
</div>
{% endfor %}
</div>
<h1>{{ badge.name }}</h1>
<p><em>{{ badge.description }}</em></p>
<p><strong>{{ badge.users_count }} users</strong>:</p>
<ul>
{% for user in awarded_users %}
<li>{{ user.username }}</li>
{% endfor %}
</ul>
{% include "_pagination.html" %}
</div>
<div class="col-md-3">
<div class="thumbnail text-center">
<h1>{{ badge.name }}</h1>
<img src="{% if badge.image %}{{ badge.image }}{% else %}http://placehold.it/150x150{% endif %}" alt="{{ badge.name }}">
<p class="text-muted">{{ badge.description }}</p>
<p class="text-center"><span class="glyphicon glyphicon-user"></span> {{ badge.users_count }}</p>
</div>
</div>
</div>
{% endblock %}
48 changes: 17 additions & 31 deletions example/templates/badgify/badge_list.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
{% extends "base.html" %}
{% load i18n %}

{% block title %}
{% trans "Badges" %}
{% endblock %}
{% block title %}Badges{% endblock %}

{% block content %}
<div class="badgify-badge-list">
<h2>{% trans "Badges" %}</h2>
{% if not badges %}
<div class="alert alert-success" role="alert">
<p>{% trans "No badges yet." %}</p>
</div>
{% else %}
<div class="row">
{% for badge in badges %}
<div class="col-md-3">
<div class="thumbnail text-center">
<a href="{{ badge.get_absolute_url }}">
<img src="{% if badge.image %}{{ badge.image }}{% else %}http://placehold.it/140x140{% endif %}" alt="{{ badge.name }}">
</a>
<div class="caption">
<h4 class="text-center">{{ badge.name }}</h4>
<p class="text-muted">{{ badge.description }}</p>
<p class="text-center"><span class="glyphicon glyphicon-user"></span> {{ badge.users_count }}</p>
</div>
</div>
</div>
{% endfor %}
{% include "_pagination.html" %}
</div>
{% endif %}
</div>
{% if not badges %}
<p>No badges yet.</p>
{% else %}
<ul>
{% for badge in badges %}
<li>
<h4><a href="{{ badge.get_absolute_url }}">{{ badge.name }}</a></h4>
<ul>
<li><em>{{ badge.description }}</em></li>
<li><strong>{{ badge.users_count }} users</strong></li>
</ul>
</li>
{% endfor %}
</ul>
{% include "_pagination.html" %}
{% endif %}
{% endblock %}

49 changes: 13 additions & 36 deletions example/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
{% load staticfiles i18n %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Badgify | {% block title %}{% endblock %}</title>
<link href="{% static 'vendor/bootstrap/dist/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'vendor/bootstrap/dist/css/bootstrap-theme.min.css' %}" rel="stylesheet">
<link href="{% static 'main.css' %}" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'home' %}">Badgify</a>
<head>
<meta charset="utf-8">
<title>Badgify | {% block title %}{% endblock %}</title>
</head>
<body>
<header>
<h1><a href="{% url 'badge_list' %}">Home</a></h1>
</header>
<hr>
<div class="content">
{% block content %}
{% endblock %}
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav pull-right">
<li><a href="{% url 'home' %}">Home</a></li>
<li><a href="{% url 'badge_list' %}">Badges</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
{% block content %}
{% endblock %}
</div>
<script src="{% static 'vendor/jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'vendor/bootstrap/dist/js/bootstrap.min.js' %}"></script>
</body>
</body>
</html>
56 changes: 0 additions & 56 deletions example/templates/home.html

This file was deleted.

9 changes: 4 additions & 5 deletions example/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView

urlpatterns = patterns('',
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^badges/', include('badgify.urls')),
url(r'^$', TemplateView.as_view(template_name='home.html'), name='home')
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
url(r'', include('badgify.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

0 comments on commit bd7d896

Please sign in to comment.