Skip to content

Commit e602ce5

Browse files
author
a.shtyrnyaev
committed
- add WYSIWYG "Django CKEditor"
- add page post - divided link_post and text_post - made in a separate file block news_right_sidebar
1 parent cde1e8e commit e602ce5

File tree

8 files changed

+70
-37
lines changed

8 files changed

+70
-37
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.8 on 2018-01-13 10:37
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('news', '0004_auto_20161002_2204'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='article',
17+
name='is_our',
18+
field=models.BooleanField(default=False, verbose_name='Наш пост?'),
19+
),
20+
migrations.AddField(
21+
model_name='article',
22+
name='text',
23+
field=models.TextField(blank=True, verbose_name='Текст'),
24+
),
25+
]

apps/news/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.db.models import QuerySet
33
from model_utils import Choices
44
from model_utils.models import TimeStampedModel
5+
from ckeditor_uploader.fields import RichTextUploadingField
56

67

78
class ArticleQuerySet(QuerySet):
@@ -20,6 +21,8 @@ class Article(TimeStampedModel):
2021
url = models.URLField('URL')
2122
name = models.CharField('Заголовок', max_length=1024)
2223
description = models.TextField('Описание', blank=True)
24+
text = RichTextUploadingField('Текст', blank=True, default='')
25+
is_our = models.BooleanField('Наш пост?', default=False)
2326
published_at = models.DateTimeField('Дата публикации')
2427
section = models.CharField('Категория', max_length=100, blank=True)
2528
language = models.CharField('Язык', max_length=2, choices=Choices(('ru', '🇷🇺'), ('en', '🇬🇧')))

python_ru/settings.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
'apps.events',
4949
'apps.news',
5050
'apps.meetups',
51+
'ckeditor',
52+
'ckeditor_uploader',
5153
)
5254

5355
MIDDLEWARE_CLASSES = (
@@ -144,6 +146,17 @@
144146

145147
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
146148
MEDIA_URL = '/media/'
149+
CKEDITOR_UPLOAD_PATH = 'uploads/'
150+
151+
CKEDITOR_CONFIGS = {
152+
'default': {
153+
'toolbar': [['Source', 'Link', 'Unlink', 'SpecialChar', 'Image', 'CodeSnippet']],
154+
'height': 400,
155+
'width': 900,
156+
'removePlugins': 'stylesheetparser',
157+
'extraPlugins': 'codesnippet',
158+
},
159+
}
147160

148161
LOGGING = {
149162
'version': 1,

python_ru/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
url(r'^post/(?P<pk>\d+)/$', news_views.PostView.as_view(), name='post_page'),
1414

1515
url(r'^admin/', include(admin.site.urls)),
16+
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
1617
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

templates/blocks/news.html

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,14 @@
1111
{% endif %}
1212
<div class="description">
1313
<time datetime="">{{ article_featured.published_at|date:"j E Y" }}</time>
14-
<h1><a href="{{ article_featured.url }}" target="_blank">
14+
<h1><a {% if not article_featured.is_our %}href="{{ article_featured.url }}" target="_blank"{% else %}href="{% url 'post_page' article_featured.id %}"{% endif %}>
1515
{{ article_featured.name }}
1616
</a></h1>
1717
</div>
1818
</div>
1919
</article>
2020

21-
{# News right sidebar #}
22-
<section class="grid-item articles-list">
23-
<div class="item-holder">
24-
<strong class="title">Новости</strong>
25-
<div class="articles-holder">
26-
{% for article in articles_top %}
27-
<article class="article">
28-
<time datetime="{{ event.date|date:"Y-m-d H:m" }}">{{ article.published_at|date:"j E Y" }}</time>
29-
<h1><a href="{{ article.url }}" target="_blank">
30-
{{ article.name }}
31-
</a></h1>
32-
</article>
33-
{% endfor %}
34-
</div>
35-
</div>
36-
</section>
21+
{% include 'blocks/news_right_sidebar.html' %}
3722

3823
{% for article in articles_all %}
3924
<article class="grid-item">
@@ -45,14 +30,13 @@ <h1><a href="{{ article.url }}" target="_blank">
4530
{% endif %}
4631
<div class="text-holder">
4732
<time datetime="{{ event.date|date:"Y-m-d H:m" }}">{{ article.published_at|date:"j E Y" }}</time>
48-
<h1><a href="{{ article.url }}" target="_blank">{{ article.name }}</a></h1>
33+
<h1><a {% if not article.is_our %}href="{{ article.url }}" target="_blank"{% else %}href="{% url 'post_page' article.id %}" {% endif %}>{{ article.name }}</a></h1>
4934
{{ article.description|safe }}
5035
</div>
5136
</div>
5237
</article>
5338
{% endfor %}
5439
</div>
55-
5640
{# <div class="btn-holder">#}
5741
{# <a href="#" class="btn-default btn-more">Показать ещё</a>#}
5842
{# </div>#}

templates/blocks/news_post.html

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
{# News right sidebar #}
3+
<section class="grid-item articles-list">
4+
<div class="item-holder">
5+
<strong class="title">Новости</strong>
6+
<div class="articles-holder">
7+
{% for article in articles_top %}
8+
<article class="article">
9+
<time datetime="{{ event.date|date:"Y-m-d H:m" }}">{{ article.published_at|date:"j E Y" }}</time>
10+
<h1><a {% if not article.is_our %}href="{{ article.url }}" target="_blank"{% else %}href="{% url 'post_page' article.id %}" {% endif %}>
11+
{{ article.name }}
12+
</a></h1>
13+
</article>
14+
{% if not article.is_our %}
15+
<time>{{ article.url }}</time>
16+
{% endif %}
17+
{% endfor %}
18+
</div>
19+
</div>
20+
</section>

templates/post.html

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,21 @@
1010
<div class="item-holder">
1111
<div class="text-holder">
1212
{% if article_featured.image %}
13-
<img src="{% thumbnail article_featured.image 792 529 %}" width="792" height="529" alt="">
13+
<img src="{% thumbnail article_featured.image %}" width="792" height="529" alt="">
1414
{% endif %}
15-
<div class="description">
15+
<div>
1616
<time datetime="">{{ article_featured.published_at|date:"j E Y" }}</time>
1717
<h1>{{ post.name }}</h1>
18+
{% if post.url %}<time datetime="">{{ post.url }}</time>{% endif %}
1819
<article class="article">
19-
{{ post.description }}
20+
{{ post.text|safe }}
2021
</article>
2122
</div>
2223
</div>
2324
</div>
2425
</article>
2526

26-
{# News right sidebar #}
27-
<section class="grid-item articles-list">
28-
<div class="item-holder">
29-
<strong class="title">Новости</strong>
30-
<div class="articles-holder">
31-
{% for article in articles_top %}
32-
<time datetime="{{ event.date|date:"Y-m-d H:m" }}">{{ article.published_at|date:"j E Y" }}</time>
33-
<h1><a href="{{ article.url }}" target="_blank">
34-
{{ article.name }}
35-
</a></h1>
36-
</article>
37-
{% endfor %}
38-
</div>
39-
</div>
40-
</section>
27+
{% include 'blocks/news_right_sidebar.html' %}
4128

4229
</div>
4330

0 commit comments

Comments
 (0)