Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cooperation field to site pages #125

Merged
merged 8 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/frontend/sass/modules/_cards.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@

.project-author {
color: $color-light-text;
.project-featuring {
font-size: 0.875em;
}
}

.project-author--block {
Expand Down
27 changes: 27 additions & 0 deletions core/migrations/0011_add_cooperation_field_to_site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2018-05-04 09:19
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

dependencies = [
('core', '0010_wagtailsitepage_screenshot'),
]

operations = [
migrations.AddField(
model_name='wagtailsitepage',
name='in_cooperation_with',
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='+',
to='core.WagtailCompanyPage'
),
),
]
40 changes: 35 additions & 5 deletions core/models.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.db.models import Count
from django.db.models import Case, Count, Q, Value, When
from django.utils.encoding import python_2_unicode_compatible
from django.utils.html import mark_safe
from modelcluster.fields import ParentalKey
Expand Down Expand Up @@ -244,13 +244,15 @@ class WagtailCompanyPage(WagtailPage):
parent_types = ['core.HomePage']
subpage_types = ['core.WagtailSitePage']

SITES_ORDERING_ALPHABETICAL = 'alphabetical'
SITES_ORDERING_CREATED = 'created'
SITES_ORDERING_PATH = 'path'
SITES_ORDERING = {
'path': {
SITES_ORDERING_PATH: {
'name': 'Path (i.e. manual)',
'ordering': ['-path'],
},
'alphabetical': {
SITES_ORDERING_ALPHABETICAL: {
'name': 'Alphabetical',
'ordering': ['title'],
},
Expand Down Expand Up @@ -341,12 +343,32 @@ def og_image(self):
return image

def children(self):
ordering = self.SITES_ORDERING[self.sites_ordering]['ordering']
return WagtailSitePage.objects.live().descendant_of(self).order_by(*ordering)
user_ordering = self.SITES_ORDERING[self.sites_ordering]['ordering']
pages = WagtailSitePage.objects.live().filter(Q(path__startswith=self.path) | Q(in_cooperation_with=self))

# When ordering by `path`, the collaborations would either all be listed first or last
# depending on whether the collaborator(s) page(s) was created before or after this page.
# Adding an overwrite here so collaborations always appear last.
if self.sites_ordering == self.SITES_ORDERING_PATH:
pages = pages.annotate(
is_own=Case(
When(path__startswith=self.path, then=Value(True)),
default_value=Value(False),
output_field=models.BooleanField(),
)
).order_by('is_own', *user_ordering)

# When ordering alphabetically or by creation date,
# own sites and collaboration sites will be sorted together.
else:
pages = pages.order_by(*user_ordering)

return pages

def get_context(self, request, *args, **kwargs):
# Get pages
pages = self.children()

# Pagination
page = request.GET.get('page')
paginator = Paginator(pages, 12) # Show 12 pages per page
Expand Down Expand Up @@ -405,6 +427,14 @@ class WagtailSitePage(WagtailPage):
help_text='The URL of your site, something like "https://www.springload.co.nz"',
)

in_cooperation_with = models.ForeignKey(
'core.WagtailCompanyPage',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
)

search_fields = Page.search_fields + [
index.SearchField('site_url'),
index.SearchField('body_text')
Expand Down
1 change: 1 addition & 0 deletions core/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ImageChooserPanel('site_screenshot'),
FieldPanel('body', classname="full"),
FieldPanel('tags'),
FieldPanel('in_cooperation_with'),
]

WAGTAIL_COMPANY_PAGE_CONTENT_PANELS = HOME_PAGE_CONTENT_PANELS + [
Expand Down
12 changes: 11 additions & 1 deletion core/templates/core/includes/sites.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ <h4 class="project-title">
{{ page.title }}
</h4>
<p class="project-author">
{{ page.parent.title|default:"A Wagtail developer" }}
<a href="{{ page.parent.url }}" title="View the company page of {{ page.parent.title|default:"A Wagtail developer" }}">
{{ page.parent.title|default:"A Wagtail developer" }}
</a>
{% if page.in_cooperation_with %}
<span class="project-featuring">
&mdash; in cooperation with
<a href="{{ page.in_cooperation_with.url }}">
{{ page.in_cooperation_with.title }}
</a>
</span>
{% endif %}
</p>
</div>
{% endfor %}
Expand Down
6 changes: 6 additions & 0 deletions core/templates/core/wagtail_site_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ <h2>{{ self.title }}</h2>
Made by <a href="{{self.parent.url}}" title="">
{{ self.parent.title }}
</a>
{% if self.in_cooperation_with %}
<span class="project-featuring">&mdash; in cooperation with <a href="{{self.in_cooperation_with.url}}" title="">
{{ self.in_cooperation_with.title }}
</a>
</span>
{% endif %}
</p>
{{ self.body|richtext }}

Expand Down