Browse Source

Remove flake8, run black on everything

Debian 9 can't support black out of the box due to a Python 3.6
requirement.  I'm still opting to use it on the codebase, and at some
point down the road it can be integrated into CI and etc.

Since flake8 conflicts with black, it is being removed.
pull/326/head
parent
commit
0cfefb7032
No known key found for this signature in database
71 changed files with 2977 additions and 1829 deletions
  1. 0
    1
      Makefile
  2. 34
    32
      bin/seed_db.py
  3. 6
    6
      momw/chroniko/__init__.py
  4. 1
    1
      momw/chroniko/apps.py
  5. 376
    250
      momw/chroniko/data_seeds/blog.py
  6. 11
    7
      momw/chroniko/feeds.py
  7. 11
    9
      momw/chroniko/forms.py
  8. 129
    46
      momw/chroniko/migrations/0001_initial.py
  9. 40
    31
      momw/chroniko/models.py
  10. 90
    64
      momw/chroniko/tests.py
  11. 54
    35
      momw/chroniko/urls.py
  12. 143
    93
      momw/chroniko/views.py
  13. 2
    2
      momw/media/__init__.py
  14. 1
    1
      momw/media/apps.py
  15. 37
    13
      momw/media/data_seeds/media.py
  16. 2
    2
      momw/media/feeds.py
  17. 7
    7
      momw/media/forms.py
  18. 45
    15
      momw/media/migrations/0001_initial.py
  19. 3
    6
      momw/media/migrations/0002_auto_20171110_1604.py
  20. 10
    13
      momw/media/migrations/0003_auto_20180107_1358.py
  21. 8
    7
      momw/media/migrations/0004_auto_20190504_2044.py
  22. 34
    21
      momw/media/models.py
  23. 29
    18
      momw/media/tests.py
  24. 25
    14
      momw/media/urls.py
  25. 52
    32
      momw/media/views.py
  26. 33
    21
      momw/momw/cfg.py
  27. 1
    2
      momw/momw/context_processors.py
  28. 540
    255
      momw/momw/data_seeds/media.py
  29. 173
    118
      momw/momw/data_seeds/test_mod_data.py
  30. 1
    2
      momw/momw/errors.py
  31. 1
    1
      momw/momw/feeds.py
  32. 38
    23
      momw/momw/forms.py
  33. 8
    4
      momw/momw/managers.py
  34. 167
    54
      momw/momw/migrations/0001_initial.py
  35. 20
    14
      momw/momw/migrations/0002_auto_20180413_1444.py
  36. 5
    7
      momw/momw/migrations/0003_tag_description.py
  37. 10
    8
      momw/momw/migrations/0004_auto_20180714_1729.py
  38. 7
    7
      momw/momw/migrations/0005_auto_20180715_1516.py
  39. 2
    9
      momw/momw/migrations/0006_remove_mod_plugin_order.py
  40. 8
    7
      momw/momw/migrations/0007_mod_has_bsa.py
  41. 13
    7
      momw/momw/migrations/0008_mod_compat.py
  42. 30
    15
      momw/momw/migrations/0009_modissue.py
  43. 4
    6
      momw/momw/migrations/0010_mod_needs_cleaning.py
  44. 3
    7
      momw/momw/migrations/0011_mod_extra_cfg.py
  45. 3
    7
      momw/momw/migrations/0012_mod_extra_cfg_raw.py
  46. 7
    7
      momw/momw/migrations/0013_mod_depends_on.py
  47. 7
    7
      momw/momw/migrations/0014_mod_folder_paths.py
  48. 80
    51
      momw/momw/models.py
  49. 85
    73
      momw/momw/settings.py
  50. 36
    36
      momw/momw/sitemaps.py
  51. 87
    28
      momw/momw/tests.py
  52. 132
    76
      momw/momw/urls.py
  53. 170
    129
      momw/momw/views.py
  54. 1
    1
      momw/search/__init__.py
  55. 1
    1
      momw/search/apps.py
  56. 1
    3
      momw/search/urls.py
  57. 58
    46
      momw/search/views.py
  58. 1
    1
      momw/utilz/__init__.py
  59. 1
    1
      momw/utilz/apps.py
  60. 13
    10
      momw/utilz/cache.py
  61. 11
    11
      momw/utilz/context_processors.py
  62. 12
    5
      momw/utilz/forms.py
  63. 1
    1
      momw/utilz/git.py
  64. 2
    2
      momw/utilz/management/commands/printurls.py
  65. 2
    2
      momw/utilz/management/commands/warmcache.py
  66. 2
    5
      momw/utilz/middleware.py
  67. 2
    4
      momw/utilz/queries.py
  68. 3
    3
      momw/utilz/templatetags/extra_tags.py
  69. 1
    1
      momw/utilz/templatetags/filterz.py
  70. 27
    10
      momw/utilz/tests.py
  71. 17
    15
      momw/utilz/views.py

+ 0
- 1
Makefile View File

@@ -61,7 +61,6 @@ start-xvfb-ci:

test:
ifndef SKIPTESTS
find $(proj_dir) -type f -name "*.py" | xargs flake8
sudo -u momwdb dropdb test_momwdb || echo test db is gone
$(proj_dir)/momw/manage.py test chroniko.tests momw.tests utilz.tests
endif

+ 34
- 32
bin/seed_db.py View File

@@ -2,16 +2,21 @@
import sys
import os
import pendulum

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.append(BASE_DIR + '/momw')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'momw.settings')
sys.path.append(BASE_DIR + "/momw")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "momw.settings")
import django

django.setup()
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
from momw.data_seeds.blog import blog_category_factory, blog_tag_factory, \
blog_entry_factory
from momw.data_seeds.blog import (
blog_category_factory,
blog_tag_factory,
blog_entry_factory,
)
from momw.data_seeds.media import media_factory
from momw.data_seeds.mod_data import mod_cats, mods, mod_tags

@@ -22,20 +27,16 @@ User = get_user_model()

def site_factory():
s1 = Site.objects.get(pk=1)
s1.domain = '0.0.0.0:8666'
s1.name = 'Modding-OpenMW.com'
s1.domain = "0.0.0.0:8666"
s1.name = "Modding-OpenMW.com"
s1.save()

# For testing from my phone.
site2 = {
"domain": "192.168.1.100:8666",
"name": "Modding-OpenMW.com"}
site2 = {"domain": "192.168.1.100:8666", "name": "Modding-OpenMW.com"}
s2 = Site(**site2)
s2.save()

site3 = {
"domain": "localhost:8666",
"name": "Modding-OpenMW.com"}
site3 = {"domain": "localhost:8666", "name": "Modding-OpenMW.com"}
s3 = Site(**site3)
s3.save()

@@ -43,11 +44,12 @@ def site_factory():
def user_factory():
"""Creates user accounts!"""
admin = {
'username': 'MaiqTheAdmin',
'password': 'pbkdf2_sha256$30000$sq1bF20gppnd$OLo3HeVIpZXD9obg4uFU3SjbHQE4kCAV0Pmgo6cqNrw=',
'first_name': "M'aiq",
'last_name': 'The Admin',
'email': 'admin@modding-openmw.com'}
"username": "MaiqTheAdmin",
"password": "pbkdf2_sha256$30000$sq1bF20gppnd$OLo3HeVIpZXD9obg4uFU3SjbHQE4kCAV0Pmgo6cqNrw=",
"first_name": "M'aiq",
"last_name": "The Admin",
"email": "admin@modding-openmw.com",
}
a = User(**admin)
a.is_staff = True
a.is_superuser = True
@@ -56,26 +58,26 @@ def user_factory():

def main():
def _run(arg, func, earg=None):
if '--{}'.format(arg) in sys.argv or '--full' in sys.argv:
print('Running {}() ...'.format(func.__name__), end=' ')
if "--{}".format(arg) in sys.argv or "--full" in sys.argv:
print("Running {}() ...".format(func.__name__), end=" ")
if earg:
func(earg)
else:
func()
print('Done!')
print("Done!")

print('... Starting {} db seed ...'.format(settings.PROJECT_NAME.upper()))
_run('site', site_factory)
_run('user', user_factory)
_run('blog-cat', blog_category_factory)
_run('blog-tag', blog_tag_factory)
_run('blog-entry', blog_entry_factory)
_run('media', media_factory)
_run('mod-cat', mod_cats)
_run('mod-tag', mod_tags)
_run('mods', mods, earg=User.objects.get(pk=1))
print('... Finished {} db seed!'.format(settings.PROJECT_NAME.upper()))
print("... Starting {} db seed ...".format(settings.PROJECT_NAME.upper()))
_run("site", site_factory)
_run("user", user_factory)
_run("blog-cat", blog_category_factory)
_run("blog-tag", blog_tag_factory)
_run("blog-entry", blog_entry_factory)
_run("media", media_factory)
_run("mod-cat", mod_cats)
_run("mod-tag", mod_tags)
_run("mods", mods, earg=User.objects.get(pk=1))
print("... Finished {} db seed!".format(settings.PROJECT_NAME.upper()))


if __name__ == '__main__':
if __name__ == "__main__":
main()

+ 6
- 6
momw/chroniko/__init__.py View File

@@ -1,9 +1,9 @@
# Some constants for the blog
# TODO: de-hard code the app name
ADD_CATEGORY_PERM = 'chroniko.add_blogcategory'
ADD_ENTRY_PERM = 'chroniko.add_blogentry'
CHANGE_CATEGORY_PERM = 'chroniko.change_blogcategory'
CHANGE_ENTRY_PERM = 'chroniko.change_blogentry'
ENTRY_DATE_FIELD = 'date_added'
ADD_CATEGORY_PERM = "chroniko.add_blogcategory"
ADD_ENTRY_PERM = "chroniko.add_blogentry"
CHANGE_CATEGORY_PERM = "chroniko.change_blogcategory"
CHANGE_ENTRY_PERM = "chroniko.change_blogentry"
ENTRY_DATE_FIELD = "date_added"

default_app_config = 'chroniko.apps.ChronikoConfig'
default_app_config = "chroniko.apps.ChronikoConfig"

+ 1
- 1
momw/chroniko/apps.py View File

@@ -2,5 +2,5 @@ from django.apps import AppConfig


class ChronikoConfig(AppConfig):
name = 'chroniko'
name = "chroniko"
verbose_name = "Chroniko Blogging Engine"

+ 376
- 250
momw/chroniko/data_seeds/blog.py View File

@@ -17,8 +17,7 @@ def generate_category(title, slug, desc):
return c


def generate_entry(body, date_added, slug, status,
title, author, category, excerpt=''):
def generate_entry(body, date_added, slug, status, title, author, category, excerpt=""):
"""
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2010-12-18 14:34:34 -0500', datetime_format),
@@ -28,71 +27,118 @@ def generate_entry(body, date_added, slug, status,
'author': u,
'category': cat1
"""
e = BlogEntry.objects.create(body=body, date_added=date_added, slug=slug,
status=status, title=title, author=author,
category=category, excerpt=excerpt)
e = BlogEntry.objects.create(
body=body,
date_added=date_added,
slug=slug,
status=status,
title=title,
author=author,
category=category,
excerpt=excerpt,
)
e.save()
return e


def blog_category_factory():
BlogCategory(title='Category One', slug='category-one', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Two', slug='category-two', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Three', slug='category-three', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Four', slug='category-four', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Five', slug='category-five', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Six', slug='category-six', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Seven', slug='category-seven', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Eight', slug='category-eight', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Nine', slug='category-nine', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(title='Category Ten', slug='category-ten', description=rikeripsum.generate_paragraph(10)).save()
BlogCategory(
title="Category One",
slug="category-one",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Two",
slug="category-two",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Three",
slug="category-three",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Four",
slug="category-four",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Five",
slug="category-five",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Six",
slug="category-six",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Seven",
slug="category-seven",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Eight",
slug="category-eight",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Nine",
slug="category-nine",
description=rikeripsum.generate_paragraph(10),
).save()
BlogCategory(
title="Category Ten",
slug="category-ten",
description=rikeripsum.generate_paragraph(10),
).save()


def blog_tag_factory():
BlogTag(name='Tag1').save()
BlogTag(name='Tag2').save()
BlogTag(name='Tag3').save()
BlogTag(name='Tag4').save()
BlogTag(name='Tag5').save()
BlogTag(name='Tag6').save()
BlogTag(name='Tag7').save()
BlogTag(name='Tag8').save()
BlogTag(name='Tag9').save()
BlogTag(name='Tag10').save()
BlogTag(name='Tag11').save()
BlogTag(name='Tag12').save()
BlogTag(name='Tag13').save()
BlogTag(name='Tag14').save()
BlogTag(name='Tag15').save()
BlogTag(name='Tag16').save()
BlogTag(name='Tag17').save()
BlogTag(name='Tag18').save()
BlogTag(name='Tag19').save()
BlogTag(name='Tag20').save()
BlogTag(name='Tag21').save()
BlogTag(name='Tag22').save()
BlogTag(name='Tag23').save()
BlogTag(name='Tag24').save()
BlogTag(name='Tag25').save()
BlogTag(name='Tag26').save()
BlogTag(name='Tag27').save()
BlogTag(name='Tag28').save()
BlogTag(name='Tag29').save()
BlogTag(name='Tag30').save()
BlogTag(name='Tag31').save()
BlogTag(name='Tag32').save()
BlogTag(name='Tag33').save()
BlogTag(name='Tag34').save()
BlogTag(name='Tag35').save()
BlogTag(name='Tag36').save()
BlogTag(name='Tag37').save()
BlogTag(name='Tag38').save()
BlogTag(name='Tag39').save()
BlogTag(name='Tag40').save()
BlogTag(name="Tag1").save()
BlogTag(name="Tag2").save()
BlogTag(name="Tag3").save()
BlogTag(name="Tag4").save()
BlogTag(name="Tag5").save()
BlogTag(name="Tag6").save()
BlogTag(name="Tag7").save()
BlogTag(name="Tag8").save()
BlogTag(name="Tag9").save()
BlogTag(name="Tag10").save()
BlogTag(name="Tag11").save()
BlogTag(name="Tag12").save()
BlogTag(name="Tag13").save()
BlogTag(name="Tag14").save()
BlogTag(name="Tag15").save()
BlogTag(name="Tag16").save()
BlogTag(name="Tag17").save()
BlogTag(name="Tag18").save()
BlogTag(name="Tag19").save()
BlogTag(name="Tag20").save()
BlogTag(name="Tag21").save()
BlogTag(name="Tag22").save()
BlogTag(name="Tag23").save()
BlogTag(name="Tag24").save()
BlogTag(name="Tag25").save()
BlogTag(name="Tag26").save()
BlogTag(name="Tag27").save()
BlogTag(name="Tag28").save()
BlogTag(name="Tag29").save()
BlogTag(name="Tag30").save()
BlogTag(name="Tag31").save()
BlogTag(name="Tag32").save()
BlogTag(name="Tag33").save()
BlogTag(name="Tag34").save()
BlogTag(name="Tag35").save()
BlogTag(name="Tag36").save()
BlogTag(name="Tag37").save()
BlogTag(name="Tag38").save()
BlogTag(name="Tag39").save()
BlogTag(name="Tag40").save()


def blog_entry_factory():
datetime_format = '%Y-%m-%d %H:%M:%S %z'
datetime_format = "%Y-%m-%d %H:%M:%S %z"
entry_content_type = ContentType.objects.get_for_model(BlogEntry)
u = User.objects.get(pk=1)
cat1 = BlogCategory.objects.get(pk=1)
@@ -146,198 +192,198 @@ def blog_entry_factory():
tag39 = BlogTag.objects.get(pk=39)
tag40 = BlogTag.objects.get(pk=40)
e1 = {
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2010-12-18 14:34:34 -0500', datetime_format),
'slug': 'blog-entry-one',
'status': 1,
'title': 'Blog Entry One LIVE',
'author': u,
'category': cat1
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2010-12-18 14:34:34 -0500", datetime_format),
"slug": "blog-entry-one",
"status": 1,
"title": "Blog Entry One LIVE",
"author": u,
"category": cat1,
}
e2 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2011-01-19 10:34:34 -0500', datetime_format),
'slug': 'blog-entry-two',
'status': 2,
'title': 'Blog Entry Two DRAFT',
'author': u,
'category': cat2
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2011-01-19 10:34:34 -0500", datetime_format),
"slug": "blog-entry-two",
"status": 2,
"title": "Blog Entry Two DRAFT",
"author": u,
"category": cat2,
}
e3 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2011-02-22 16:34:34 -0500', datetime_format),
'slug': 'blog-entry-three',
'status': 3,
'title': 'Blog Entry Three HIDDEN',
'author': u,
'category': cat3
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2011-02-22 16:34:34 -0500", datetime_format),
"slug": "blog-entry-three",
"status": 3,
"title": "Blog Entry Three HIDDEN",
"author": u,
"category": cat3,
}
e4 = {
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2011-02-22 16:34:34 -0500', datetime_format),
'slug': 'blog-entry-four',
'status': 1,
'title': 'Blog Entry Four LIVE',
'author': u,
'category': cat4
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2011-02-22 16:34:34 -0500", datetime_format),
"slug": "blog-entry-four",
"status": 1,
"title": "Blog Entry Four LIVE",
"author": u,
"category": cat4,
}
e5 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2011-03-04 03:04:34 -0500', datetime_format),
'slug': 'blog-entry-five',
'status': 2,
'title': 'Blog Entry Five DRAFT',
'author': u,
'category': cat5
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2011-03-04 03:04:34 -0500", datetime_format),
"slug": "blog-entry-five",
"status": 2,
"title": "Blog Entry Five DRAFT",
"author": u,
"category": cat5,
}
e6 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2011-04-20 04:20:34 -0500', datetime_format),
'slug': 'blog-entry-six',
'status': 3,
'title': 'Blog Entry Six HIDDEN',
'author': u,
'category': cat6
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2011-04-20 04:20:34 -0500", datetime_format),
"slug": "blog-entry-six",
"status": 3,
"title": "Blog Entry Six HIDDEN",
"author": u,
"category": cat6,
}
e7 = {
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2012-01-01 15:20:34 -0500', datetime_format),
'slug': 'blog-entry-seven',
'status': 1,
'title': 'Blog Entry Seven LIVE',
'author': u,
'category': cat7
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2012-01-01 15:20:34 -0500", datetime_format),
"slug": "blog-entry-seven",
"status": 1,
"title": "Blog Entry Seven LIVE",
"author": u,
"category": cat7,
}
e8 = {
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2012-02-11 15:34:34 -0500', datetime_format),
'slug': 'blog-entry-eight',
'status': 1,
'title': 'Blog Entry Eight LIVE',
'author': u,
'category': cat8
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2012-02-11 15:34:34 -0500", datetime_format),
"slug": "blog-entry-eight",
"status": 1,
"title": "Blog Entry Eight LIVE",
"author": u,
"category": cat8,
}
e9 = {
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2012-02-11 15:34:34 -0500', datetime_format),
'slug': 'blog-entry-nine',
'status': 1,
'title': 'Blog Entry Nine LIVE',
'author': u,
'category': cat9
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2012-02-11 15:34:34 -0500", datetime_format),
"slug": "blog-entry-nine",
"status": 1,
"title": "Blog Entry Nine LIVE",
"author": u,
"category": cat9,
}
e10 = {
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2012-03-04 15:34:34 -0500', datetime_format),
'slug': 'blog-entry-ten',
'status': 1,
'title': 'Blog Entry Ten LIVE',
'author': u,
'category': cat10
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2012-03-04 15:34:34 -0500", datetime_format),
"slug": "blog-entry-ten",
"status": 1,
"title": "Blog Entry Ten LIVE",
"author": u,
"category": cat10,
}
e11 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2012-04-20 16:20:34 -0500', datetime_format),
'slug': 'blog-entry-eleven',
'status': 1,
'title': 'Blog Entry Eleven LIVE',
'author': u,
'category': cat1
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2012-04-20 16:20:34 -0500", datetime_format),
"slug": "blog-entry-eleven",
"status": 1,
"title": "Blog Entry Eleven LIVE",
"author": u,
"category": cat1,
}
e12 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2012-05-06 15:34:34 -0500', datetime_format),
'slug': 'blog-entry-twelve',
'status': 1,
'title': 'Blog Entry Twelve LIVE',
'author': u,
'category': cat2
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2012-05-06 15:34:34 -0500", datetime_format),
"slug": "blog-entry-twelve",
"status": 1,
"title": "Blog Entry Twelve LIVE",
"author": u,
"category": cat2,
}
e13 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2012-05-06 15:34:34 -0500', datetime_format),
'slug': 'blog-entry-thirteen',
'status': 1,
'title': 'Blog Entry Thirteen LIVE',
'author': u,
'category': cat3
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2012-05-06 15:34:34 -0500", datetime_format),
"slug": "blog-entry-thirteen",
"status": 1,
"title": "Blog Entry Thirteen LIVE",
"author": u,
"category": cat3,
}
e14 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2012-06-30 15:34:34 -0500', datetime_format),
'slug': 'blog-entry-fourteen',
'status': 1,
'title': 'Blog Entry Fourteen LIVE',
'author': u,
'category': cat4
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2012-06-30 15:34:34 -0500", datetime_format),
"slug": "blog-entry-fourteen",
"status": 1,
"title": "Blog Entry Fourteen LIVE",
"author": u,
"category": cat4,
}
e15 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2013-03-04 20:34:34 -0500', datetime_format),
'slug': 'blog-entry-fifteen',
'status': 1,
'title': 'Blog Entry Fifteen LIVE',
'author': u,
'category': cat5
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2013-03-04 20:34:34 -0500", datetime_format),
"slug": "blog-entry-fifteen",
"status": 1,
"title": "Blog Entry Fifteen LIVE",
"author": u,
"category": cat5,
}
e16 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2013-07-13 20:34:34 -0500', datetime_format),
'slug': 'blog-entry-sixteen',
'status': 1,
'title': 'Blog Entry Sixteen LIVE',
'author': u,
'category': cat6
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2013-07-13 20:34:34 -0500", datetime_format),
"slug": "blog-entry-sixteen",
"status": 1,
"title": "Blog Entry Sixteen LIVE",
"author": u,
"category": cat6,
}
e17 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2013-07-14 20:34:34 -0500', datetime_format),
'slug': 'blog-entry-seventeen',
'status': 1,
'title': 'Blog Entry Seventeen LIVE',
'author': u,
'category': cat7
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2013-07-14 20:34:34 -0500", datetime_format),
"slug": "blog-entry-seventeen",
"status": 1,
"title": "Blog Entry Seventeen LIVE",
"author": u,
"category": cat7,
}
e18 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2014-03-04 20:34:34 -0500', datetime_format),
'slug': 'blog-entry-eighteen',
'status': 1,
'title': 'Blog Entry Eighteen LIVE',
'author': u,
'category': cat8
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2014-03-04 20:34:34 -0500", datetime_format),
"slug": "blog-entry-eighteen",
"status": 1,
"title": "Blog Entry Eighteen LIVE",
"author": u,
"category": cat8,
}
e19 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2014-04-20 20:34:34 -0500', datetime_format),
'slug': 'blog-entry-nineteen',
'status': 1,
'title': 'Blog Entry Nineteen LIVE',
'author': u,
'category': cat9
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2014-04-20 20:34:34 -0500", datetime_format),
"slug": "blog-entry-nineteen",
"status": 1,
"title": "Blog Entry Nineteen LIVE",
"author": u,
"category": cat9,
}
e20 = {
'excerpt': rikeripsum.generate_paragraph(5),
'body': rikeripsum.generate_paragraph(100),
'date_added': datetime.strptime('2014-10-10 20:34:34 -0500', datetime_format),
'slug': 'blog-entry-twenty',
'status': 1,
'title': 'Blog Entry Twenty LIVE',
'author': u,
'category': cat10
"excerpt": rikeripsum.generate_paragraph(5),
"body": rikeripsum.generate_paragraph(100),
"date_added": datetime.strptime("2014-10-10 20:34:34 -0500", datetime_format),
"slug": "blog-entry-twenty",
"status": 1,
"title": "Blog Entry Twenty LIVE",
"author": u,
"category": cat10,
}
BlogEntry(**e1).save()
BlogEntry(**e2).save()
@@ -391,62 +437,142 @@ def blog_entry_factory():
entry19 = BlogEntry.objects.get(pk=19)
entry20 = BlogEntry.objects.get(pk=20)
entry1.tags.add(tag1, tag2)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry1.id, tag=tag1).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry1.id, tag=tag2).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry1.id, tag=tag1
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry1.id, tag=tag2
).save()
entry2.tags.add(tag3, tag4)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry2.id, tag=tag3).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry2.id, tag=tag4).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry2.id, tag=tag3
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry2.id, tag=tag4
).save()
entry3.tags.add(tag5, tag6)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry3.id, tag=tag5).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry3.id, tag=tag6).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry3.id, tag=tag5
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry3.id, tag=tag6
).save()
entry4.tags.add(tag7, tag8)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry4.id, tag=tag7).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry4.id, tag=tag8).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry4.id, tag=tag7
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry4.id, tag=tag8
).save()
entry5.tags.add(tag9, tag10)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry5.id, tag=tag9).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry5.id, tag=tag10).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry5.id, tag=tag9
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry5.id, tag=tag10
).save()
entry6.tags.add(tag11, tag12)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry6.id, tag=tag11).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry6.id, tag=tag12).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry6.id, tag=tag11
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry6.id, tag=tag12
).save()
entry7.tags.add(tag13, tag14)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry7.id, tag=tag13).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry7.id, tag=tag14).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry7.id, tag=tag13
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry7.id, tag=tag14
).save()
entry8.tags.add(tag15, tag16)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry8.id, tag=tag15).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry8.id, tag=tag16).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry8.id, tag=tag15
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry8.id, tag=tag16
).save()
entry9.tags.add(tag17, tag18)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry9.id, tag=tag17).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry9.id, tag=tag18).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry9.id, tag=tag17
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry9.id, tag=tag18
).save()
entry10.tags.add(tag19, tag20)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry10.id, tag=tag19).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry10.id, tag=tag20).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry10.id, tag=tag19
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry10.id, tag=tag20
).save()
entry11.tags.add(tag21, tag22)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry11.id, tag=tag21).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry11.id, tag=tag22).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry11.id, tag=tag21
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry11.id, tag=tag22
).save()
entry12.tags.add(tag23, tag24)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry12.id, tag=tag23).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry12.id, tag=tag24).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry12.id, tag=tag23
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry12.id, tag=tag24
).save()
entry13.tags.add(tag25, tag26)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry13.id, tag=tag25).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry13.id, tag=tag26).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry13.id, tag=tag25
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry13.id, tag=tag26
).save()
entry14.tags.add(tag27, tag28)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry14.id, tag=tag27).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry14.id, tag=tag28).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry14.id, tag=tag27
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry14.id, tag=tag28
).save()
entry15.tags.add(tag29, tag30)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry15.id, tag=tag29).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry15.id, tag=tag30).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry15.id, tag=tag29
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry15.id, tag=tag30
).save()
entry16.tags.add(tag31, tag32)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry16.id, tag=tag31).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry16.id, tag=tag32).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry16.id, tag=tag31
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry16.id, tag=tag32
).save()
entry17.tags.add(tag33, tag34)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry17.id, tag=tag33).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry17.id, tag=tag34).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry17.id, tag=tag33
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry17.id, tag=tag34
).save()
entry18.tags.add(tag35, tag36)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry18.id, tag=tag35).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry18.id, tag=tag36).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry18.id, tag=tag35
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry18.id, tag=tag36
).save()
entry19.tags.add(tag37, tag38)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry19.id, tag=tag37).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry19.id, tag=tag38).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry19.id, tag=tag37
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry19.id, tag=tag38
).save()
entry20.tags.add(tag39, tag40)
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry20.id, tag=tag39).save()
TaggedEntry(content_type_id=entry_content_type.id, object_id=entry20.id, tag=tag40).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry20.id, tag=tag39
).save()
TaggedEntry(
content_type_id=entry_content_type.id, object_id=entry20.id, tag=tag40
).save()

+ 11
- 7
momw/chroniko/feeds.py View File

@@ -17,7 +17,7 @@ except AttributeError:

class LatestEntriesFeed(Feed):
description = DESCRIPTION
link = '/blog/' # TODO: find out wtf this is for
link = "/blog/" # TODO: find out wtf this is for
title = TITLE

def items(self):
@@ -31,11 +31,15 @@ class LatestEntriesFeed(Feed):
return item.excerpt
else:
excerpt = item.body.split()[:50]
return ' '.join(excerpt)
return " ".join(excerpt)

def item_link(self, item):
return reverse('blog:entry_detail', kwargs={
'year': item.date_added.astimezone(TZ).strftime("%Y"),
'month': item.date_added.astimezone(TZ).strftime("%m"),
'day': item.date_added.astimezone(TZ).strftime("%d"),
'slug': item.slug})
return reverse(
"blog:entry_detail",
kwargs={
"year": item.date_added.astimezone(TZ).strftime("%Y"),
"month": item.date_added.astimezone(TZ).strftime("%m"),
"day": item.date_added.astimezone(TZ).strftime("%d"),
"slug": item.slug,
},
)

+ 11
- 9
momw/chroniko/forms.py View File

@@ -7,7 +7,7 @@ class CategoryForm(forms.ModelForm):
super().__init__(*args, **kwargs)

class Meta:
fields = '__all__'
fields = "__all__"
model = BlogCategory


@@ -16,7 +16,7 @@ class TagForm(forms.ModelForm):
super().__init__(*args, **kwargs)

class Meta:
fields = '__all__'
fields = "__all__"
model = BlogTag


@@ -31,20 +31,22 @@ class DeleteThingForm(forms.Form):
class EntryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['category'].widget.attrs['class'] = 'u-full-width'
self.fields['status'].widget.attrs['class'] = 'u-full-width'
self.fields['tags'].label = 'Comma-separated list of tags'
self.fields["category"].widget.attrs["class"] = "u-full-width"
self.fields["status"].widget.attrs["class"] = "u-full-width"
self.fields["tags"].label = "Comma-separated list of tags"

class Meta:
exclude = ('author', 'date_added')
exclude = ("author", "date_added")
model = BlogEntry

date_added_0 = forms.DateField(label='Publish Date', required=True)
date_added_1 = forms.TimeField(label='Publish Time', required=True)
date_added_0 = forms.DateField(label="Publish Date", required=True)
date_added_1 = forms.TimeField(label="Publish Time", required=True)


class ToggleTinyMCEForm(forms.Form):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

toggle_tinymce = forms.BooleanField(help_text="Toggle the TinyMCE editor on or off. Any unsaved data will be lost!!")
toggle_tinymce = forms.BooleanField(
help_text="Toggle the TinyMCE editor on or off. Any unsaved data will be lost!!"
)

+ 129
- 46
momw/chroniko/migrations/0001_initial.py View File

@@ -12,77 +12,160 @@ class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('contenttypes', '0002_remove_content_type_name'),
("contenttypes", "0002_remove_content_type_name"),
]

operations = [
migrations.CreateModel(
name='BlogCategory',
name="BlogCategory",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=250)),
('slug', models.SlugField(help_text='Suggested value automatically generated from title.', unique=True)),
('description', models.TextField()),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=250)),
(
"slug",
models.SlugField(
help_text="Suggested value automatically generated from title.",
unique=True,
),
),
("description", models.TextField()),
],
options={
'verbose_name': 'Category',
'verbose_name_plural': 'Categories',
'db_table': 'blog_categories',
'ordering': ['title'],
"verbose_name": "Category",
"verbose_name_plural": "Categories",
"db_table": "blog_categories",
"ordering": ["title"],
},
),
migrations.CreateModel(
name='BlogEntry',
name="BlogEntry",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('excerpt', models.TextField(blank=True)),
('featured', models.BooleanField(default=False)),
('date_added', models.DateTimeField()),
('date_updated', models.DateTimeField(auto_now=True)),
('slug', models.SlugField(unique=True)),
('status', models.IntegerField(choices=[(1, 'Live'), (2, 'Draft'), (3, 'Hidden')], default=2)),
('title', models.CharField(max_length=250)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
('category', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='chroniko.BlogCategory')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("body", models.TextField()),
("excerpt", models.TextField(blank=True)),
("featured", models.BooleanField(default=False)),
("date_added", models.DateTimeField()),
("date_updated", models.DateTimeField(auto_now=True)),
("slug", models.SlugField(unique=True)),
(
"status",
models.IntegerField(
choices=[(1, "Live"), (2, "Draft"), (3, "Hidden")], default=2
),
),
("title", models.CharField(max_length=250)),
(
"author",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
(
"category",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="chroniko.BlogCategory",
),
),
],
options={
'verbose_name': 'Entry',
'verbose_name_plural': 'Entries',
'db_table': 'blog_entries',
'ordering': ['-date_added'],
"verbose_name": "Entry",
"verbose_name_plural": "Entries",
"db_table": "blog_entries",
"ordering": ["-date_added"],
},
),
migrations.CreateModel(
name='BlogTag',
name="BlogTag",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True, verbose_name='Name')),
('slug', models.SlugField(max_length=100, unique=True, verbose_name='Slug')),
('is_enabled', models.BooleanField(default=True)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"name",
models.CharField(max_length=100, unique=True, verbose_name="Name"),
),
(
"slug",
models.SlugField(max_length=100, unique=True, verbose_name="Slug"),
),
("is_enabled", models.BooleanField(default=True)),
],
options={
'verbose_name': 'Tag',
'verbose_name_plural': 'Tags',
'db_table': 'blog_tags',
'ordering': ['-name'],
"verbose_name": "Tag",
"verbose_name_plural": "Tags",
"db_table": "blog_tags",
"ordering": ["-name"],
},
),
migrations.CreateModel(
name='TaggedEntry',
name="TaggedEntry",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('object_id', models.IntegerField(db_index=True, verbose_name='Object id')),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chroniko_taggedentry_tagged_items', to='contenttypes.ContentType', verbose_name='Content type')),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='chroniko_taggedentry_items', to='chroniko.BlogTag')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"object_id",
models.IntegerField(db_index=True, verbose_name="Object id"),
),
(
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="chroniko_taggedentry_tagged_items",
to="contenttypes.ContentType",
verbose_name="Content type",
),
),
(
"tag",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="chroniko_taggedentry_items",
to="chroniko.BlogTag",
),
),
],
options={
'db_table': 'tagged_blog_entries',
},
options={"db_table": "tagged_blog_entries"},
),
migrations.AddField(
model_name='blogentry',
name='tags',
field=taggit.managers.TaggableManager(blank=True, help_text='A comma-separated list of tags.', through='chroniko.TaggedEntry', to='chroniko.BlogTag', verbose_name='Tags'),
model_name="blogentry",
name="tags",
field=taggit.managers.TaggableManager(
blank=True,
help_text="A comma-separated list of tags.",
through="chroniko.TaggedEntry",
to="chroniko.BlogTag",
verbose_name="Tags",
),
),
]

+ 40
- 31
momw/chroniko/models.py View File

@@ -7,8 +7,12 @@ from django.db import models
from django.utils.translation import ugettext_lazy as _
from taggit.managers import TaggableManager
from taggit.models import TagBase, GenericTaggedItemBase
from utilz.managers import DraftThingManager, EnabledTagManager, \
HiddenThingManager, LiveThingManager
from utilz.managers import (
DraftThingManager,
EnabledTagManager,
HiddenThingManager,
LiveThingManager,
)


TZ = pendulum.timezone(settings.TIME_ZONE)
@@ -20,30 +24,29 @@ except AttributeError:

class BlogCategory(models.Model):
title = models.CharField(max_length=250)
slug = models.SlugField(help_text='Suggested value automatically generated from title.', unique=True)
slug = models.SlugField(
help_text="Suggested value automatically generated from title.", unique=True
)
description = models.TextField()

class Meta:
db_table = 'blog_categories'
ordering = ['title', ]
verbose_name = _('Category')
verbose_name_plural = _('Categories')
db_table = "blog_categories"
ordering = ["title"]
verbose_name = _("Category")
verbose_name_plural = _("Categories")

def __str__(self):
return self.title

def get_absolute_url(self):
return reverse('blog:category_detail', kwargs={'slug': self.slug})
return reverse("blog:category_detail", kwargs={"slug": self.slug})


class BlogEntry(models.Model):
LIVE = 1
DRAFT = 2
HIDDEN = 3
STATUS_CHOICES = (
(LIVE, 'Live'),
(DRAFT, 'Draft'),
(HIDDEN, 'Hidden'))
STATUS_CHOICES = ((LIVE, "Live"), (DRAFT, "Draft"), (HIDDEN, "Hidden"))
objects = models.Manager()
live = LiveThingManager()
draft = DraftThingManager()
@@ -58,26 +61,30 @@ class BlogEntry(models.Model):
title = models.CharField(max_length=250)
author = models.ForeignKey(get_user_model(), on_delete=models.PROTECT)
category = models.ForeignKey(BlogCategory, on_delete=models.PROTECT)
tags = TaggableManager(through='TaggedEntry', blank=True)
tags = TaggableManager(through="TaggedEntry", blank=True)

class Meta:
db_table = 'blog_entries'
ordering = ['-date_added', ]
verbose_name = _('Entry')
verbose_name_plural = _('Entries')
db_table = "blog_entries"
ordering = ["-date_added"]
verbose_name = _("Entry")
verbose_name_plural = _("Entries")

def __str__(self):
return self.title

def get_absolute_url(self, short=SHORT_URLS):
if short:
url = reverse("slug_root", kwargs={'slug': self.slug})
url = reverse("slug_root", kwargs={"slug": self.slug})
else:
url = reverse('blog:entry_detail', kwargs={
'year': self.date_added.astimezone(TZ).strftime("%Y"),
'month': self.date_added.astimezone(TZ).strftime("%m"),
'day': self.date_added.astimezone(TZ).strftime("%d"),
'slug': self.slug})
url = reverse(
"blog:entry_detail",
kwargs={
"year": self.date_added.astimezone(TZ).strftime("%Y"),
"month": self.date_added.astimezone(TZ).strftime("%m"),
"day": self.date_added.astimezone(TZ).strftime("%d"),
"slug": self.slug,
},
)
return url

def get_status_string(self):
@@ -90,10 +97,10 @@ class BlogTag(TagBase):
is_enabled = models.BooleanField(default=True)

class Meta:
db_table = 'blog_tags'
ordering = ['-name', ]
verbose_name = _('Tag')
verbose_name_plural = _('Tags')
db_table = "blog_tags"
ordering = ["-name"]
verbose_name = _("Tag")
verbose_name_plural = _("Tags")

@property
def tagged_entries(self):
@@ -108,16 +115,18 @@ class BlogTag(TagBase):
return self.chroniko_taggedentry_items.count()

def get_absolute_url(self):
return reverse('blog:tag_detail', kwargs={'slug': self.slug})
return reverse("blog:tag_detail", kwargs={"slug": self.slug})

def save(self, *args, **kwargs):
if not self.pk:
self.name = self.name.strip(',')
self.name = self.name.strip(",")
super().save(*args, **kwargs)


class TaggedEntry(GenericTaggedItemBase):
tag = models.ForeignKey(BlogTag, related_name='%(app_label)s_%(class)s_items', on_delete=models.PROTECT)
tag = models.ForeignKey(
BlogTag, related_name="%(app_label)s_%(class)s_items", on_delete=models.PROTECT
)

class Meta:
db_table = 'tagged_blog_entries'
db_table = "tagged_blog_entries"

+ 90
- 64
momw/chroniko/tests.py View File

@@ -7,10 +7,22 @@ from django.utils import timezone
from chroniko.data_seeds.blog import generate_category, generate_entry
from chroniko.models import BlogEntry
from .models import BlogCategory, BlogTag
from .views import CategoryDetailView, CategoryIndexView, DraftEntriesView, \
EntryDetailView, EntryIndexView, HiddenEntriesView, TagCloudView, \
TagDetailView, category_create, category_edit, entry_create, entry_delete,\
entry_edit, tag_edit
from .views import (
CategoryDetailView,
CategoryIndexView,
DraftEntriesView,
EntryDetailView,
EntryIndexView,
HiddenEntriesView,
TagCloudView,
TagDetailView,
category_create,
category_edit,
entry_create,
entry_delete,
entry_edit,
tag_edit,
)


HTTP_FOUND = 302
@@ -19,56 +31,74 @@ HTTP_NOT_FOUND = 404
HTTP_OK = 200


class SetUpBase():
class SetUpBase:
def setUp(self):
super().setUp()
self.f = RequestFactory()
# TODO: don't create a user here
if not User.objects.all():
self.u = User.objects.create(first_name="First Name",
last_name="Last Name",
username="first-last-jaja-lala",
password="12345",
is_superuser=True)
self.c = generate_category("Category One", "one",
"This is category one, yeah!")
self.c2 = generate_category("Category Two", "TWOOOOOOSWEEEET",
"This is category two, BoiiII!")
self.e = generate_entry("BODY " * 300,
timezone.localtime(timezone.now()),
"test-slug", BlogEntry.LIVE,
"Test Title", self.u, self.c)
self.e2 = generate_entry("BODY " * 300,
timezone.localtime(timezone.now()),
"test-slug2", BlogEntry.LIVE,
"Test Title 2", self.u, self.c2,
excerpt="EXCERPT " * 300)
self.u = User.objects.create(
first_name="First Name",
last_name="Last Name",
username="first-last-jaja-lala",
password="12345",
is_superuser=True,
)
self.c = generate_category("Category One", "one", "This is category one, yeah!")
self.c2 = generate_category(
"Category Two", "TWOOOOOOSWEEEET", "This is category two, BoiiII!"
)
self.e = generate_entry(
"BODY " * 300,
timezone.localtime(timezone.now()),
"test-slug",
BlogEntry.LIVE,
"Test Title",
self.u,
self.c,
)
self.e2 = generate_entry(
"BODY " * 300,
timezone.localtime(timezone.now()),
"test-slug2",
BlogEntry.LIVE,
"Test Title 2",
self.u,
self.c2,
excerpt="EXCERPT " * 300,
)
self.t = BlogTag.objects.create(name="live")
# TODO: use generate_entry() ??
self.el = BlogEntry.objects.create(excerpt="EXCERPT TIME",
body="BODY TIME",
date_added=timezone.now(),
slug="live-1",
status=BlogEntry.LIVE,
title="Live ONE",
author=self.u,
category=self.c)
self.ed = BlogEntry.objects.create(excerpt="EXCERPT TIME",
body="BODY TIME",
date_added=timezone.now(),
slug="draft-1",
status=BlogEntry.DRAFT,
title="Draft ONE",
author=self.u,
category=self.c)
self.eh = BlogEntry.objects.create(excerpt="EXCERPT TIME",
body="BODY TIME",
date_added=timezone.now(),
slug="hidden-1",
status=BlogEntry.HIDDEN,
title="Hidden ONE",
author=self.u,
category=self.c)
self.el = BlogEntry.objects.create(
excerpt="EXCERPT TIME",
body="BODY TIME",
date_added=timezone.now(),
slug="live-1",
status=BlogEntry.LIVE,
title="Live ONE",
author=self.u,
category=self.c,
)
self.ed = BlogEntry.objects.create(
excerpt="EXCERPT TIME",
body="BODY TIME",
date_added=timezone.now(),
slug="draft-1",
status=BlogEntry.DRAFT,
title="Draft ONE",
author=self.u,
category=self.c,
)
self.eh = BlogEntry.objects.create(
excerpt="EXCERPT TIME",
body="BODY TIME",
date_added=timezone.now(),
slug="hidden-1",
status=BlogEntry.HIDDEN,
title="Hidden ONE",
author=self.u,
category=self.c,
)


class ChronikoSeleniumTestCase(SetUpBase):
@@ -229,7 +259,6 @@ class ChronikoSeleniumTestCase(SetUpBase):

# TODO: many if not all of the below are obsoleted by the above selenium tests
class ChronikoTestCase(SetUpBase, TestCase):

def test_cat_absolute_url(self):
self.assertIsInstance(self.c.get_absolute_url(), str)

@@ -247,10 +276,9 @@ class ChronikoTestCase(SetUpBase, TestCase):
slug = self.el.slug
r = self.f.get(self.el.get_absolute_url())
r.user = AnonymousUser()
response = EntryDetailView.as_view()(r, year=year,
month=month,
day=day,
slug=slug)
response = EntryDetailView.as_view()(
r, year=year, month=month, day=day, slug=slug
)
self.assertEqual(response.status_code, HTTP_OK)

def test_live_entry_is_viewable_short_url(self):
@@ -273,8 +301,7 @@ class ChronikoTestCase(SetUpBase, TestCase):
self.assertEqual(response.status_code, HTTP_OK)

def test_category_detail(self):
r = self.f.get(reverse("blog:category_detail",
kwargs={"slug": self.c.slug}))
r = self.f.get(reverse("blog:category_detail", kwargs={"slug": self.c.slug}))
r.user = AnonymousUser()
response = CategoryDetailView.as_view()(r, slug=self.c.slug)
self.assertEqual(response.status_code, HTTP_OK)
@@ -295,25 +322,24 @@ class ChronikoTestCase(SetUpBase, TestCase):
self.assertEqual(r.status_code, HTTP_NOT_FOUND)

def test_category_create_post(self):
r = self.f.post(reverse("blog:new_category"),
data={"title": "New 1",
"slug": "new-1",
"description": "STUFF HERE"})
r = self.f.post(
reverse("blog:new_category"),
data={"title": "New 1", "slug": "new-1", "description": "STUFF HERE"},
)
r.user = self.u
category_create(r)
self.assertTrue(BlogCategory.objects.get(slug="new-1"))

def test_category_edit_post(self):
c = self.c
r = self.f.post(reverse("blog:category_edit",
kwargs={"slug": c.slug}),
data={"title": "New 11",
"slug": "new-11",
"description": "NEW STUFF HERE"})
r = self.f.post(
reverse("blog:category_edit", kwargs={"slug": c.slug}),
data={"title": "New 11", "slug": "new-11", "description": "NEW STUFF HERE"},
)
r.user = self.u
category_edit(r, slug=c.slug)
c_edited = BlogCategory.objects.get(pk=c.pk)
self.assertTrue(c_edited.slug == 'new-11')
self.assertTrue(c_edited.slug == "new-11")

# def test_category_delete(self):
# pass

+ 54
- 35
momw/chroniko/urls.py View File

@@ -2,42 +2,61 @@ from django.conf import settings
from django.urls import path
from django.views.decorators.cache import cache_page
from .feeds import LatestEntriesFeed
from .views import AllEntriesView, CategoryDetailView, CategoryIndexView, \
DraftEntriesView, EntriesByDayView, EntriesByMonthView, EntriesByYearView,\
EntryDetailView, EntryIndexView, HiddenEntriesView, TagCloudView, \
TagDetailView, category_create, category_delete, category_edit, \
entry_create, entry_delete, entry_edit, tag_edit
from .views import (
AllEntriesView,
CategoryDetailView,
CategoryIndexView,
DraftEntriesView,
EntriesByDayView,
EntriesByMonthView,
EntriesByYearView,
EntryDetailView,
EntryIndexView,
HiddenEntriesView,
TagCloudView,
TagDetailView,
category_create,
category_delete,
category_edit,
entry_create,
entry_delete,
entry_edit,
tag_edit,
)


app_name = 'chroniko' # TODO: DRY this
app_name = "chroniko" # TODO: DRY this
urlpatterns = [
path('', EntryIndexView.as_view(), name='index'),
path('categories/', CategoryIndexView.as_view(), name='category_index'),
path('categories/new/', category_create, name='new_category'),
path('categories/<slug:slug>/', CategoryDetailView.as_view(),
name='category_detail'),
path('categories/<slug:slug>/delete/', category_delete,
name='category_delete'),
path('categories/<slug:slug>/edit/', category_edit,
name='category_edit'),
path('drafts/', DraftEntriesView.as_view(), name='draft_entries'),
path('entries/all/', AllEntriesView.as_view(), name='all_entries'),
path('entries/new/', entry_create, name='new_entry'),
path('feeds/latest-entries/', cache_page(settings.CACHE_MIDDLEWARE_SECONDS)(LatestEntriesFeed()),
name='latest_entries_feed'),
path('hidden/', HiddenEntriesView.as_view(), name='hidden_entries'),
path('tag/cloud/', TagCloudView.as_view(), name='tag_cloud'),
path('tag/<slug:slug>/', TagDetailView.as_view(),
name='tag_detail'),
path('tag/<slug:slug>/edit/', tag_edit,
name='tag_edit'),
path('<slug:slug>/delete/', entry_delete, name='entry_delete'),
path('<slug:slug>/edit/', entry_edit, name='entry_edit'),
path('<int:year>/', EntriesByYearView.as_view(), name='by_year'),
path('<int:year>/<int:month>/', EntriesByMonthView.as_view(),
name='by_month'),
path('<int:year>/<int:month>/<int:day>/',
EntriesByDayView.as_view(), name='by_day'),
path('<int:year>/<int:month>/<int:day>/<slug:slug>/',
EntryDetailView.as_view(), name='entry_detail'),
path("", EntryIndexView.as_view(), name="index"),
path("categories/", CategoryIndexView.as_view(), name="category_index"),
path("categories/new/", category_create, name="new_category"),
path(
"categories/<slug:slug>/", CategoryDetailView.as_view(), name="category_detail"
),
path("categories/<slug:slug>/delete/", category_delete, name="category_delete"),
path("categories/<slug:slug>/edit/", category_edit, name="category_edit"),
path("drafts/", DraftEntriesView.as_view(), name="draft_entries"),
path("entries/all/", AllEntriesView.as_view(), name="all_entries"),
path("entries/new/", entry_create, name="new_entry"),
path(
"feeds/latest-entries/",
cache_page(settings.CACHE_MIDDLEWARE_SECONDS)(LatestEntriesFeed()),
name="latest_entries_feed",
),
path("hidden/", HiddenEntriesView.as_view(), name="hidden_entries"),
path("tag/cloud/", TagCloudView.as_view(), name="tag_cloud"),
path("tag/<slug:slug>/", TagDetailView.as_view(), name="tag_detail"),
path("tag/<slug:slug>/edit/", tag_edit, name="tag_edit"),
path("<slug:slug>/delete/", entry_delete, name="entry_delete"),
path("<slug:slug>/edit/", entry_edit, name="entry_edit"),
path("<int:year>/", EntriesByYearView.as_view(), name="by_year"),
path("<int:year>/<int:month>/", EntriesByMonthView.as_view(), name="by_month"),
path(
"<int:year>/<int:month>/<int:day>/", EntriesByDayView.as_view(), name="by_day"
),
path(
"<int:year>/<int:month>/<int:day>/<slug:slug>/",
EntryDetailView.as_view(),
name="entry_detail",
),
]

+ 143
- 93
momw/chroniko/views.py View File

@@ -4,125 +4,130 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.contenttypes.models import ContentType
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import render, reverse, get_object_or_404
from django.views.generic import (DayArchiveView, DetailView, ListView,
MonthArchiveView, YearArchiveView)
from django.views.generic import (
DayArchiveView,
DetailView,
ListView,
MonthArchiveView,
YearArchiveView,
)
from utilz.cache import CacheCtl
from . import (CHANGE_CATEGORY_PERM, CHANGE_ENTRY_PERM,
ENTRY_DATE_FIELD)
from .forms import CategoryForm, DeleteThingForm, EntryForm, TagForm, \
ToggleTinyMCEForm
from . import CHANGE_CATEGORY_PERM, CHANGE_ENTRY_PERM, ENTRY_DATE_FIELD
from .forms import CategoryForm, DeleteThingForm, EntryForm, TagForm, ToggleTinyMCEForm
from .models import BlogCategory, BlogEntry, BlogTag, TaggedEntry


# TODO: use a mixin for pagination
class AllEntriesView(CacheCtl, ListView):
context_object_name = 'all_entries'
context_object_name = "all_entries"
date_field = ENTRY_DATE_FIELD
queryset = BlogEntry.live.all()
template_name = 'all_entries.html'
template_name = "all_entries.html"
paginate_by = settings.PAGINATE_BY


class DraftEntriesView(LoginRequiredMixin, ListView):
context_object_name = 'draft_entries'
context_object_name = "draft_entries"
date_field = ENTRY_DATE_FIELD
queryset = BlogEntry.draft.all()
raise_exception = True
template_name = 'draft_entries.html'
template_name = "draft_entries.html"
paginate_by = settings.PAGINATE_BY


class EntriesByDayView(CacheCtl, DayArchiveView):
context_object_name = 'entries_by_day'
context_object_name = "entries_by_day"
date_field = ENTRY_DATE_FIELD
make_object_list = True
month_format = settings.MONTH_FORMAT
paginate_by = settings.PAGINATE_BY
queryset = BlogEntry.live.all()
template_name = 'entries_by_day.html'
template_name = "entries_by_day.html"
paginate_by = settings.PAGINATE_BY


class EntriesByMonthView(CacheCtl, MonthArchiveView):
context_object_name = 'entries_by_month'
context_object_name = "entries_by_month"
date_field = ENTRY_DATE_FIELD
make_object_list = True
month_format = settings.MONTH_FORMAT
paginate_by = settings.PAGINATE_BY
queryset = BlogEntry.live.all()
template_name = 'entries_by_month.html'
template_name = "entries_by_month.html"
paginate_by = settings.PAGINATE_BY


class EntriesByYearView(CacheCtl, YearArchiveView):
context_object_name = 'entries_by_year'
context_object_name = "entries_by_year"
date_field = ENTRY_DATE_FIELD
make_object_list = True
month_format = settings.MONTH_FORMAT
paginate_by = settings.PAGINATE_BY
queryset = BlogEntry.live.all()
template_name = 'entries_by_year.html'
template_name = "entries_by_year.html"
paginate_by = settings.PAGINATE_BY


class EntryDetailView(CacheCtl, DetailView):
context_object_name = 'entry'
context_object_name = "entry"
model = BlogEntry
month_format = settings.MONTH_FORMAT
queryset = BlogEntry.live.all()
template_name = 'entry_detail.html'
template_name = "entry_detail.html"
paginate_by = settings.PAGINATE_BY


class EntryIndexView(CacheCtl, ListView):
context_object_name = 'entry_list'
context_object_name = "entry_list"
date_field = ENTRY_DATE_FIELD
paginate_by = settings.PAGINATE_BY
paginate_orphans = 4
queryset = BlogEntry.live.all()
template_name = 'entry_index.html'
template_name = "entry_index.html"
paginate_by = settings.PAGINATE_BY


class HiddenEntriesView(LoginRequiredMixin, ListView):
context_object_name = 'hidden_entries'
context_object_name = "hidden_entries"
date_field = ENTRY_DATE_FIELD
queryset = BlogEntry.hidden.all()
raise_exception = True
template_name = 'hidden_entries.html'
template_name = "hidden_entries.html"
paginate_by = settings.PAGINATE_BY


class CategoryDetailView(CacheCtl, DetailView):
context_object_name = 'category'
context_object_name = "category"
model = BlogCategory
template_name = 'category_detail.html'
template_name = "category_detail.html"
paginate_by = settings.PAGINATE_BY

def get_context_data(self, **kwargs):
context = super(CategoryDetailView, self).get_context_data(**kwargs)
context['category_live_entries'] = BlogEntry.live.filter(category=context['object'].pk)
context["category_live_entries"] = BlogEntry.live.filter(
category=context["object"].pk
)
return context


class CategoryIndexView(CacheCtl, ListView):
context_object_name = 'categories'
context_object_name = "categories"
model = BlogCategory
template_name = 'category_index.html'
template_name = "category_index.html"
paginate_by = settings.PAGINATE_BY


class TagCloudView(CacheCtl, ListView):
context_object_name = 'tags'
context_object_name = "tags"
queryset = BlogTag.enabled.all()
template_name = 'tag_cloud.html'
template_name = "tag_cloud.html"
paginate_by = settings.PAGINATE_BY


class TagDetailView(CacheCtl, DetailView):
context_object_name = 'tag'
context_object_name = "tag"
model = BlogTag
template_name = 'tag_detail.html'
template_name = "tag_detail.html"
paginate_by = settings.PAGINATE_BY


@@ -130,7 +135,7 @@ def category_create(request):
form = CategoryForm()
user = request.user
if user.is_authenticated and user.has_perm(CHANGE_CATEGORY_PERM):
if request.method == 'POST':
if request.method == "POST":
postdata = request.POST.copy()
form = CategoryForm(postdata)
if form.is_valid():
@@ -138,10 +143,9 @@ def category_create(request):
# Redirect to the Category's edit page,
# in case the slug was changed.
return HttpResponseRedirect(
reverse("blog:category_edit",
kwargs={"slug": postdata.get("slug")}))
return render(request, 'category_create.html',
{'form': form})
reverse("blog:category_edit", kwargs={"slug": postdata.get("slug")})
)
return render(request, "category_create.html", {"form": form})
else:
raise Http404

@@ -159,7 +163,7 @@ def category_edit(request, slug):
form = CategoryForm()
user = request.user
if user.is_authenticated and user.has_perm(CHANGE_CATEGORY_PERM):
if request.method == 'POST':
if request.method == "POST":
postdata = request.POST.copy()
form = CategoryForm(postdata, instance=category)
if form.is_valid():
@@ -167,18 +171,18 @@ def category_edit(request, slug):
# Redirect to the Category's edit page,
# in case the slug was changed.
return HttpResponseRedirect(
reverse("blog:category_edit",
kwargs={"slug": postdata.get("slug")}))
return render(request, 'category_edit.html',
{'category': category,
'form': form})
reverse("blog:category_edit", kwargs={"slug": postdata.get("slug")})
)
return render(
request, "category_edit.html", {"category": category, "form": form}
)
else:
raise Http404


def entry_create(request):
"""Create a new Entry."""
datetime_format = '%Y-%m-%d %H:%M:%S %z'
datetime_format = "%Y-%m-%d %H:%M:%S %z"
user = request.user
try:
toggle_tinymce = settings.USE_TINYMCE
@@ -187,7 +191,7 @@ def entry_create(request):
if user.is_authenticated and user.has_perm(CHANGE_ENTRY_PERM):
form = EntryForm()
toggleform = ToggleTinyMCEForm()
if request.method == 'POST':
if request.method == "POST":
postdata = request.POST.copy()
if "toggleTinyMCE" not in postdata:
form = EntryForm(postdata)
@@ -198,40 +202,57 @@ def entry_create(request):
new_date = postdata.get("date_added_0", None)
new_time = postdata.get("date_added_1", None)
if new_date and new_time:
new_datetime_string = ' '.join((new_date, ''.join((
new_time, " ".join((":00", settings.TIME_ZONE_OFFSET))))))
new_datetime = datetime.strptime(new_datetime_string, datetime_format)
new_datetime_string = " ".join(
(
new_date,
"".join(
(
new_time,
" ".join((":00", settings.TIME_ZONE_OFFSET)),
)
),
)
)
new_datetime = datetime.strptime(
new_datetime_string, datetime_format
)
entry.date_added = new_datetime
form.save()
# Update the Entry's tags if need be.
new_tags = postdata.get("tags", None)
if new_tags:
for t in new_tags.split(', '):
for t in new_tags.split(", "):
entry.tags.add(t)
tag = BlogTag.objects.get(name=t)
entry_content_type = ContentType.objects.get_for_model(BlogEntry)
entry_content_type = ContentType.objects.get_for_model(
BlogEntry
)
TaggedEntry(
content_type_id=entry_content_type.id,
object_id=entry.id,
tag=tag).save()
tag=tag,
).save()
# Redirect to the Entry's edit page,
# in case the slug was changed.
return HttpResponseRedirect(
reverse("slug_entry_edit",
kwargs={"slug": postdata.get("slug")}))
reverse(
"slug_entry_edit", kwargs={"slug": postdata.get("slug")}
)
)
elif "toggleTinyMCE" in postdata:
form = EntryForm()
toggleform = ToggleTinyMCEForm(postdata)
if toggleform.is_valid():
if postdata.get("toggle_tinymce", None) == 'on':
if postdata.get("toggle_tinymce", None) == "on":
toggle_tinymce = True
else: # if request.method == 'POST':
postdata = None
toggleform = ToggleTinyMCEForm()
return render(request, 'entry_create.html',
{"form": form,
"toggle_tinymce": toggle_tinymce,
'toggleform': toggleform})
return render(
request,
"entry_create.html",
{"form": form, "toggle_tinymce": toggle_tinymce, "toggleform": toggleform},
)
else: # if user.is_authenticated and user.has_perm(CHANGE_ENTRY_PERM):
# Anonymous user
raise Http404
@@ -242,7 +263,7 @@ def tag_edit(request, slug):
form = TagForm()
user = request.user
if user.is_authenticated and user.has_perm(CHANGE_CATEGORY_PERM):
if request.method == 'POST':
if request.method == "POST":
postdata = request.POST.copy()
form = TagForm(postdata, instance=tag)
if form.is_valid():
@@ -250,11 +271,9 @@ def tag_edit(request, slug):
# Redirect to the Category's edit page,
# in case the slug was changed.
return HttpResponseRedirect(
reverse("blog:tag_edit",
kwargs={"slug": postdata.get("slug")}))
return render(request, 'tag_edit.html',
{'tag': tag,
'form': form})
reverse("blog:tag_edit", kwargs={"slug": postdata.get("slug")})
)
return render(request, "tag_edit.html", {"tag": tag, "form": form})
else:
raise Http404

@@ -275,22 +294,32 @@ def entry_delete(request, slug):
if user.is_authenticated and user.has_perm(CHANGE_ENTRY_PERM):
entry = get_object_or_404(BlogEntry, slug=slug)
form = DeleteThingForm()
if request.method == 'POST':
if request.method == "POST":
postdata = request.POST.copy()
form = DeleteThingForm(postdata)
if form.is_valid():
deleted_name = entry.__str__()
deleted = _delete_entry(entry)
return render(request, 'entry_delete.html', {
"deleted": deleted,
"deleted_name": deleted_name,
"entry": entry,
"form": form})
return render(request, 'entry_delete.html', {
"deleted": deleted,
"deleted_name": deleted_name,
"entry": entry,
"form": form})
return render(
request,
"entry_delete.html",
{
"deleted": deleted,
"deleted_name": deleted_name,
"entry": entry,
"form": form,
},
)
return render(
request,
"entry_delete.html",
{
"deleted": deleted,
"deleted_name": deleted_name,
"entry": entry,
"form": form,
},
)
else: # if user.is_authenticated and user.has_perm(CHANGE_ENTRY_PERM):
# Anonymous user
raise Http404
@@ -300,7 +329,7 @@ def entry_edit(request, slug):
"""Edit the Entry with the slug 'slug'."""
date_string = "%Y-%m-%d"
time_string = "%H:%M"
datetime_format = '%Y-%m-%d %H:%M:%S %z'
datetime_forma