Commit 23335a5c authored by gijs's avatar gijs
Browse files

Added page contenttype, labels on instantiating stubs.

parent 6b56c74a
......@@ -13,7 +13,7 @@ from markdown.extensions.toc import TocExtension
from py_etherpad import EtherpadLiteClient
from generator.parse import parse_pads
from generator.models import collectionFor
from generator.utils import info
from generator.utils import info, regroup, try_attributes
from django.template import loader
from django.template.defaultfilters import slugify
......@@ -48,34 +48,12 @@ def output (path, template, context):
info('Writing {} -> {}'.format(template, path))
w.write(loader.render_to_string(template, context))
def generate_single_pages (collection, template, outputdir, make_context):
for model in collection.models:
output(os.path.join(outputdir, model.prefix, '{}.html'.format(model.key)), template, make_context(model))
produser_role_sorting = ['artist', 'co-producer', 'other professional', 'team', ' qpartner']
def regroup (iterable, field):
index = {}
grouped = []
for entry in iterable:
try:
key = getattr(entry, field)
except AttributeError:
key = ''
if not key in index:
grouped.append((key, [ entry ]))
index[key] = grouped[-1]
else:
index[key][1].append(entry)
return grouped
def try_attributes (obj, attributes):
for attr in attributes:
if hasattr(obj, attr):
return getattr(obj, attr)
return ''
class Command(BaseCommand):
args = ''
help = 'Generate a static interpretation of the pads'
......@@ -91,6 +69,7 @@ class Command(BaseCommand):
os.mkdir(outputdir)
os.mkdir(os.path.join(outputdir, 'produsers'))
os.mkdir(os.path.join(outputdir, 'events'))
os.mkdir(os.path.join(outputdir, 'pages'))
info('Copying static files')
......@@ -103,6 +82,7 @@ class Command(BaseCommand):
produsers = collectionFor('produser')
events = collectionFor('event')
pages = collectionFor('page')
grouped_produsers = sorted(regroup(sorted(produsers.models, key=lambda produser: try_attributes(produser, ['name', 'produser'])), 'role'), key=lambda group: produser_role_sorting.index(group[0]) if group[0] in produser_role_sorting else inf)
......@@ -110,11 +90,16 @@ class Command(BaseCommand):
output(os.path.join(outputdir, 'produsers.html'), 'produsers.html', { 'produsers': sorted(produsers.models, key=lambda r: str(r.key)), 'grouped_produsers': grouped_produsers })
output(os.path.join(outputdir, 'produsers.layout.html'), 'produsers.layout.html', { 'produsers': sorted(produsers.models, key=lambda r: str(r.key)), 'grouped_produsers': grouped_produsers })
for produser in produsers.models:
output(os.path.join(outputdir, produser.prefix, '{}.html'.format(produser.key)), 'produser.html', { 'produser': produser })
# for produser in produsers.models:
# output(os.path.join(outputdir, produser.prefix, '{}.html'.format(produser.key)), 'produser.html', { 'produser': produser })
# for event in events.models:
# output(os.path.join(outputdir, event.prefix, '{}.html'.format(event.key)), 'event.html', { 'event': event })
for event in events.models:
output(os.path.join(outputdir, event.prefix, '{}.html'.format(event.key)), 'event.html', { 'event': event })
generate_single_pages(produsers, 'produser.html', outputdir, lambda produser: { 'produser': produser })
generate_single_pages(events, 'event.html', outputdir, lambda event: { 'event': event })
generate_single_pages(pages, 'page.html', outputdir, lambda page: { 'page': page })
output(os.path.join(outputdir, 'index.html'), 'index.html', { 'events': sorted(events.models, key=lambda event: try_attributes(event, ['date']), reverse=True) })
......
......@@ -118,13 +118,19 @@ class Model(object):
labelField = 'title'
metadata = {}
def __init__ (self, key=None, metadata=None, content=None):
def __init__ (self, key=None, label=None, metadata=None, content=None):
# debug('Instantiating model, key: {}, label: {}'.format(key, label))
self.metadata = {}
if key:
self.key = key
else:
self.key = self.extractKey(metadata)
self.metadata = {}
if label:
# debug('Setting label, {}, {}'.format(label, self.labelField))
self.__setattr__(self.labelField, [label])
if metadata:
self.setMetadata(metadata)
......@@ -155,20 +161,20 @@ class Model(object):
for key in metadata:
self.__setattr__(key, metadata[key])
def fill(self, metadata={}, content=None):
def fill(self, metadata={}, content=None, source_path=None):
if metadata:
self.empty = False
self.setMetadata(metadata)
if content:
self.empty = False
self.content = content
if source_path:
self.source_path = source_path
def __setattr__ (self, name, value):
# This might break with the links
if name == 'key':
super().__setattr__('key', value)
elif name == 'metadata':
super().__setattr__('metadata', value)
if name in ['key', 'metadata', 'source_path']:
super().__setattr__(name, value)
elif name == 'content':
super().__setattr__('_content', value)
elif name in self.metadataFields:
......@@ -192,8 +198,10 @@ class Model(object):
elif hasattr(self, self.keyField):
return getattr(self, self.keyField)
else:
debug('Has not attr for to string {}'.format(self.metadata))
return super().__str__()
# @property
# def content (self):
# return self._content
......@@ -220,29 +228,29 @@ class Collection(object):
# # return '[{}]({}){{: .{}}}'.format(self.label, self.target.link, self.target.contentType)
# return '<a href="{target}" class="{className}">{label}</a>'.format(label=self.label, target=self.target.link, className=self.target.contentType)
def __iter__ (self):
return self
# def __iter__ (self):
# return self
def __next__ (self):
self.iterindex = self.iterindex + 1
# def __next__ (self):
# self.iterindex = self.iterindex + 1
if len(self.models) >= self.iterindex:
raise StopIteration
else:
return self.models[self.iterindex]
# if len(self.models) >= self.iterindex:
# raise StopIteration
# else:
# return self.models[self.iterindex]
"""
Retreive a model from the collection with the given key.
Retreive a model from the collection with the given label.
If instantiate is set to true an empty model will be created.
"""
def get (self, key, instantiate=True):
key = keyFilter(key)
if key in self.index:
def get (self, label):
key = keyFilter(label)
if self.has(key):
debug('Found entry for {}'.format(key))
return self.index[key]
elif key and instantiate:
elif key:
debug('Could not find entry for {}, instantiating'.format(key))
return self.instantiateStub(key)
return self.instantiateStub(key=key, label=label)
else:
return None
......@@ -273,8 +281,8 @@ class Collection(object):
self.register(obj)
return obj
def instantiateStub (self, key):
obj = self.model(key=key)
def instantiateStub (self, key, label=None):
obj = self.model(key=key, label=label)
self.register(obj)
return obj
......@@ -289,19 +297,21 @@ class Event (Model):
'title': fields.Single(fields.StringField()),
'summary': fields.Single(fields.MarkdownField()),
'location': fields.Single(fields.StringField()),
'address': fields.StringField()
'address': fields.StringField(),
'tags': linkMultiReverse('tags', 'events')
}
class Produser (Model):
contentType = 'produser'
keyField = 'produser'
labelField = 'produser'
prefix = 'produsers'
metadataFields = {
'role': fields.Single(fields.StringField()),
'name': fields.Single(fields.StringField()),
'produser': fields.Single(fields.StringField()),
'tags': fields.StringField()
'tags': linkMultiReverse('tags', 'produsers')
}
class Trajectory (Model):
......@@ -315,8 +325,9 @@ class Pad (Model):
contentType = 'pad'
metadataFields = {
'produser': linkMultiReverse('produser', 'pads'),
'event': linkMultiReverse('events', 'pads'),
'event': linkMultiReverse('event', 'pads'),
'trajectory': linkMultiReverse('trajectory', 'pads'),
'tags': linkMultiReverse('tags', 'pads'),
'tags': fields.StringField()
}
......@@ -324,14 +335,29 @@ class Note (Model):
contentType = 'note'
metadataFields = {
'produser': linkMultiReverse('produser', 'notes'),
'event': linkMultiReverse('events', 'notes'),
'tags': fields.StringField()
'event': linkMultiReverse('event', 'notes'),
'tags': linkMultiReverse('tag', 'notes')
}
class Page (Model):
contentType = 'page'
keyField = 'name'
keyField = 'title'
labelField = 'title'
prefix = 'pages'
metadataFields = {
'title': fields.Single(fields.StringField()),
'tags': linkMultiReverse('tag', 'pages')
}
class Tag (Model):
contentType = 'tag'
keyField = 'tag'
labelField = 'tag'
metaFields = {
'tag': fields.Single(fields.StringField())
}
# Perhaps include the sort in the collection?
# Might also need to include the outputfolder here
......
......@@ -14,6 +14,23 @@ from etherpadlite.models import Pad
from ethertoff.settings import PAD_NAMESPACE_SEPARATOR, BASE_DIR, DEBUG
"""
We loop through all the pads and 'parse' them as markdown.
This should return both the content and a dictionary for the metadata
From this information a model is contstructed. The metadata is further
parsed depending the field type.
Links will try to look up their targets. If the pad isn't parsed yet a
stub is created to be filled later in the process.
TODO: decouple metadata parsing and linking. To make sure all data is seen
before linking is performed.
"""
def parse_pads ():
epclient = None
......@@ -49,7 +66,7 @@ def parse_pads ():
model = collection.get(key)
if model.empty:
debug('Filling model {}'.format(key))
model.fill(metadata=meta, content=content)
model.fill(metadata=meta, content=content, source_path=pad.display_slug)
else:
error('Model for key {} already filled'.format(key))
......
MENU_ITEMS = [
('About', 'about.html'),
('About', 'pages/about.html'),
('Produsers', 'produsers.html' ),
('Contact', 'contact.html')
]
......
......@@ -15,7 +15,7 @@
</a>
<ul>
{% for label, url in MENU_ITEMS %}
<li><a href="{{ url }}">{{ label }}</a></li>
<li><a href="{{ SITE_URL}}{{ url }}">{{ label }}</a></li>
{% endfor %}
</ul>
</nav>
......@@ -23,11 +23,13 @@
</section>
<section id="header-content">
<p>
{% block header-text %}
<strong>Caveat</strong> tries to find more sustainable, balanced ways of operating within the existing legal frameworks. And when the limits of the existing system are reached, it tries to come up with possible new narratives that open up space for reflection.
{% endblock %}
</p>
{% block header-text %}
<p>
<strong>Caveat</strong> tries to find more sustainable, balanced ways of operating
within the existing legal frameworks. And when the limits of the existing system are
reached, it tries to come up with possible new narratives that open up space for reflection.
</p>
{% endblock %}
</section>
</header>
<main>
......@@ -35,7 +37,10 @@
{% endblock %}
</main>
<footer>
<p class=""><img class="logo-partners" src="{{ SITE_URL }}static/imag/logos/innoviris.svg"/><strong>Caveat</strong> is a co-create research project convened by the Brussels-based artists’ initiative Jubilee, in partnership with Open Source Publishing, No New Enemies and Été 78 and supported by Innoviris, Brussels Institute for Research and Innovation.</p>
<p class=""><img class="logo-partners" src="{{ SITE_URL }}static/imag/logos/innoviris.svg"/>
<strong>Caveat</strong> is a co-create research project convened by the Brussels-based artists’
initiative Jubilee, in partnership with Open Source Publishing, No New Enemies and Été 78 and
supported by Innoviris, Brussels Institute for Research and Innovation.</p>
</footer>
</body>
</html>
\ No newline at end of file
{% extends "generator_base.html" %}
{% block title %}Caveat → events → {{ event.title }}{% endblock %}
{% block content %}
<h1>{{ page.title }}</h1>
{{ page.content}}
{% endblock %}
\ No newline at end of file
......@@ -16,19 +16,23 @@
{{ trajectory.content}}
{% endfor %}
{% endif %}
<h2>Biography</h2>
{{ produser.content }}
{% if produser.events %}
<h2>Events</h2>
<ul>
{% for event in produser.events %}
<li>
<section class="event-preview">
<a href="{{ event.link }}">{{ event.event }} {{ event.title }}</a>
{{ event.summary }}
</section>
</li>
{% endfor %}
</ul>
{% if produser.content %}
<h2>Biography</h2>
{{ produser.content }}
{% endif %}
{% if produser.events %}
<h2>Events</h2>
<ul>
{% for event in produser.events %}
<li>
<section class="event-preview">
<a href="{{ event.link }}">{{ event.event }} {{ event.title }}</a>
{{ event.summary }}
</section>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -175,6 +175,10 @@ main p {
max-width: 47.5em;
}
p {
margin-bottom: var(--line-height);
}
/* ==========================================================================
Page structure
========================================================================== */
......@@ -299,4 +303,8 @@ footer {
footer .logo-partners {
float: right;
}
footer p {
margin-bottom: 0;
}
\ No newline at end of file
......@@ -15,4 +15,30 @@ def debug(*args, color=CYELLOW):
print(color, *args, CEND)
def error(*args):
print(CRED, *args, CEND)
\ No newline at end of file
print(CRED, *args, CEND)
def regroup (iterable, field):
index = {}
grouped = []
for entry in iterable:
try:
key = getattr(entry, field)
except AttributeError:
key = ''
if not key in index:
grouped.append((key, [ entry ]))
index[key] = grouped[-1]
else:
index[key][1].append(entry)
return grouped
def try_attributes (obj, attributes):
for attr in attributes:
if hasattr(obj, attr):
return getattr(obj, attr)
return ''
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment