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 a 'in cooperation with' field to site submissions #120

Closed
wants to merge 6 commits into from
Closed
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'
),
),
]
21 changes: 15 additions & 6 deletions core/models.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
from operator import itemgetter

from bs4 import BeautifulSoup
from core import panels
from core.forms import SubmitFormBuilder
from core.utilities import has_recaptcha, validate_only_one_instance
Copy link
Contributor

@loicteixeira loicteixeira May 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those imports should stay where they were as it is enforced by isort.

I'm not sure why the CI didn't run on this PR. If it still doesn't run on next commit, you can run make lint-py from within the Vagrant box to verify that it's all good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allright I'll revert that change.

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 Count, Q
from django.utils.encoding import python_2_unicode_compatible
from django.utils.html import mark_safe
from modelcluster.fields import ParentalKey
Expand All @@ -18,10 +21,6 @@
from wagtail.wagtailsearch import index
from wagtailcaptcha.models import WagtailCaptchaEmailForm

from core import panels
from core.forms import SubmitFormBuilder
from core.utilities import has_recaptcha, validate_only_one_instance


class IndexPage(models.Model):
"""
Expand Down Expand Up @@ -346,7 +345,9 @@ def children(self):

def get_context(self, request, *args, **kwargs):
# Get pages
pages = self.children()
pages = WagtailSitePage.objects.filter(
Q(path__startswith=self.path) | Q(in_cooperation_with=self)
).distinct()
Copy link
Contributor

@loicteixeira loicteixeira May 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is losing the custom ordering defined in the children method (controlled in the admin via the sites_ordering field).

It should be possible to re-add the ordering without much issue for the alphabetical and created options. However it might be problematic for the path option as it was meant to allow manual ordering of pages but you won't be able to control the contributions (i.e. site not owned directly) would all appear either first or last (depending on whether the other developer profile was created before or after yours). Any ideas?

Copy link
Contributor Author

@thijskramer thijskramer May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can add an option to a CompanyPage, whether to 'mix' the cooperations with self-developed sites, or show cooperations separately from developed sites.
When the sorting preference is 'alphabetical' or 'created', the option can be applied on the separate queries / whole query.
When the sorting preference is 'path (manual)', maybe always show the self-developed sites (manually ordered) first, and then the cooperations (ordered by creation_date) after that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While adding an additional option would indeed help covering all the use-cases, I would rather keep it simple for now (until we have a need for more control):

  • alphabetical: order all sites together by title
  • created: order all sites together by first_published_at
  • path: order all self-developed sites by path first, then all cooperations sites by path

How does that sound?

# Pagination
page = request.GET.get('page')
paginator = Paginator(pages, 12) # Show 12 pages per page
Expand Down Expand Up @@ -405,6 +406,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