Skip to content

Commit 8af0ac2

Browse files
author
a.shtyrnyaev
committed
update!
2 parents 97fa286 + e602ce5 commit 8af0ac2

File tree

8 files changed

+128
-20
lines changed

8 files changed

+128
-20
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', '🇬🇧')))

apps/news/views.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ def get_context_data(self, **kwargs):
2828
return context
2929

3030

31+
class PostView(TemplateView):
32+
template_name = 'post.html'
33+
34+
def get_context_data(self, **kwargs):
35+
context = super().get_context_data()
36+
pk = self.kwargs.get('pk')
37+
post = Article.objects.get(id=pk)
38+
39+
article_featured = Article.objects.featured()
40+
context.update({
41+
'article_featured': article_featured,
42+
'articles_top': [a for a in Article.objects.active()[:3] if a != article_featured],
43+
'articles_all': [a for a in Article.objects.active()[3:10] if a != article_featured],
44+
'events': Event.objects.upcoming()[:5],
45+
'post': post,
46+
'links': sorted(Link.objects.all(), key=lambda i: Link.SECTION_SLUGS.index(i.section)),
47+
'social_links': [
48+
{'id': 'facebook', 'url': 'https://www.facebook.com/groups/MoscowDjango/', 'name': 'facebook'},
49+
{'id': 'twitter', 'url': 'https://twitter.com/moscowpython', 'name': 'twitter'},
50+
{'id': 'slack', 'url': 'http://slack.python.ru/', 'name': 'slack'},
51+
]
52+
})
53+
return context
54+
55+
3156
class JuniorView(RedirectView):
3257
permanent = True
3358

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 = (
@@ -150,6 +152,17 @@
150152
os.path.join(BASE_DIR, 'media'),
151153
)
152154
MEDIA_URL = '/media/'
155+
CKEDITOR_UPLOAD_PATH = 'uploads/'
156+
157+
CKEDITOR_CONFIGS = {
158+
'default': {
159+
'toolbar': [['Source', 'Link', 'Unlink', 'SpecialChar', 'Image', 'CodeSnippet']],
160+
'height': 400,
161+
'width': 900,
162+
'removePlugins': 'stylesheetparser',
163+
'extraPlugins': 'codesnippet',
164+
},
165+
}
153166

154167
LOGGING = {
155168
'version': 1,

python_ru/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
url(r'^$', news_views.IndexView.as_view(), name='index'),
1313
url(r'^meetups/', include('apps.meetups.urls')),
1414
url(r'^junior/$', news_views.JuniorView.as_view(), name='junior'),
15+
url(r'^post/(?P<pk>\d+)/$', news_views.PostView.as_view(), name='post_page'),
1516

16-
url(r'^admin/', admin.site.urls),
17+
url(r'^admin/', include(admin.site.urls)),
18+
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
1719
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
1820

1921
urlpatterns += staticfiles_urlpatterns()

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>#}
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% extends 'base.html' %}
2+
3+
{% block main_content %}
4+
{% load staticfiles nginx_image %}
5+
<section class="news-section" id="news">
6+
<div class="container">
7+
<div class="js-masonry" data-masonry-options='{"columnWidth": 2, "itemSelector": ".grid-item" }'>
8+
9+
<article class="grid-item large">
10+
<div class="item-holder">
11+
<div class="text-holder">
12+
{% if article_featured.image %}
13+
<img src="{% thumbnail article_featured.image %}" width="792" height="529" alt="">
14+
{% endif %}
15+
<div>
16+
<time datetime="">{{ article_featured.published_at|date:"j E Y" }}</time>
17+
<h1>{{ post.name }}</h1>
18+
{% if post.url %}<time datetime="">{{ post.url }}</time>{% endif %}
19+
<article class="article">
20+
{{ post.text|safe }}
21+
</article>
22+
</div>
23+
</div>
24+
</div>
25+
</article>
26+
27+
{% include 'blocks/news_right_sidebar.html' %}
28+
29+
</div>
30+
31+
</div>
32+
</section>
33+
34+
{% include 'blocks/subscribe.html' %}
35+
{% include 'blocks/links.html' %}
36+
{% endblock %}

0 commit comments

Comments
 (0)