Skip to content

Commit

Permalink
Merge pull request #291 from Parbhat/master
Browse files Browse the repository at this point in the history
Address issue #265
  • Loading branch information
chrisdev authored Jun 21, 2016
2 parents 282db8d + 2126447 commit 9f3de5e
Show file tree
Hide file tree
Showing 8 changed files with 1,557 additions and 1,019 deletions.
2,342 changes: 1,358 additions & 984 deletions {{cookiecutter.repo_name}}/db.sql

Large diffs are not rendered by default.

46 changes: 26 additions & 20 deletions {{cookiecutter.repo_name}}/feeds/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.utils.feedgenerator import Rss201rev2Feed
from wagtail.wagtailimages.models import Filter
from wagtail.wagtailcore.models import Site
from django.conf import settings
from datetime import datetime, time
from django.utils.html import strip_tags
from django.apps import apps
Expand All @@ -15,10 +14,17 @@
from urllib.parse import urljoin
from django.utils import feedgenerator

feed_app_label = getattr(settings, "FEED_APP_LABEL")
feed_model_name = getattr(settings, "FEED_MODEL_NAME")
feed_model = apps.get_model(app_label=feed_app_label,
model_name=feed_model_name)
from .models import FeedsAppSettings

feed_app_settings = FeedsAppSettings.for_site(
site=Site.objects.get(is_default_site=True))
feed_app_label = feed_app_settings.feed_app_label
feed_model_name = feed_app_settings.feed_model_name
try:
feed_model = apps.get_model(app_label=feed_app_label,
model_name=feed_model_name)
except:
feed_model = None


class CustomFeedGenerator(Rss201rev2Feed):
Expand Down Expand Up @@ -53,15 +59,15 @@ class BasicFeed(Feed):
feed_type = feedgenerator.Rss201rev2Feed

# The RSS information that gets shown at the top of the feed.
title = getattr(settings, "FEED_TITLE", "")
link = getattr(settings, "FEED_LINK", "")
description = getattr(settings, "FEED_DESCRIPTION", "Blog Feed")
title = feed_app_settings.feed_title
link = feed_app_settings.feed_link
description = feed_app_settings.feed_description

author_email = getattr(settings, "FEED_AUTHOR_EMAIL", "")
author_link = getattr(settings, "FEED_AUTHOR_LINK", "")
author_email = feed_app_settings.feed_author_email
author_link = feed_app_settings.feed_author_link

item_description_field = getattr(settings, "FEED_ITEM_DESCRIPTION_FIELD")
item_content_field = getattr(settings, "FEED_ITEM_CONTENT_FIELD")
item_description_field = feed_app_settings.feed_item_description_field
item_content_field = feed_app_settings.feed_item_content_field

def items(self):
return feed_model.objects.order_by('-date').live()
Expand All @@ -82,15 +88,15 @@ class ExtendedFeed(Feed):
feed_type = CustomFeedGenerator

# The RSS information that gets shown at the top of the feed.
title = getattr(settings, "FEED_TITLE", "")
link = getattr(settings, "FEED_LINK", "")
description = getattr(settings, "FEED_DESCRIPTION", "Blog Feed")
title = feed_app_settings.feed_title
link = feed_app_settings.feed_link
description = feed_app_settings.feed_description

author_email = getattr(settings, "FEED_AUTHOR_EMAIL", "")
author_link = getattr(settings, "FEED_AUTHOR_LINK", "")
author_email = feed_app_settings.feed_author_email
author_link = feed_app_settings.feed_author_link

item_description_field = getattr(settings, "FEED_ITEM_DESCRIPTION_FIELD")
item_content_field = getattr(settings, "FEED_ITEM_CONTENT_FIELD")
item_description_field = feed_app_settings.feed_item_description_field
item_content_field = feed_app_settings.feed_item_content_field

def get_site_url(self):
site = Site.objects.get(is_default_site=True)
Expand All @@ -113,7 +119,7 @@ def item_link(self, item):
return item.full_url

def item_author_name(self, item):
return u'Jonh Blog'
pass

def item_extra_kwargs(self, item):
"""
Expand Down
30 changes: 30 additions & 0 deletions {{cookiecutter.repo_name}}/feeds/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-18 12:31
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

initial = True

dependencies = [
('wagtailcore', '0028_merge'),
]

operations = [
migrations.CreateModel(
name='FeedsAppSettings',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('feed_app_label', models.CharField(help_text=b'blog App whose Feed is to be generated', max_length=255)),
('feed_model_name', models.CharField(help_text=b'Model to be used for feed generation', max_length=255)),
('site', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.Site')),
],
options={
'abstract': False,
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-20 11:55
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('feeds', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='feedsappsettings',
name='feed_author_email',
field=models.EmailField(blank=True, help_text=b'Email of author', max_length=255),
),
migrations.AddField(
model_name='feedsappsettings',
name='feed_author_link',
field=models.URLField(blank=True, help_text=b'Link of author', max_length=255),
),
migrations.AddField(
model_name='feedsappsettings',
name='feed_description',
field=models.CharField(blank=True, help_text=b'Description of field', max_length=255),
),
migrations.AddField(
model_name='feedsappsettings',
name='feed_item_content_field',
field=models.CharField(blank=True, help_text=b'Content Field for feed item', max_length=255),
),
migrations.AddField(
model_name='feedsappsettings',
name='feed_item_description_field',
field=models.CharField(blank=True, help_text=b'Description field for feed item', max_length=255),
),
migrations.AddField(
model_name='feedsappsettings',
name='feed_link',
field=models.URLField(blank=True, help_text=b'link for Feed', max_length=255),
),
migrations.AddField(
model_name='feedsappsettings',
name='feed_title',
field=models.CharField(blank=True, help_text=b'Title of Feed', max_length=255),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-20 13:01
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('feeds', '0002_auto_20160620_1155'),
]

operations = [
migrations.AlterField(
model_name='feedsappsettings',
name='feed_app_label',
field=models.CharField(blank=True, help_text=b'blog App whose Feed is to be generated', max_length=255, null=True),
),
migrations.AlterField(
model_name='feedsappsettings',
name='feed_author_email',
field=models.EmailField(blank=True, help_text=b'Email of author', max_length=255, null=True),
),
migrations.AlterField(
model_name='feedsappsettings',
name='feed_author_link',
field=models.URLField(blank=True, help_text=b'Link of author', max_length=255, null=True),
),
migrations.AlterField(
model_name='feedsappsettings',
name='feed_description',
field=models.CharField(blank=True, help_text=b'Description of field', max_length=255, null=True),
),
migrations.AlterField(
model_name='feedsappsettings',
name='feed_item_content_field',
field=models.CharField(blank=True, help_text=b'Content Field for feed item', max_length=255, null=True),
),
migrations.AlterField(
model_name='feedsappsettings',
name='feed_item_description_field',
field=models.CharField(blank=True, help_text=b'Description field for feed item', max_length=255, null=True),
),
migrations.AlterField(
model_name='feedsappsettings',
name='feed_link',
field=models.URLField(blank=True, help_text=b'link for Feed', max_length=255, null=True),
),
migrations.AlterField(
model_name='feedsappsettings',
name='feed_model_name',
field=models.CharField(blank=True, help_text=b'Model to be used for feed generation', max_length=255, null=True),
),
migrations.AlterField(
model_name='feedsappsettings',
name='feed_title',
field=models.CharField(blank=True, help_text=b'Title of Feed', max_length=255, null=True),
),
]
30 changes: 30 additions & 0 deletions {{cookiecutter.repo_name}}/feeds/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
from django.db import models

from wagtail.contrib.settings.models import BaseSetting, register_setting

# Create your models here.


@register_setting
class FeedsAppSettings(BaseSetting):
feed_app_label = models.CharField(
max_length=255, help_text='blog App whose Feed is to be generated',
null=True, blank=True)
feed_model_name = models.CharField(
max_length=255, help_text='Model to be used for feed generation',
null=True, blank=True)
feed_title = models.CharField(
max_length=255, help_text='Title of Feed', null=True, blank=True)
feed_link = models.URLField(
max_length=255, help_text='link for Feed', null=True, blank=True)
feed_description = models.CharField(
max_length=255, help_text='Description of field', null=True,
blank=True)
feed_author_email = models.EmailField(
max_length=255, help_text='Email of author', null=True, blank=True)
feed_author_link = models.URLField(
max_length=255, help_text='Link of author', null=True, blank=True)

feed_item_description_field = models.CharField(
max_length=255, help_text='Description field for feed item',
null=True, blank=True)
feed_item_content_field = models.CharField(
max_length=255, help_text='Content Field for feed item',
null=True, blank=True)
2 changes: 1 addition & 1 deletion {{cookiecutter.repo_name}}/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ celery==3.1.23
django-libsass==0.7
libsass==0.11.1
ansible==2.1.0.0
wagalytics==0.5
wagalytics==0.6
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_env_variable(var_name):

'wagalytics',
'wagtailfontawesome',

'utils',
'pages',
'blog',
Expand All @@ -86,6 +86,7 @@ def get_env_variable(var_name):
'photo_gallery',
'products',
'documents_gallery',
'feeds',
)

MIDDLEWARE_CLASSES = (
Expand Down Expand Up @@ -183,19 +184,6 @@ def get_env_variable(var_name):

COMPRESS_OFFLINE = True

# Feeds app for Wagtail CMS
FEED_APP_LABEL = 'blog'
FEED_MODEL_NAME = 'BlogPage'
FEED_ITEM_DESCRIPTION_FIELD = 'intro'
FEED_ITEM_CONTENT_FIELD = 'body'

FEED_TITLE = 'From the Desk of John Blog'
FEED_LINK = '/news/'
FEED_DESCRIPTION = "News and views from around the Web"
FEED_AUTHOR_EMAIL = 'john@johnblog.com'
FEED_AUTHOR_LINK = 'https://johnblog.com'


# Settings for wagalytics
GA_KEY_FILEPATH = ''
GA_VIEW_ID = ''
Expand Down

0 comments on commit 9f3de5e

Please sign in to comment.