Very, very rudimentary support for making h-entries: they don't look so good and don't appear on the homepage yet but it's a good start
This commit is contained in:
parent
430f8d9a1d
commit
950459cd5f
14 changed files with 161 additions and 2 deletions
1
entries/__init__.py
Normal file
1
entries/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
default_app_config = 'entries.apps.EntriesConfig'
|
5
entries/admin.py
Normal file
5
entries/admin.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import Entry
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Entry)
|
5
entries/apps.py
Normal file
5
entries/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class EntriesConfig(AppConfig):
|
||||||
|
name = 'entries'
|
15
entries/kinds.py
Normal file
15
entries/kinds.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class Note:
|
||||||
|
id = 'note'
|
||||||
|
icon = 'fa fa-paper-plane'
|
||||||
|
plural = 'notes'
|
||||||
|
|
||||||
|
|
||||||
|
class Article:
|
||||||
|
id = 'article'
|
||||||
|
icon = 'fa fa-file-text'
|
||||||
|
plural = 'articles'
|
||||||
|
|
||||||
|
|
||||||
|
all = (Note, Article)
|
||||||
|
from_id = {k.id: k for k in all}
|
||||||
|
from_plural = {k.plural: k for k in all}
|
36
entries/migrations/0001_initial.py
Normal file
36
entries/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.6 on 2017-10-25 00:50
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Entry',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('kind', models.CharField(choices=[('note', 'Note'), ('article', 'Article')], default='note', max_length=30)),
|
||||||
|
('name', models.CharField(blank=True, max_length=100)),
|
||||||
|
('summary', models.TextField(blank=True)),
|
||||||
|
('content', models.TextField()),
|
||||||
|
('published', models.DateTimeField()),
|
||||||
|
('updated', models.DateTimeField()),
|
||||||
|
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name_plural': 'entries',
|
||||||
|
'ordering': ['-published'],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
0
entries/migrations/__init__.py
Normal file
0
entries/migrations/__init__.py
Normal file
33
entries/models.py
Normal file
33
entries/models.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
from . import kinds
|
||||||
|
ENTRY_KINDS = [(k.id, k.__name__) for k in kinds.all]
|
||||||
|
|
||||||
|
|
||||||
|
class Entry(models.Model):
|
||||||
|
kind = models.CharField(
|
||||||
|
max_length=30,
|
||||||
|
choices=ENTRY_KINDS,
|
||||||
|
default=ENTRY_KINDS[0][0]
|
||||||
|
)
|
||||||
|
|
||||||
|
name = models.CharField(max_length=100, blank=True)
|
||||||
|
summary = models.TextField(blank=True)
|
||||||
|
content = models.TextField()
|
||||||
|
|
||||||
|
author = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
published = models.DateTimeField()
|
||||||
|
updated = models.DateTimeField()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{kind} {id}: {content}'.format(
|
||||||
|
kind=self.kind,
|
||||||
|
id=self.id,
|
||||||
|
content=self.content
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = 'entries'
|
||||||
|
ordering = ['-published']
|
24
entries/templates/entries/entry.html
Normal file
24
entries/templates/entries/entry.html
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{% load humanize %}<article class="card h-entry">
|
||||||
|
<div class="card-body">
|
||||||
|
{% if entry.name %}<h4 class="card-title p-name">{{ entry.name }}</h4>{% endif %}
|
||||||
|
<div class="e-content{% if not entry.name %} p-name{% endif %}">{{ entry.content }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<a class="p-author h-card" href="{{ entry.author.url }}">
|
||||||
|
<img class="u-photo" src="{{ entry.author.avatar.url }}" />
|
||||||
|
{{ entry.author.first_name }} {{ entry.author.last_name }}
|
||||||
|
</a>
|
||||||
|
<a class="u-url" href="{{ entry.url }}">
|
||||||
|
<time class="dt-published" datetime="{{ entry.published.isoformat }}">
|
||||||
|
<i class="fa fa-calendar"></i>
|
||||||
|
{{ entry.published | naturaltime }}
|
||||||
|
</time>
|
||||||
|
</a>
|
||||||
|
{% if entry.updated != entry.published %}
|
||||||
|
<time class="dt-updated" datetime="{{ entry.updated.isoformat }}">
|
||||||
|
<i class="fa fa-pencil"></i>
|
||||||
|
{{ entry.updated | naturaltime }}
|
||||||
|
</time>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</article>
|
11
entries/templates/entries/index.html
Normal file
11
entries/templates/entries/index.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{% extends 'lemoncurry/layout.html' %}
|
||||||
|
{% block html_class %}h-feed{% endblock %}
|
||||||
|
{% block main %}
|
||||||
|
<ol class="list-unstyled">
|
||||||
|
{% for entry in entries %}
|
||||||
|
<li>
|
||||||
|
{% include 'entries/entry.html' %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ol>
|
||||||
|
{% endblock %}
|
12
entries/urls.py
Normal file
12
entries/urls.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from django.conf.urls import url
|
||||||
|
from . import kinds, views
|
||||||
|
from lemoncurry import breadcrumbs
|
||||||
|
|
||||||
|
app_name = 'entries'
|
||||||
|
urlpatterns = []
|
||||||
|
for k in kinds.all:
|
||||||
|
index = k.plural + '_index'
|
||||||
|
urlpatterns.extend((
|
||||||
|
url(k.plural, views.index, name=index, kwargs={'kind': k}),
|
||||||
|
))
|
||||||
|
breadcrumbs.add(app_name + ':' + index, label=k.plural, parent='home:index')
|
10
entries/views.py
Normal file
10
entries/views.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
from .models import Entry
|
||||||
|
|
||||||
|
|
||||||
|
def index(request, kind):
|
||||||
|
entries = Entry.objects.filter(kind=kind.id)
|
||||||
|
return render(request, 'entries/index.html', {
|
||||||
|
'entries': entries,
|
||||||
|
'title': kind.plural
|
||||||
|
})
|
|
@ -59,6 +59,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.humanize',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.sitemaps',
|
'django.contrib.sitemaps',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
|
@ -73,6 +74,7 @@ INSTALLED_APPS = [
|
||||||
'meta',
|
'meta',
|
||||||
|
|
||||||
'lemoncurry',
|
'lemoncurry',
|
||||||
|
'entries',
|
||||||
'home',
|
'home',
|
||||||
'lemonauth',
|
'lemonauth',
|
||||||
'users',
|
'users',
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import json
|
import json
|
||||||
from collections import namedtuple
|
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
@ -8,6 +7,7 @@ from django.conf import settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from .. import breadcrumbs
|
from .. import breadcrumbs
|
||||||
|
from entries import kinds
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
cache = SimpleNamespace(package_json=None)
|
cache = SimpleNamespace(package_json=None)
|
||||||
|
@ -45,7 +45,11 @@ def site_name():
|
||||||
|
|
||||||
@register.inclusion_tag('lemoncurry/tags/nav.html')
|
@register.inclusion_tag('lemoncurry/tags/nav.html')
|
||||||
def nav_left(request):
|
def nav_left(request):
|
||||||
items = ()
|
items = (MenuItem(
|
||||||
|
label=k.plural,
|
||||||
|
icon=k.icon,
|
||||||
|
url='entries:'+k.plural+'_index'
|
||||||
|
) for k in kinds.all)
|
||||||
return {'items': items, 'request': request}
|
return {'items': items, 'request': request}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ maps = {'sitemaps': sections}
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url('', include('home.urls')),
|
url('', include('home.urls')),
|
||||||
|
url('', include('entries.urls')),
|
||||||
url('^.well-known/', include('wellknowns.urls')),
|
url('^.well-known/', include('wellknowns.urls')),
|
||||||
url('^admin/', otp_admin_site.urls),
|
url('^admin/', otp_admin_site.urls),
|
||||||
url('^auth/', include('lemonauth.urls')),
|
url('^auth/', include('lemonauth.urls')),
|
||||||
|
|
Loading…
Reference in a new issue