From 3311080fded49f3a194e77b9a1be967df30bbfb2 Mon Sep 17 00:00:00 2001 From: Oliver Marks Date: Thu, 5 Jan 2017 18:43:32 +0000 Subject: [PATCH] Added in feeds django app, can be manged in the admin backend --- README.org | 31 +++++++++++++- config/settings/common.py | 1 + config/settings/local.py | 1 + dev.yml | 9 +--- docker-compose.yml | 1 - mhackspace/README.org | 42 +++++++++++++++++++ mhackspace/feeds/admin.py | 12 ++++++ mhackspace/feeds/fixtures/defaults.json | 4 ++ mhackspace/feeds/helper.py | 18 ++++++++ mhackspace/feeds/migrations/0001_initial.py | 26 ++++++++++++ .../migrations/0002_auto_20170104_2033.py | 30 +++++++++++++ .../migrations/0003_auto_20170104_2035.py | 20 +++++++++ .../feeds/migrations/0004_feed_enabled.py | 20 +++++++++ mhackspace/feeds/migrations/__init__.py | 0 mhackspace/feeds/models.py | 20 +++++++++ mhackspace/feeds/templatetags/feed_views.py | 20 +++++++++ mhackspace/templates/base.html | 35 +++++++++++++++- mhackspace/templates/feeds/list.html | 22 ++++++++++ mhackspace/templates/pages/home.html | 9 +++- requirements/base.txt | 2 + 20 files changed, 312 insertions(+), 11 deletions(-) create mode 100644 mhackspace/README.org create mode 100644 mhackspace/feeds/admin.py create mode 100644 mhackspace/feeds/fixtures/defaults.json create mode 100644 mhackspace/feeds/helper.py create mode 100644 mhackspace/feeds/migrations/0001_initial.py create mode 100644 mhackspace/feeds/migrations/0002_auto_20170104_2033.py create mode 100644 mhackspace/feeds/migrations/0003_auto_20170104_2035.py create mode 100644 mhackspace/feeds/migrations/0004_feed_enabled.py create mode 100644 mhackspace/feeds/migrations/__init__.py create mode 100644 mhackspace/feeds/models.py create mode 100644 mhackspace/feeds/templatetags/feed_views.py create mode 100644 mhackspace/templates/feeds/list.html diff --git a/README.org b/README.org index 790d2d2..e1b3262 100644 --- a/README.org +++ b/README.org @@ -1,6 +1,20 @@ +* Maidstone hackspace website + +Repository for the maidstone hackspace website -First build your containers locally if needed, only needed when you first start or if requirements change. +** Requirements +Before getting started make sure you have compose and docker and git installed on your machine +The simplest way to setup this site is to use docker-compose so please install that from this site https://docs.docker.com/engine/installation/ and make sure the quick start guide works https://docs.docker.com/machine/get-started/ then you can use the commands below to test and make changes. + +** Setup +To get started checkout the project to your machine. + +#+BEGIN_SRC sh +git clone https://github.com/olymk2/maidstone-hackspace.git +#+END_SRC + +Once checked out build your containers locally if needed, only needed when you first start or if requirements change. #+BEGIN_SRC sh docker-compose -fdev.yml build @@ -11,3 +25,18 @@ Startup your new containers containing a database and django #+BEGIN_SRC sh docker-compose -fdev up #+END_SRC + +Test django is serving pages +http://127.0.0.1:8180 + + +Run migrations and setup admin user +to run django command just prefix them with =docker-compose -f dev.yml run django= +#+BEGIN_SRC sh +docker-compose -f dev.yml run django python manage.py makemigrations +docker-compose -f dev.yml run django python manage.py migrate +#+END_SRC + +#+BEGIN_SRC sh +docker-compose -f dev.yml run django python manage.py createsuperuser +#+END_SRC diff --git a/config/settings/common.py b/config/settings/common.py index 9a9b7f3..eb8bde3 100644 --- a/config/settings/common.py +++ b/config/settings/common.py @@ -46,6 +46,7 @@ THIRD_PARTY_APPS = ( LOCAL_APPS = ( # custom users app 'mhackspace.users.apps.UsersConfig', + 'mhackspace.feeds', # Your stuff: custom apps go here ) diff --git a/config/settings/local.py b/config/settings/local.py index bd7ee1f..dce1b6b 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -47,6 +47,7 @@ CACHES = { MIDDLEWARE += ('debug_toolbar.middleware.DebugToolbarMiddleware',) INSTALLED_APPS += ('debug_toolbar', ) +ALLOWED_HOSTS = ['*'] INTERNAL_IPS = ['127.0.0.1', '10.0.2.2', ] # tricks to have debug toolbar when developing with docker if os.environ.get('USE_DOCKER') == 'yes': diff --git a/dev.yml b/dev.yml index 43ab754..c7a5e5f 100644 --- a/dev.yml +++ b/dev.yml @@ -26,18 +26,13 @@ services: volumes: - .:/app ports: - - "8000:8000" + - "8180:8000" links: - postgres - - mailhog - - - - mailhog: image: mailhog/mailhog ports: - - "8025:8025" + - "8025:8125" diff --git a/docker-compose.yml b/docker-compose.yml index a7b7c1c..8f0abc6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,6 @@ services: build: ./compose/nginx depends_on: - django - - certbot ports: diff --git a/mhackspace/README.org b/mhackspace/README.org new file mode 100644 index 0000000..e1b3262 --- /dev/null +++ b/mhackspace/README.org @@ -0,0 +1,42 @@ +* Maidstone hackspace website + +Repository for the maidstone hackspace website + + +** Requirements +Before getting started make sure you have compose and docker and git installed on your machine +The simplest way to setup this site is to use docker-compose so please install that from this site https://docs.docker.com/engine/installation/ and make sure the quick start guide works https://docs.docker.com/machine/get-started/ then you can use the commands below to test and make changes. + +** Setup +To get started checkout the project to your machine. + +#+BEGIN_SRC sh +git clone https://github.com/olymk2/maidstone-hackspace.git +#+END_SRC + +Once checked out build your containers locally if needed, only needed when you first start or if requirements change. + +#+BEGIN_SRC sh +docker-compose -fdev.yml build +#+END_SRC + +Startup your new containers containing a database and django + +#+BEGIN_SRC sh +docker-compose -fdev up +#+END_SRC + +Test django is serving pages +http://127.0.0.1:8180 + + +Run migrations and setup admin user +to run django command just prefix them with =docker-compose -f dev.yml run django= +#+BEGIN_SRC sh +docker-compose -f dev.yml run django python manage.py makemigrations +docker-compose -f dev.yml run django python manage.py migrate +#+END_SRC + +#+BEGIN_SRC sh +docker-compose -f dev.yml run django python manage.py createsuperuser +#+END_SRC diff --git a/mhackspace/feeds/admin.py b/mhackspace/feeds/admin.py new file mode 100644 index 0000000..3167acd --- /dev/null +++ b/mhackspace/feeds/admin.py @@ -0,0 +1,12 @@ +from django.contrib import admin +from django.contrib.admin import AdminSite, TabularInline, ModelAdmin +from mhackspace.feeds.models import Feed + + +@admin.register(Feed) +class FeedAdmin(ModelAdmin): + list_display = ('url', 'author', 'tags', 'enabled') + +admin.site.site_title = 'Maidstone hackspace Admin Area' +admin.site.site_header = 'Maidstone hackspace Admin Area' +admin.site.index_title = 'Maidstone Admin Home' diff --git a/mhackspace/feeds/fixtures/defaults.json b/mhackspace/feeds/fixtures/defaults.json new file mode 100644 index 0000000..8d25010 --- /dev/null +++ b/mhackspace/feeds/fixtures/defaults.json @@ -0,0 +1,4 @@ +Postgres is up - continuing... +/usr/local/lib/python3.5/site-packages/environ/environ.py:608: UserWarning: /app/config/settings/.env doesn't exist - if you're not configuring your environment separately, create one. + "environment separately, create one." % env_file) +[{"model": "feeds.feed", "pk": 1, "fields": {"url": "http://waistcoatforensicator.blogspot.com/feeds/posts/default?alt=rss", "author": "Simon Ridley", "tags": "", "image": "", "enabled": true}}, {"model": "feeds.feed", "pk": 2, "fields": {"url": "http://www.matthewbeddow.co.uk/?feed=rss2", "author": "Mathew Beddow", "tags": "tech", "image": "", "enabled": true}}, {"model": "feeds.feed", "pk": 3, "fields": {"url": "http://blog.digitaloctave.co.uk/rss.xml", "author": "Oliver Marks", "tags": "", "image": "", "enabled": true}}, {"model": "feeds.feed", "pk": 4, "fields": {"url": "http://webboggles.com/feed/", "author": "Ilya Titov", "tags": "", "image": "", "enabled": true}}, {"model": "feeds.feed", "pk": 5, "fields": {"url": "http://thearduinoguy.org/?feed=rss2", "author": "Mike McRoberts", "tags": "", "image": "", "enabled": true}}, {"model": "feeds.feed", "pk": 6, "fields": {"url": "https://feeds.feedburner.com/projects-jl", "author": "James", "tags": "", "image": "", "enabled": false}}] \ No newline at end of file diff --git a/mhackspace/feeds/helper.py b/mhackspace/feeds/helper.py new file mode 100644 index 0000000..c30f0e3 --- /dev/null +++ b/mhackspace/feeds/helper.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from django import template +from mhackspace.feeds.models import Feed +from scaffold.readers.rss_reader import feed_reader + +register = template.Library() + +@register.inclusion_tag('feed_tiles.html') +def fetch_feeds(): + for feed + rss_feeds = [] + for feed in Feed.objects.all(): + rss_feeds.append({ + 'author':'Simon Ridley', + 'url': 'http://waistcoatforensicator.blogspot.com/feeds/posts/default?alt=rss' + }) + + return feed_reader(rss_feeds) diff --git a/mhackspace/feeds/migrations/0001_initial.py b/mhackspace/feeds/migrations/0001_initial.py new file mode 100644 index 0000000..53bcf3c --- /dev/null +++ b/mhackspace/feeds/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-01-04 14:04 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Feed', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('url', models.CharField(max_length=255)), + ('author', models.CharField(max_length=255)), + ('tags', models.CharField(max_length=255)), + ('image', models.ImageField(upload_to='')), + ], + ), + ] diff --git a/mhackspace/feeds/migrations/0002_auto_20170104_2033.py b/mhackspace/feeds/migrations/0002_auto_20170104_2033.py new file mode 100644 index 0000000..4f8bd15 --- /dev/null +++ b/mhackspace/feeds/migrations/0002_auto_20170104_2033.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-01-04 20:33 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('feeds', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='feed', + name='id', + field=models.IntegerField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name='feed', + name='image', + field=models.ImageField(blank=True, upload_to=''), + ), + migrations.AlterField( + model_name='feed', + name='tags', + field=models.CharField(blank=True, max_length=255), + ), + ] diff --git a/mhackspace/feeds/migrations/0003_auto_20170104_2035.py b/mhackspace/feeds/migrations/0003_auto_20170104_2035.py new file mode 100644 index 0000000..55a38dc --- /dev/null +++ b/mhackspace/feeds/migrations/0003_auto_20170104_2035.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-01-04 20:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('feeds', '0002_auto_20170104_2033'), + ] + + operations = [ + migrations.AlterField( + model_name='feed', + name='id', + field=models.AutoField(primary_key=True, serialize=False), + ), + ] diff --git a/mhackspace/feeds/migrations/0004_feed_enabled.py b/mhackspace/feeds/migrations/0004_feed_enabled.py new file mode 100644 index 0000000..9579887 --- /dev/null +++ b/mhackspace/feeds/migrations/0004_feed_enabled.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-01-04 21:39 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('feeds', '0003_auto_20170104_2035'), + ] + + operations = [ + migrations.AddField( + model_name='feed', + name='enabled', + field=models.BooleanField(default=True), + ), + ] diff --git a/mhackspace/feeds/migrations/__init__.py b/mhackspace/feeds/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mhackspace/feeds/models.py b/mhackspace/feeds/models.py new file mode 100644 index 0000000..6a9275b --- /dev/null +++ b/mhackspace/feeds/models.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals, absolute_import + +from django.db import models +from django.utils.encoding import python_2_unicode_compatible +from django.utils.translation import ugettext_lazy as _ + + +@python_2_unicode_compatible +class Feed(models.Model): + id = models.AutoField(primary_key=True) + url = models.CharField(max_length=255) + author = models.CharField(max_length=255) + tags = models.CharField(max_length=255, blank=True) + image = models.ImageField(blank=True) + enabled = models.BooleanField(default=True) + + def __str__(self): + return self.url + diff --git a/mhackspace/feeds/templatetags/feed_views.py b/mhackspace/feeds/templatetags/feed_views.py new file mode 100644 index 0000000..463e6ea --- /dev/null +++ b/mhackspace/feeds/templatetags/feed_views.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from django import template +from mhackspace.feeds.models import Feed +from scaffold.readers.rss_reader import feed_reader + +register = template.Library() + +@register.inclusion_tag('feeds/list.html') +def show_feeds(): + rss_feeds = [] + for feed in Feed.objects.all(): + if feed.enabled is False: + continue + rss_feeds.append({ + 'author': feed.author, + 'url': feed.url + }) + + result = feed_reader(rss_feeds) + return {'feeds': [item for item in result]} diff --git a/mhackspace/templates/base.html b/mhackspace/templates/base.html index 83eee4a..54dc0a5 100644 --- a/mhackspace/templates/base.html +++ b/mhackspace/templates/base.html @@ -42,6 +42,21 @@ + + + + + @@ -82,7 +97,25 @@ {% endblock content %} - + {% block modal %}{% endblock modal %}