Skip to content

Commit

Permalink
A ton of docstrings and code style clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed Apr 10, 2020
1 parent 8183dcc commit dd9042b
Show file tree
Hide file tree
Showing 49 changed files with 1,650 additions and 906 deletions.
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ disable=print-statement,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
comprehension-escape
comprehension-escape,
too-many-ancestors,
logging-format-interpolation

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
14 changes: 10 additions & 4 deletions apps/cms/admin.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
"""Admin module for managing pages."""
from django.contrib import admin
from apps.cms.models import ContentPage, HomePage, CollectionsPage, VolumesPage

class HomePageAdmin(admin.ModelAdmin):
"""Home page admin class."""
search_fields = ('featured_volumes', 'featured_collections')
autocomplete_fields = ('featured_volumes',)
class Meta:
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
model = HomePage

class ContentPageAdmin(admin.ModelAdmin):
class Meta:
"""Content page admin class."""
# TODO: What are content pages? Add description to docstring above.
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
model = ContentPage

class CollectionsPageAdmin(admin.ModelAdmin):
class Meta:
"""Collections page admin class."""
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
model = CollectionsPage

class VolumesPageAdmin(admin.ModelAdmin):
class Meta:
"""Volumes page admin class."""
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
model = VolumesPage

admin.site.register(ContentPage, ContentPageAdmin)
Expand Down
3 changes: 2 additions & 1 deletion apps/cms/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""App config"""
from django.apps import AppConfig


class CmsConfig(AppConfig):
"""Config for CMS app."""
name = 'apps.cms'
verbose_name = "Content Management System"
7 changes: 4 additions & 3 deletions apps/cms/blocks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Custom `StructBlock` classes."""
from wagtail.images.blocks import ImageChooserBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtail.core.blocks import (
Expand All @@ -14,7 +15,7 @@ class ImageBlock(StructBlock):
caption = CharBlock(required=False)
attribution = CharBlock(required=False)

class Meta:
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
icon = 'image'
template = "blocks/image_block.html"

Expand All @@ -31,7 +32,7 @@ class HeadingBlock(StructBlock):
('h4', 'H4')
], blank=True, required=False)

class Meta:
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
icon = "title"
template = "blocks/heading_block.html"

Expand All @@ -44,7 +45,7 @@ class BlockQuote(StructBlock):
attribute_name = CharBlock(
blank=True, required=False, label='e.g. Mary Berry')

class Meta:
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
icon = "fa-quote-left"
template = "blocks/blockquote.html"

Expand Down
176 changes: 93 additions & 83 deletions apps/cms/models.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
from django.db import models
from django import forms
from wagtail.core.models import Page, Orderable
from modelcluster.models import ClusterableModel
"""CMS Models."""
from urllib.parse import urlencode
from modelcluster.fields import ParentalManyToManyField
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField, StreamField
from modelcluster.fields import ParentalKey, ParentalManyToManyField
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtailautocomplete.edit_handlers import AutocompletePanel
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel, InlinePanel
from urllib.parse import urlencode
from urllib.parse import urlencode
from django.http.response import Http404
from django.http import request

from .blocks import BaseStreamBlock
from django.db import models
from apps.cms.blocks import BaseStreamBlock
from apps.readux.models import UserAnnotation
from ..iiif.kollections.models import Collection
from ..iiif.manifests.models import Manifest
from ..iiif.canvases.models import Canvas
from ..iiif import manifests
import urllib.request
from apps.iiif.kollections.models import Collection
from apps.iiif.manifests.models import Manifest
from apps.iiif.canvases.models import Canvas

class ContentPage(Page):
"""Content page"""
body = StreamField(
BaseStreamBlock(), verbose_name="Page body", blank=True
)
Expand All @@ -29,13 +23,20 @@ class ContentPage(Page):
]

class CollectionsPage(Page):
"""Collections page"""
page_title = models.TextField(blank=True)
tagline = models.TextField(blank=True)
paragraph = models.TextField(blank=True)
layout = models.CharField(max_length=20, choices = (("Grid", "Grid"),
("List", "List"),("Banner", "Banner")),
default = "List",
help_text="Select to show all volumes as a list or a grid of icons.")
layout = models.CharField(
max_length=20,
choices =(
("Grid", "Grid"),
("List", "List"),
("Banner", "Banner")
),
default="List",
help_text="Select to show all volumes as a list or a grid of icons."
)
collections = Collection.objects.all
volumes = Manifest.objects.all
content_panels = Page.content_panels + [
Expand All @@ -46,13 +47,19 @@ class CollectionsPage(Page):
]

class VolumesPage(Page):
"""Content page"""
page_title = models.TextField(blank=True)
tagline = models.TextField(blank=True)
paragraph = models.TextField(blank=True)
layout = models.CharField(max_length=20, choices = (("Grid", "Grid"),
("List", "List"),),
default = "Grid",
help_text="Select to show all volumes as a list or a grid of icons.")
layout = models.CharField(
max_length=20,
choices=(
("Grid", "Grid"),
("List", "List"),
),
default="Grid",
help_text="Select to show all volumes as a list or a grid of icons."
)
collections = Collection.objects.all
volumes = Manifest.objects.all
content_panels = Page.content_panels + [
Expand All @@ -61,27 +68,13 @@ class VolumesPage(Page):
FieldPanel('paragraph', classname="full"),
FieldPanel('layout', classname="full"),
]
# def get_context(self, request):
# context = super(VolumesPage, self).get_context(request)
# sort_order = self.get_sort(request)
# volumes = Manifest.objects.all().order_by(sort_order)
# context['sort'] = request.GET.get('sort', 'created_at')
# context['volumes'] = volumes
# return context
#
# def get_sort(self, request):
# if request.GET.get('sort', 'created_at') == 'created_at':
# return '-created_at'
# else:
# return 'label'


def get_context(self, request):
"""Context function."""
context = super().get_context(request)
sort = request.GET.get('sort', None)
order = request.GET.get('order', None)

q = Manifest.objects.all()
query_set = Manifest.objects.all()

sort_options = ['title', 'author', 'date published', 'date added']
order_options = ['asc', 'desc']
Expand All @@ -94,25 +87,25 @@ def get_context(self, request):
order = 'asc'

if sort == 'title':
if(order == 'asc'):
q = q.order_by('label')
elif(order == 'desc'):
q = q.order_by('-label')
if order == 'asc':
query_set = query_set.order_by('label')
elif order == 'desc':
query_set = query_set.order_by('-label')
elif sort == 'author':
if(order == 'asc'):
q = q.order_by('author')
elif(order == 'desc'):
q = q.order_by('-author')
if order == 'asc':
query_set = query_set.order_by('author')
elif order == 'desc':
query_set = query_set.order_by('-author')
elif sort == 'date published':
if(order == 'asc'):
q = q.order_by('published_date')
elif(order == 'desc'):
q = q.order_by('-published_date')
if order == 'asc':
query_set = query_set.order_by('published_date')
elif order == 'desc':
query_set = query_set.order_by('-published_date')
elif sort == 'date added':
if(order == 'asc'):
q = q.order_by('created_at')
elif(order == 'desc'):
q = q.order_by('-created_at')
if order == 'asc':
query_set = query_set.order_by('created_at')
elif order == 'desc':
query_set = query_set.order_by('-created_at')

sort_url_params = request.GET.copy()
order_url_params = request.GET.copy()
Expand All @@ -123,12 +116,12 @@ def get_context(self, request):
del sort_url_params['sort']
elif 'order' in order_url_params:
del order_url_params['order']
context['volumespage'] = q.all

context['volumespage'] = query_set.all
context['user_annotation'] = UserAnnotation.objects.filter(owner_id=request.user.id)
annocount_list = []
canvaslist = []
for volume in q:
for volume in query_set:
user_annotation_count = UserAnnotation.objects.filter(owner_id=request.user.id).filter(canvas__manifest__id=volume.id).count()
annocount_list.append({volume.pid: user_annotation_count})
context['user_annotation_count'] = annocount_list
Expand All @@ -140,60 +133,77 @@ def get_context(self, request):
context['value'] = value

context.update({
'sort_url_params': urlencode(sort_url_params),
'order_url_params': urlencode(order_url_params),
'sort': sort, 'sort_options': sort_options,
'order': order, 'order_options': order_options,
})
'sort_url_params': urlencode(sort_url_params),
'order_url_params': urlencode(order_url_params),
'sort': sort, 'sort_options': sort_options,
'order': order, 'order_options': order_options,
})
return context


class HomePage(Page):
"""Home page"""
tagline = RichTextField(blank=True)
content_display = models.CharField(max_length=20, choices = (("Collections", "Collections"),
("Volumes", "Volumes"),),
default = "Collections",
help_text="Select to show all collections or all volumes on the home page")
content_display = models.CharField(
max_length=20,
choices=(
("Collections", "Collections"),
("Volumes", "Volumes"),
),
default="Collections",
help_text="Select to show all collections or all volumes on the home page"
)
featured_collections = ParentalManyToManyField(Collection, blank=True)
featured_collections_sort_order = models.CharField(max_length=20, choices = (
featured_collections_sort_order = models.CharField(
max_length=20,
choices=(
("label", "Title"),
("created_at", "Input Date"),),
default = "label",
help_text="Select order to sort collections on home page")
("created_at", "Input Date"),
),
default="label",
help_text="Select order to sort collections on home page"
)
featured_volumes = ParentalManyToManyField(Manifest, blank=True)
featured_volumes_sort_order = models.CharField(max_length=20, choices = (
featured_volumes_sort_order = models.CharField(
max_length=20,
choices=(
("label", "Title"),
("created_at", "Input Date"),
("author", "Author"),
("published_date", "Publication Date"),),
default = "label",
help_text="Select order to sort volumes on home page")
("published_date", "Publication Date"),
),
default="label",
help_text="Select order to sort volumes on home page"
)
collections = Collection.objects.all
volumes = Manifest.objects.all

content_panels = Page.content_panels + [
FieldPanel('tagline', classname="full"),
FieldPanel('content_display', classname="full"),
#FieldPanel('featured_collections', widget=forms.CheckboxSelectMultiple, classname="full"),
AutocompletePanel('featured_collections', target_model="kollections.Collection"),
FieldPanel('featured_collections_sort_order', classname="full"),
AutocompletePanel('featured_volumes', target_model="manifests.Manifest"),
#FieldPanel('featured_volumes', widget=forms.CheckboxSelectMultiple, classname="full"),
FieldPanel('featured_volumes_sort_order', classname="full"),
]


def get_context(self, request):
"""Function that returns context"""
context = super().get_context(request)
q = Manifest.objects.all()
query_set = Manifest.objects.all()

context['volumespage'] = q.all
context['volumespage'] = query_set.all
context['user_annotation'] = UserAnnotation.objects.filter(owner_id=request.user.id)
context['volumesurl'] = Page.objects.type(VolumesPage).first()
annocount_list = []
canvaslist = []
for volume in q:
user_annotation_count = UserAnnotation.objects.filter(owner_id=request.user.id).filter(canvas__manifest__id=volume.id).count()
for volume in query_set:
user_annotation_count = UserAnnotation.objects.filter(
owner_id=request.user.id
).filter(
canvas__manifest__id=volume.id
).count()
annocount_list.append({volume.pid: user_annotation_count})
context['user_annotation_count'] = annocount_list
canvasquery = Canvas.objects.filter(is_starting_page=1).filter(manifest__id=volume.id)
Expand Down
3 changes: 0 additions & 3 deletions apps/cms/views.py

This file was deleted.

0 comments on commit dd9042b

Please sign in to comment.