diff --git a/core/frontend/sass/modules/_cards.scss b/core/frontend/sass/modules/_cards.scss index e102471..fb265f5 100644 --- a/core/frontend/sass/modules/_cards.scss +++ b/core/frontend/sass/modules/_cards.scss @@ -76,6 +76,9 @@ .project-author { color: $color-light-text; + .project-featuring { + font-size: 0.875em; + } } .project-author--block { diff --git a/core/migrations/0011_add_cooperation_field_to_site.py b/core/migrations/0011_add_cooperation_field_to_site.py new file mode 100644 index 0000000..89b10cd --- /dev/null +++ b/core/migrations/0011_add_cooperation_field_to_site.py @@ -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' + ), + ), + ] diff --git a/core/models.py b/core/models.py old mode 100644 new mode 100755 index c8e1e96..60ef492 --- a/core/models.py +++ b/core/models.py @@ -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 @@ -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'], }, @@ -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 @@ -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') diff --git a/core/panels.py b/core/panels.py index a9364d8..d3a4208 100644 --- a/core/panels.py +++ b/core/panels.py @@ -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 + [ diff --git a/core/templates/core/includes/sites.html b/core/templates/core/includes/sites.html index 98a9ba3..6798126 100644 --- a/core/templates/core/includes/sites.html +++ b/core/templates/core/includes/sites.html @@ -29,7 +29,17 @@