Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
577ea80
Move get_cached_with_mtime to separate module
akx Nov 4, 2016
6e4c1b9
Augment `twitter_search` results with `.html`
akx Nov 4, 2016
454c74b
Merge pull request #64 from City-of-Helsinki/augmentwitter
juyrjola Nov 7, 2016
b8a76bb
Update front page event info
terotik Nov 11, 2016
88a28c1
Merge pull request #68 from terotic/master
vikoivun Nov 11, 2016
0c4a2cd
Update front page event info
terotik Nov 18, 2016
75609cd
Merge pull request #69 from terotic/master
vikoivun Nov 18, 2016
6af8112
Add Twitter feed on front page, restyle blog feed on front page (#71)
terotik Dec 7, 2016
59a9a1f
Upgrade Django
juyrjola Dec 8, 2016
3fb5cbe
Catch errors if twitter tokens are missing or invalid
Rikuoja Dec 16, 2016
9bf6f6b
Add digiserviceguide page models, templates and styles
terotik Dec 19, 2016
5634b68
Hotfix for twitter tags
juyrjola Dec 19, 2016
84a8cd6
Minor style and content changes on guide pages
terotik Dec 19, 2016
148e3ff
Fix guide pages migration
terotik Dec 21, 2016
298e4d5
Upgrade Pillow dependency
juyrjola Jan 13, 2017
d203541
Remove line under blog post header, increase blog post image height o…
terotik Jan 16, 2017
5666f5d
Fix anchor point positioning on digi guide principles page
terotik Jan 16, 2017
91db28f
Add Twitter link on front page hashtag headline
terotik Jan 16, 2017
3e88b83
Add event list (#70)
Rikuoja Jan 19, 2017
b996b4c
Add twitter hashtag-feed on project pages
terotik Jan 16, 2017
01c114c
Add and use Django Social Widgets on blog posts
terotik Jan 19, 2017
1f6af1e
Only display future events in events page
Rikuoja Jan 19, 2017
c66d11a
add fields to Indicator model
hkotkanen Jan 24, 2017
b2aad50
show added fields on the front page
hkotkanen Jan 24, 2017
5b6d662
add management command to update indicators
hkotkanen Jan 24, 2017
20b3ae3
added logic for updating varaukset KPI in management command
hkotkanen Jan 25, 2017
4ed859c
Merge pull request #87 from hkotkanen/feature-frontpage-indicators
hkotkanen Feb 7, 2017
f06e638
Add __init__.py files to templatetags directories
jukvalim Feb 8, 2017
1326230
#80 In kehmet, generate table of contents automatically from h2 tags,…
jukvalim Feb 8, 2017
0011aad
#80 Fix if-statement parentheses
jukvalim Feb 8, 2017
cd905fd
Restyle events index page, make boxes even height
terotik Jan 20, 2017
6465c39
Run matchHeight after all events are added
terotik Feb 9, 2017
97cb6a6
Merge pull request #85 from terotic/visual-fine-tuning
Rikuoja Feb 13, 2017
5f974e1
Merge pull request #90 from jukvalim/master
Rikuoja Feb 13, 2017
76d4454
Add TOC element on kehmet content-template
terotik Nov 24, 2016
55e9be7
Restyle automatic page toc. Make kehmet side navigation floating
terotik Feb 14, 2017
0f32f31
Make blog templates support multiple blogs. Show related blog content…
terotik Feb 9, 2017
b3a2ebe
Add text field on person index page
terotik Feb 15, 2017
c9dd32f
Create service phase custom tag and add phases model on Project Page
terotik Feb 9, 2017
0986e5b
Merge pull request #95 from terotic/feature-project-phases
tituomin Feb 15, 2017
f2fe009
Merge pull request #94 from terotic/visual-fine-tuning
tituomin Feb 15, 2017
95ee992
Merge pull request #91 from terotic/feature-page-toc
jussiarpalahti Feb 15, 2017
e8b7b45
Merge pull request #93 from terotic/feature-multiple-blogs
jussiarpalahti Feb 15, 2017
55ea00a
Merge branch 'master' into glossary
jukvalim Feb 20, 2017
5c878df
#86 Creating and linking to glossary pages
jukvalim Feb 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
91 changes: 91 additions & 0 deletions content/templatetags/content_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import re
from collections import Sequence

from bs4 import BeautifulSoup

from django import template
from django.utils.safestring import mark_safe

from wagtail.wagtailcore.blocks.base import BoundBlock
from wagtail.wagtailcore.rich_text import RichText

register = template.Library()


Expand Down Expand Up @@ -97,3 +105,86 @@ def sidebar_page_nav(page):
html = list_children(parent, page)

return mark_safe(html)


class TableOfContentsNode(template.Node):
def __init__(self, html_accessor, toc_var_name):
self.html_accessor = html_accessor
self.html_var = template.Variable(html_accessor)
self.toc_var_name = toc_var_name

def render(self, context):

blocks = self.html_var.resolve(context)

if not isinstance(blocks, Sequence):
blocks = [blocks]

headings_and_anchors = []
toc_anchor_count = 1

for block in blocks:
if (not isinstance(block, BoundBlock) or not
isinstance(block.value, RichText)):
continue
soup = BeautifulSoup(block.value.source)
h2_tags = soup.find_all('h2')

if not h2_tags:
continue

for t in h2_tags:
# let's not add empty headings to table of contents
if not t.string.strip():
continue
anchor = 'toc-{}'.format(toc_anchor_count)
headings_and_anchors.append((t.string, anchor))
t.insert_before(soup.new_tag('span', id=anchor, **{'class':'toc-anchor'}))
toc_anchor_count += 1

new_source = str(soup)
# See wagtail.wagtailcore.rich_text expand_db_html and
# replace_embed_tag - if the embed tag doesn't close itself,
# replace_embed_tag doesn't recognize it, and can't replace it
# with img tag
new_source = new_source.replace('></embed>', '/>')
block.value.source = new_source


context[self.toc_var_name] = headings_and_anchors

return ''

def __unicode__(self):
return u'String repr'


def do_table_of_contents(parser, token):
"""
Use like this:
{% do_table_of_contents <context variable> as
<table of contents item list> %}

This takes a WagTail BoundBlock or a list of them, and for each block with
RichText value, goes through H2 elements, and adds an anchor to them. It
puts out a list or headings and anchors, as in
[('Heading 1', 'toc-1'), ...], which can be used to render a table of
contents in the template.
"""
try:
# Splitting by None == splitting by spaces.
tag_name, arg = token.contents.split(None, 1)
except ValueError:
raise template.TemplateSyntaxError(
"%r tag requires arguments" % token.contents.split()[0]
)
m = re.search(r'(.*?) as (\w+)', arg)
if not m:
raise template.TemplateSyntaxError("%r tag had invalid arguments" %
tag_name)
format_string, var_name = m.groups()

return TableOfContentsNode(format_string, var_name)


register.tag('do_table_of_contents', do_table_of_contents)
45 changes: 45 additions & 0 deletions digi/management/commands/update_indicators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.core.management.base import BaseCommand, CommandError
from digi.models import Indicator
from datetime import date, timedelta
import requests

class Command(BaseCommand):
help = 'Fetches and saves new indicator values'

def handle(self, *args, **options):
for indicator in Indicator.objects.all():

#POPULATION
if indicator.slug == 'vaesto':
continue
# indicator.value = indicator.value + 1

#HRI DATASETS
elif indicator.slug == 'tietoaineistot':
try:
resp = requests.get('http://hri.fi/api/3/action/package_list')
indicator.value = len(resp.json()['result'])
except Exception as e:
raise CommandError('Something went wrong while updating indicator {}. Retaining previous value {}.'.format(indicator.slug, indicator.value))

#OPEN311 ISSUES
elif indicator.slug == 'palaute':
try:
week_ago = (date.today() - timedelta(days=7)).isoformat()
resp = requests.get('https://asiointi.hel.fi/palautews/rest/v1/requests.json?status=closed&start_date={}'.format(week_ago))
# today = date.today().isoformat()
# resp = requests.get('https://asiointi.hel.fi/palautews/rest/v1/requests.json?status=closed&start_date={}'.format(today))
indicator.value = len(resp.json())
except Exception as e:
raise CommandError('Something went wrong while updating indicator {}. Retaining previous value {}.'.format(indicator.slug, indicator.value))

elif indicator.slug == 'varaukset':
try:
resp = requests.get('http://api.hel.fi/respa/v1/reservation?all=true')
indicator.value = resp.json()['count']
except Exception as e:
raise CommandError('Something went wrong while updating indicator {}. Retaining previous value {}.'.format(indicator.slug, indicator.value))


indicator.save()
self.stdout.write(self.style.SUCCESS('Successfully updated indicator {}. Value is now {}'.format(indicator.slug, indicator.value)))
28 changes: 28 additions & 0 deletions digi/migrations/0009_guidefrontpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.10 on 2016-11-24 13:05
from __future__ import unicode_literals

import digihel.mixins
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0029_unicode_slugfield_dj19'),
('digi', '0008_auto_20160909_1909'),
]

operations = [
migrations.CreateModel(
name='GuideFrontPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
],
options={
'abstract': False,
},
bases=(digihel.mixins.RelativeURLMixin, 'wagtailcore.page'),
),
]
33 changes: 33 additions & 0 deletions digi/migrations/0010_guidecontentpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2016-12-14 11:03
from __future__ import unicode_literals

import digihel.mixins
from django.db import migrations, models
import django.db.models.deletion
import wagtail.wagtailcore.blocks
import wagtail.wagtailcore.fields
import wagtail.wagtailimages.blocks


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0029_unicode_slugfield_dj19'),
('digi', '0009_guidefrontpage'),
]

operations = [
migrations.CreateModel(
name='GuideContentPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('body', wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock())))),
('sidebar', wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock())))),
],
options={
'abstract': False,
},
bases=(digihel.mixins.RelativeURLMixin, 'wagtailcore.page'),
),
]
28 changes: 28 additions & 0 deletions digi/migrations/0011_fix_guidepages_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2016-12-21 13:35
from __future__ import unicode_literals

from django.db import migrations
import wagtail.wagtailcore.blocks
import wagtail.wagtailcore.fields
import wagtail.wagtailimages.blocks


class Migration(migrations.Migration):

dependencies = [
('digi', '0010_guidecontentpage'),
]

operations = [
migrations.AlterField(
model_name='guidecontentpage',
name='body',
field=wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock()), ('raw_content', wagtail.wagtailcore.blocks.RawHTMLBlock()))),
),
migrations.AlterField(
model_name='guidecontentpage',
name='sidebar',
field=wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock()), ('raw_content', wagtail.wagtailcore.blocks.RawHTMLBlock()))),
),
]
20 changes: 20 additions & 0 deletions digi/migrations/0012_themepage_twitter_hashtag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-01-16 08:55
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('digi', '0011_fix_guidepages_fields'),
]

operations = [
migrations.AddField(
model_name='themepage',
name='twitter_hashtag',
field=models.CharField(default='', max_length=255),
),
]
35 changes: 35 additions & 0 deletions digi/migrations/0013_add_KPI_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-01-24 14:59
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('digi', '0012_themepage_twitter_hashtag'),
]

operations = [
migrations.AddField(
model_name='indicator',
name='illustration_filename',
field=models.CharField(default='images/hki-tietoaineisto.svg', max_length=100),
),
migrations.AddField(
model_name='indicator',
name='slug',
field=models.CharField(default='', max_length=100),
),
migrations.AddField(
model_name='indicator',
name='source_description',
field=models.CharField(default='', max_length=200),
),
migrations.AddField(
model_name='indicator',
name='source_url',
field=models.CharField(default='http://dev.hel.fi/apis', max_length=100),
),
]
20 changes: 20 additions & 0 deletions digi/migrations/0014_projectpage_phase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-02-15 13:01
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('digi', '0013_add_KPI_fields'),
]

operations = [
migrations.AddField(
model_name='projectpage',
name='phase',
field=models.CharField(choices=[('', 'No phase'), ('DI', 'Selvitys'), ('AL', 'Alfa'), ('BE', 'Beta'), ('LI', 'Tuotanto'), ('RE', 'Poisto')], default='', max_length=2),
),
]
Loading