Projet

Général

Profil

« Précédent | Suivant » 

Révision cc12ccfe

Ajouté par Serghei Mihai (congés, retour 15/05) il y a plus de 9 ans

gadjo theme used for templates
Category and announces management views and urls updated

Voir les différences:

corbo/manage_urls.py
10 10
                name='edit_announce'),
11 11
            url(r'^announce/delete/(?P<pk>\d+)$', delete_announce,
12 12
                name='delete_announce'),
13
            url(r'^category/add$', add_category,
14
                name='add_category'),
13 15
            url(r'^category/edit/(?P<pk>\d+)$', edit_category,
14 16
                name='edit_category'),
15 17
            url(r'^category/delete/(?P<pk>\d+)$', delete_category,
corbo/settings.py
10 10

  
11 11
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12 12
import os
13
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14 13

  
14
from django.conf import global_settings
15

  
16
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
15 17

  
16 18
# Quick-start development settings - unsuitable for production
17 19
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
......
32 34
INSTALLED_APPS = (
33 35
    'corbo',
34 36
    'ckeditor',
37
    'gadjo',
35 38
    'django.contrib.auth',
36 39
    'django.contrib.admin',
37 40
    'django.contrib.contenttypes',
......
78 81

  
79 82
USE_TZ = True
80 83

  
84
STATICFILES_FINDERS = global_settings.STATICFILES_FINDERS + ('gadjo.finders.XStaticFinder',)
85

  
81 86

  
82 87
# Static files (CSS, JavaScript, Images)
83 88
# https://docs.djangoproject.com/en/1.7/howto/static-files/
84 89

  
85 90
STATIC_URL = '/static/'
86 91

  
92
STATIC_ROOT = 'static'
93

  
87 94
CKEDITOR_UPLOAD_PATH = 'ckeditor/uploads'
88 95

  
89 96
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
90 97
MEDIA_URL = '/media/'
91 98

  
92
ANNOUNCES_PER_PAGE = 10
99
ANNOUNCES_PER_PAGE = 3
93 100

  
94 101
RSS_TITLE = 'Announces'
95 102
RSS_DESCRIPTION = ''
corbo/static/css/corbo.css
15 15
    margin: 0;
16 16
}
17 17

  
18
a:link, a:visited, a:hover {
19
    text-decoration: none;
20
    color: #000;
21
}
22

  
18 23
header h1 {
19 24
    padding: 5px 10px;
20 25
    border-bottom: 1px solid #000;
......
37 42
    padding: 0;
38 43
}
39 44

  
40
ul.announces li, ul.auth li, ul#management li {
45
ul.announces li, ul.auth li, #management ul li {
41 46
    list-style-type: none;
42 47
    padding: .1em .5em;
43 48
}
44 49

  
45
ul.announces li.bright {
50
li.bright {
46 51
    background: #fff;
47 52
}
48 53

  
49
ul.announces li.grey {
50
    background: #eee;
54
li.bluesky {
55
    background: #d3d8e8 !important;
51 56
}
52 57

  
53 58
div.pub_time {
......
60 65
}
61 66

  
62 67
ul.pagination {
63
    font-size: .8>em;
68
    font-size: .8em;
64 69
    margin: 0;
65 70
    padding: 0;
66 71
}
67 72

  
68
ul.pagination li {
69
    list-style-type: none;
73
#management ul.pagination li {
70 74
    display: inline;
75
    margin: 0 2px;
71 76
}
72 77

  
73 78
ul.pagination li.current {
......
130 135

  
131 136
div.user {
132 137
    font-weight: bold;
138
    font-size: .9em;
133 139
    float: right;
134 140
    margin: 0 10px;
135 141
    padding: 3px;
136
    border: 1px solid #ccc;
142
    border: 1px solid #777;
137 143
    border-top: 0;
138 144
    border-radius: 0 0 .3em .3em;
139
    background: #aaa;
145
    background: #ddd;
140 146
}
141 147

  
142
ul#management {
148
div.user a.logout:before {
149
    content: '\f08b';
150
    margin-left: .4em;
151
}
152

  
153
#management {
143 154
    margin: 1em 0 .5em 0;
155
}
156

  
157
#management ul {
158
    margin: 1em 0 0 0;
144 159
    padding: 0;
145 160
}
146 161

  
147
ul#management li {
162
#management ul li {
148 163
    padding: 5px;
149 164
    border: 1px solid #aaa;
150 165
    background: #eee;
......
153 168
    position: relative;
154 169
}
155 170

  
171
#management h4 {
172
    margin: .4em 0;
173
}
174

  
156 175
.title {
157 176
    font-size: .9em;
158 177
    font-weight: bold;
......
208 227
    width: 20em;
209 228
    color: #aaa;
210 229
    margin: 0 auto;
230
}
231

  
232
.categories {
233
    float: right;
234
}
235

  
236
.categories select {
237
    border: 1px solid #aaa;
238
    display: inline;
239
}
240

  
241
.categories a, #management > span a {
242
    color: #000;
243
    border: 1px solid #666;
244
    padding: 1px 3px;
245
    margin: 0;
246
    font-weight: bold;
247
    font-size: .75em;
248
    background: #eee;
249
}
250

  
251
a.add:before {
252
    content: '\f067';
253
    padding-right:3px;
211 254
}
corbo/templates/base.html
1
{% load i18n static %}
2
<html>
3
  <head>
4
    <title>Corbo :: {% block title %}{%trans "Announces" %}{% endblock %}</title>
5
    <link rel='stylesheet' type='text/css' href='{% static "css/corbo.css" %}' />
6
    {% block scripts %}
7
    {% endblock %}
8
  </head>
9
  <body>
10
    <header>
11
      {% if user.is_authenticated %}
12
      <div class="user">
13
        {% trans "Welcome" %} {{ user.get_full_name }}
14
        <a href="{% url "logout" %}">{% trans "Logout" %}</a>
15
      </div>
16
      {% endif %}
17
      <h1>{% trans "Announces" %}</h1>
18
    </header>
19
    <div id="content">
20
      {% block content %}
21
      {% endblock %}
22
    </div>
23
    <footer>
24
      Powered by Corbo. &copy 2015 Entr'ouvert
25
    </footer>
26
    {% block extrascripts %}
27
    {% endblock %}
28
  </body>
29
</html>
corbo/templates/corbo/announce_form.html
1
{% extends "corbo/manage.html" %}
2
{% load i18n %}
3
{% block content %}
4
<form method="post">
5
  {% csrf_token %}
6
  {{ form.media }}
7
  {{ form.as_p }}
8
  <button>{% trans "Save" %}</button>
9
</form>
10
{% endblock %}
corbo/templates/corbo/base.html
1
{% extends "gadjo/base.html" %}
2
{% load i18n static %}
3
{% block page-title %}{% trans "Corbo" %}{% endblock %}
4

  
5
{% block css %}
6
    <link rel='stylesheet' type='text/css' href='{% static "css/corbo.css" %}' />
7
{% endblock %}
8

  
9
{% block logout-url %}
10
{% url "logout" %}
11
{% endblock %}
12

  
13
{% block site-title %} {% trans "Announces" %}{% endblock %}
14

  
15
{% block more-user-links %}
16
    {{ block.super }}
17
    {% if user.is_authenticated and user.is_superuser %}
18
    <a href="{% url 'manage' %}">{% trans "Management" %}</a>
19
    {% endif %}
20
{% endblock %}
21

  
22
{% block content %}
23
{% endblock %}
corbo/templates/corbo/category_form.html
1
{% extends "corbo/manage.html" %}
2
{% load i18n %}
3
{% block content %}
4
<form method="post">
5
  {% csrf_token %}
6
  {{ form.as_p }}
7
  <button>{% trans "Save" %}</button>
8
</form>
9
{% endblock %}
corbo/templates/corbo/homepage.html
1
{% extends 'corbo/base.html' %}
2
{% load i18n %}
3

  
4
{% block content %}
5
<ul class="announces">
6
{% for object in object_list %}
7
<li class="{% cycle 'bright' 'bluesky' %}">
8
  <h2>{{ object.title }}</h2>
9
  <div class="text">
10
    {{ object.text|safe }}
11
  </div>
12
  <div class="pub_time">
13
    {% blocktrans with pub_date=object.publication_time|date:'DATETIME_FORMAT' %}
14
    Published on {{ pub_date }}
15
    {% endblocktrans %}
16
  </div>
17
  <div class="clear"></div>
18
</li>
19
{% empty %}
20
{% trans "No announces published yet" %}
21
{% endfor %}
22
</ul>
23
{% endblock %}
corbo/templates/corbo/manage.html
1
{% extends 'corbo/base.html' %}
2
{% load i18n static %}
3
{% block page-title %}
4
{{ block.super }} :: {% trans "Management" %}
5
{% endblock %}
6

  
7

  
8

  
9
{% block content %}
10
<div class="categories">
11
  <span class="title">{% trans "Category:" %}</span>
12
  <select>
13
    <option value=''>{% trans "All" %}</option>
14
    {% for category in categories %}
15
    <option value='{{ category.id }}'{% if category_id == category.id %} selected{% endif %}>{{ category }}</option>
16
    {% endfor %}
17
  </select>
18
  <span><a class="icon add" href="{% url "add_category" %}" rel="popup">{% trans "add category" %}</a></span>
19
</div>
20
<div id="management">
21
  <h4>{% trans "Announces" %}</h4>
22
  <span><a class="icon add" href="{% url "add_announce" %}" rel="popup">{% trans "add announce" %}</a></span>
23
<ul>
24
{% for obj in object_list %}
25
<li class='{% cycle 'bluesky' '' %}'>
26
  <div class="status">
27
    {% if obj.is_published %}
28
    <span class="icon published" title="{% trans "published" %}"></span>
29
    {% endif %}
30
    {% if not obj.is_published %}
31
    {% if obj.is_expired %}
32
    <span class="icon expired" title="{% trans "expired" %}"></span>
33
    {% else %}
34
    <span class="icon unpublished" title="{% trans "not published yet" %}"></span>
35
    {% endif %}
36
    {% endif %}
37
  </div>
38
  <div class="actions">
39
    <span><a class="icon edit" href="{% url 'edit_announce' obj.id %}" rel="popup"></a></span>
40
    <span><a class="icon delete" href="{% url 'delete_announce' obj.id %}" rel="popup"></a></span>
41
  </div>
42
  <div class="announce">
43
    <div class="title">{{ obj.title }}</div>
44
    <div class="text_preview">{{ obj.text|safe|truncatechars_html:128 }}</div>
45
  </div>
46
</li>
47
{% empty %}
48
<div class="empty">
49
  {% trans "No announces matching this category" %}
50
</div>
51
{% endfor %}
52
</ul>
53

  
54
{% if is_paginated %}
55
<ul class="pagination">
56
  {% if page_obj.has_previous %}
57
  <li class="prev">
58
    <a href="?{% if category_id %}category={{ category_id}}&{% endif %}page={{ page_obj.previous_page_number }}" class="icon"></a>
59
  </li>
60
  {% endif %}
61
  <li class="current">
62
    page {{ page_obj.number }} of {{ paginator.num_pages }}
63
  </li>
64
  {% if page_obj.has_next %}
65
  <li class="next">
66
    <a href="?{% if category_id %}category={{ category_id}}&{% endif %}page={{ page_obj.next_page_number }}" class="icon"></a>
67
  </li>
68
  {% endif %}
69
</ul>
70
{% endif %}
71
</div>
72
{% endblock %}
73

  
74
{% block page-end %}
75
<script type="text/javascript">
76
  $(function() {
77
    $('div.categories select').on('change', function() {
78
        var category = $(this).val();
79
        if (category)
80
            window.location.replace('{% url "manage" %}?category=' + category);
81
        else
82
            window.location.replace({% url "manage" %});
83
    })
84
})
85
</script>
86
{% endblock %}
corbo/templates/homepage.html
1
{% extends 'base.html' %}
2
{% load i18n %}
3

  
4
{% block content %}
5
<ul class="announces">
6
{% for object in object_list %}
7
<li class="{% cycle 'bright' 'grey' %}">
8
  <h2>{{ object.title }}</h2>
9
  <div class="text">
10
    {{ object.text|safe }}
11
  </div>
12
  <div class="pub_time">
13
    {% blocktrans with pub_date=object.publication_time|date:'DATETIME_FORMAT' %}
14
    Published on {{ pub_date }}
15
    {% endblocktrans %}
16
  </div>
17
  <div class="clear"></div>
18
</li>
19
{% empty %}
20
{% trans "No announces published yet" %}
21
{% endfor %}
22
</ul>
23
{% endblock %}
corbo/templates/manage.html
1
{% extends 'base.html' %}
2
{% load i18n static %}
3
{% block title %}{% trans "Management" %}{% endblock %}
4

  
5
{% block scripts %}
6
<script type="text/javascript" src="{% static "js/jquery-1.11.2.min.js" %}"></script>
7
<script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
8
<script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
9
<script type="text/javascript" src="{% static "js/corbo.js" %}"></script>
10
{% endblock %}
11

  
12
{% block content %}
13
<div class="category">
14
  <span class="title">{% trans "Category:" %}</span>
15
  <select>
16
    <option value=''>{% trans "All" %}</option>
17
    {% for category in categories %}
18
    <option value='{{ category.id }}'{% if category_id == category.id %} selected{% endif %}>{{ category }}</option>
19
    {% endfor %}
20
  </select>
21
</div>
22
<ul id="management">
23
{% for obj in object_list %}
24
<li>
25
  <div class="status">
26
    {% if obj.is_published %}
27
    <span class="icon published" title="{% trans "published" %}"></span>
28
    {% endif %}
29
    {% if obj.is_expired %}
30
    <span class="icon expired" title="{% trans "expired" %}"></span>
31
    {% endif %}
32
    {% if obj.is_not_published %}
33
    <span class="icon unpublished" title="{% trans "not published yet" %}"></span>
34
    {% endif %}
35
  </div>
36
  <div class="actions">
37
    <span class="icon edit"><a href="#"></a></span>
38
    <span class="icon delete"><a href="#"></a></span>
39
  </div>
40
  <div class="announce">
41
    <div class="title">{{ obj.title }}</div>
42
    <div class="text_preview">{{ obj.text|safe|truncatechars_html:128 }}</div>
43
  </div>
44
</li>
45
{% empty %}
46
<div class="empty">
47
  {% trans "No announces matching this category" %}
48
</div>
49
{% endfor %}
50
</ul>
51

  
52
{% if is_paginated %}
53
<ul class="pagination">
54
  {% if page_obj.has_previous %}
55
  <li class="prev">
56
    <a href="?{% if category_id %}category={{ category_id}}&{% endif %}page={{ page_obj.previous_page_number }}" class="icon"></a>
57
  </li>
58
  {% endif %}
59
  <li class="current">
60
    page {{ page_obj.number }} of {{ paginator.num_pages }}
61
  </li>
62
  {% if page_obj.has_next %}
63
  <li class="next">
64
    <a href="?{% if category_id %}category={{ category_id}}&{% endif %}page={{ page_obj.next_page_number }}" class="icon"></a>
65
  </li>
66
  {% endif %}
67
</ul>
68
{% endif %}
69
{% endblock %}
70
{% block extrascripts %}
71
<script type="text/javascript">
72
  $(function() {
73
    $('div.category select').on('change', function() {
74
        var category = $(this).val();
75
        if (category)
76
            window.location.replace('{% url "manage" %}?category=' + category);
77
        else
78
            window.location.replace({% url "manage" %});
79
    })
80
})
81
</script>
82
{% endblock %}
corbo/templates/registration/login.html
1
{% extends 'base.html' %}
1
{% extends 'corbo/base.html' %}
2 2
{% load i18n %}
3
{% block title %}{% trans "Login" %}{% endblock %}
3
{% block page-title %}{{ block.super }} :: {% trans "Login" %}{% endblock %}
4 4
{% block content %}
5 5
<form method="post">
6 6
  <ul class="auth">
corbo/views.py
7 7
from django.contrib.syndication.views import Feed
8 8
from django.utils.feedgenerator import Atom1Feed
9 9

  
10

  
11 10
import models
11
from .forms import AnnounceForm, CategoryForm
12 12

  
13 13
class HomepageView(ListView):
14 14
    model = models.Announce
15
    template_name = 'homepage.html'
15
    template_name = 'corbo/homepage.html'
16 16

  
17 17
homepage = HomepageView.as_view()
18 18

  
19 19
class AnnounceCreateView(CreateView):
20
    model = models.Announce
20
    form_class = AnnounceForm
21
    template_name = 'corbo/announce_form.html'
22
    success_url = '..'
21 23

  
22 24
add_announce = AnnounceCreateView.as_view()
23 25

  
24 26
class AnnounceEditView(UpdateView):
25 27
    model = models.Announce
28
    success_url = '../..'
26 29

  
27 30
edit_announce = AnnounceEditView.as_view()
28 31

  
29 32
class AnnounceDeleteView(DeleteView):
33
    success_url = '../..'
30 34
    model = models.Announce
31 35

  
32 36
delete_announce = AnnounceDeleteView.as_view()
33 37

  
34
edit_announce = AnnounceEditView.as_view()
35

  
36 38
class CategoryCreateView(CreateView):
37
    model = models.Category
39
    form_class = CategoryForm
40
    template_name = 'corbo/category_form.html'
41
    success_url = '..'
42

  
43
    def form_valid(self, form):
44
        form.save()
45
        return super(CategoryCreateView, self).form_valid(form)
38 46

  
39 47
add_category = CategoryCreateView.as_view()
40 48

  
41 49
class CategoryEditView(UpdateView):
42 50
    model = models.Category
51
    success_url = '..'
43 52

  
44 53
edit_category = CategoryEditView.as_view()
45 54

  
......
51 60

  
52 61
class ManageView(ListView, MultipleObjectMixin):
53 62
    paginate_by = settings.ANNOUNCES_PER_PAGE
54
    template_name = 'manage.html'
63
    template_name = 'corbo/manage.html'
55 64
    model = models.Announce
56 65

  
57 66
    def get_queryset(self):

Formats disponibles : Unified diff