diff --git a/idre/settings.py b/idre/settings.py index 7bd816b..032c4ac 100644 --- a/idre/settings.py +++ b/idre/settings.py @@ -1,12 +1,4 @@ -""" -Django settings for idre project. - -For more information on this file, see -https://docs.djangoproject.com/en/1.7/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.7/ref/settings/ -""" +""" Django settings for idre project. """ import os @@ -33,7 +25,8 @@ INSTALLED_APPS = ( "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", - "label" + "label", + "news" ) MIDDLEWARE_CLASSES = ( diff --git a/idre/urls.py b/idre/urls.py index 9c300a2..ee1a1c5 100644 --- a/idre/urls.py +++ b/idre/urls.py @@ -5,16 +5,18 @@ from django.contrib import admin import idre.settings import idre.views import label.urls +import news.urls admin.autodiscover() -urlpatterns = [ - url(r"^$", idre.views.home, name = "home") -] + label.urls.urlpatterns + [ - url(r"^admin/", include(admin.site.urls)) -] +urlpatterns = ( + [ url(r"^(?:about/)?$", idre.views.about_view, name = "about") ] + + label.urls.urlpatterns + + news.urls.urlpatterns + + [ url(r"^admin/", include(admin.site.urls)) ] +) if idre.settings.DEBUG: urlpatterns += static( diff --git a/idre/views.py b/idre/views.py index cdc1c70..6d6e5db 100644 --- a/idre/views.py +++ b/idre/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -def home(request): - return render(request, "idre/home.html") +def about_view(request): + return render(request, "about.html") diff --git a/news/__init__.py b/news/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/news/admin.py b/news/admin.py new file mode 100644 index 0000000..d3e8a09 --- /dev/null +++ b/news/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +from news.models import Article + + +admin.site.register(Article) diff --git a/news/apps.py b/news/apps.py new file mode 100644 index 0000000..42c63ba --- /dev/null +++ b/news/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NewsConfig(AppConfig): + name = "news" diff --git a/news/migrations/0001_initial.py b/news/migrations/0001_initial.py new file mode 100644 index 0000000..431368c --- /dev/null +++ b/news/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-02-01 19:25 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Article', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=256)), + ('content', models.TextField(help_text='Markdown formatting supported')), + ('author', models.CharField(max_length=64)), + ('date', models.DateField()), + ], + options={ + 'ordering': ('date',), + }, + ), + ] diff --git a/news/migrations/__init__.py b/news/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/news/models.py b/news/models.py new file mode 100644 index 0000000..8dcd1a6 --- /dev/null +++ b/news/models.py @@ -0,0 +1,15 @@ +from django.db import models + + +ARTICLE_CONTENT_HINT = "Markdown formatting supported" + +class Article(models.Model): + """ News article. """ + + title = models.CharField(max_length = 256) + content = models.TextField(help_text = ARTICLE_CONTENT_HINT) + author = models.CharField(max_length = 64) + date = models.DateField() + + class Meta(object): + ordering = ("date",) diff --git a/news/templates/news/news.html b/news/templates/news/news.html new file mode 100644 index 0000000..9ca0665 --- /dev/null +++ b/news/templates/news/news.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} + +{% load static %} + + +{% block stylesheets %} + +{% endblock %} + + +{% block content %} +
+ +{% for article in articles %} +
+

+ {{ article.title }} + {{ article.author }}, + {{ article.date }} +

+ {% autoescape off %} + {{ article.content }} + {% endautoescape %} +
+ {% if not forloop.last %}
{% endif %} +{% endfor %} + +
+{% endblock %} diff --git a/news/urls.py b/news/urls.py new file mode 100644 index 0000000..8059445 --- /dev/null +++ b/news/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls import url + +import news.views + + +urlpatterns = [ + url(r"^news/$", news.views.articles_view, name = "news"), +] diff --git a/news/views.py b/news/views.py new file mode 100644 index 0000000..4ed474e --- /dev/null +++ b/news/views.py @@ -0,0 +1,12 @@ +from django.shortcuts import render +import markdown + +from news.models import Article + + +def articles_view(request): + articles = Article.objects.all().order_by("date").reverse() + for article in articles: + article.content = markdown.markdown(article.content) + context = { "articles": articles } + return render(request, "news/news.html", context) diff --git a/static/css/news.css b/static/css/news.css new file mode 100644 index 0000000..1873d9f --- /dev/null +++ b/static/css/news.css @@ -0,0 +1,22 @@ +#news article .title { + font-size: 1.2em; + font-weight: bold; +} + +#news article .author, +#news article .date { + font-style: oblique; +} + +#news hr { + border-color: #929292 -moz-use-text-color -moz-use-text-color; + border-right: 0px none; + border-style: solid none none; + border-width: 1px 0px 0px; + margin-bottom: 20px; + margin-top: 20px; + -moz-border-bottom-colors: none; + -moz-border-left-colors: none; + -moz-border-right-colors: none; + -moz-border-top-colors: none; +} diff --git a/idre/templates/idre/home.html b/templates/about.html similarity index 100% rename from idre/templates/idre/home.html rename to templates/about.html diff --git a/idre/templates/idre/base.html b/templates/base.html similarity index 85% rename from idre/templates/idre/base.html rename to templates/base.html index 6ddc909..ac955b5 100644 --- a/idre/templates/idre/base.html +++ b/templates/base.html @@ -23,8 +23,10 @@
@@ -36,4 +38,4 @@ - \ No newline at end of file +