Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.
Open
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
44 changes: 44 additions & 0 deletions django-verdant/rca/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from wagtail.wagtailadmin.forms import WagtailAdminPageForm


class StaffPageForm(WagtailAdminPageForm):
def clean(self):
cleaned_data = super(StaffPageForm, self).clean()

for form in self.formsets.get('roles', []):
self.clean_staff_page_role_form(form, cleaned_data)

def clean_staff_page_role_form(self, form, staff_page_cleaned_data):
if not form.is_valid():
return

area = form.cleaned_data.get('area')
location = form.cleaned_data.get('location')
programme = form.cleaned_data.get('programme')
school = form.cleaned_data.get('school')
staff_type = staff_page_cleaned_data.get('staff_type')

# Will display all errors at the same time, so need to create a dict
errors = {x: [] for x in ('area', 'location', 'programme', 'school')}

# Staff location must be only for technical staff
if staff_type != 'technical' and location:
errors['location'].append('Location can be assigned only to technical staff')

# School and programme must be only for academic staff
if staff_type != 'academic':
if school:
errors['school'].append('School can be assigned only to academic staff.')

if programme:
errors['programme'].append('Programme can be only assigned to academic staff.')

# Area cannot be filled in when staff is non-academic/administrative
if staff_type not in ('academic', 'administrative') and area:
errors['area'].append('Area can be only assigned to academic or administrative staff.')

# If there are any errors in our dict, raise them.
if any(errors.itervalues()):
for field_name, field_errors in errors.items():
for field_error in field_errors:
form.add_error(field_name, field_error)
3 changes: 1 addition & 2 deletions django-verdant/rca/help_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
('rca.ProgrammePage', 'programme_specification'): 'The link to download the programme specification',
('rca.ProgrammePage', 'twitter_feed'): 'Replace the default Twitter feed by providing an alternative Twitter handle, hashtag or search term',
('rca.ProgrammePage', 'feed_image'): 'The image displayed in content feeds, such as the news carousel. Should be 16:9 ratio.',

('rca.NewsIndex', 'twitter_feed'): 'Replace the default Twitter feed by providing an alternative Twitter handle (without the @ symbol)',
('rca.NewsIndex', 'feed_image'): 'The image displayed in content feeds, such as the news carousel. Should be 16:9 ratio.',
('rca.NewsItem', 'listing_intro'): 'Used only on pages listing news items',
Expand Down Expand Up @@ -65,7 +65,6 @@
('rca.AlumniPage', 'listing_intro'): 'Used only on pages displaying a list of pages of this type',
('rca.AlumniPage', 'feed_image'): 'The image displayed in content feeds, such as the news carousel. Should be 16:9 ratio.',
('rca.StaffPage', 'school'): 'Please complete this field for academic and administrative staff only',
('rca.StaffPage', 'staff_location'): 'Please complete this field for technical staff only',
('rca.StaffPage', 'listing_intro'): 'Used only on pages displaying a list of pages of this type',
('rca.StaffPage', 'supervised_student_other'): "Enter names of research students here who don't have a student profile. Supervised students with profile pages are pulled in automatically.",
('rca.StaffPage', 'feed_image'): 'The image displayed in content feeds, such as the news carousel. Should be 16:9 ratio.',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2017-07-06 21:26
from __future__ import unicode_literals
import json

from django.db import migrations


def move_area_data(apps, schema_editor):
"""
Move StaffPage.area to StaffPageRole.area if the user is
academic/administrative and if StaffPageRole.area is empty.
"""
StaffPage = apps.get_model('rca', 'StaffPage')

# Move area data to roles
records = StaffPage.objects \
.prefetch_related('roles') \
.filter(staff_type__in=('administrative', 'academic')) \
.filter(area__isnull=False)

print('Found {} records to update.'.format(records.count()))

for staff in records:
first_role = staff.roles.filter(area__isnull=True).first()

# Update revisions
if staff.has_unpublished_changes:
# Can't use get_latest_revision() as I am unable to call
# model methods in migrations.
revision = staff.revisions.order_by('-created_at', '-id').first()

if revision:
revision_json = json.loads(revision.content_json)

if revision_json['roles']:
print('Updating draft of {} (#{}).'.format(staff, staff.pk))

revision_json['roles'][0]['area'] = staff.area_id

revision.content_json = json.dumps(revision_json)
revision.save()

if first_role is not None:
print('Updating live version of {} (#{}).'.format(staff, staff.pk))

first_role.area = staff.area
first_role.save()


class Migration(migrations.Migration):
dependencies = [
('rca', '0087_doubleclickcampaignmanageractivities'),
]

operations = [
migrations.RunPython(move_area_data)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2017-07-06 21:28
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('rca', '0088_staffpage_migrate_area_data_to_roles'),
]

operations = [
migrations.RemoveField(
model_name='staffpage',
name='area',
),
migrations.AddField(
model_name='staffpagerole',
name='location',
field=models.CharField(blank=True, choices=[(b'ceramicsgsmj', b'Ceramics, Glass, Metalwork & Jewellery'), (b'darwinworshops', b'Darwin Workshops'), (b'fashiontextiles', b'Fashion & Textiles'), (b'lensbasedmediaaudio', b'Lens-based Media and Audio'), (b'paintingsculpture', b'Painting & Sculpture'), (b'printmakingletterpress', b'Printmaking & Letterpress'), (b'rapidform', b'Rapidform')], help_text=b'', max_length=255),
),
migrations.AlterField(
model_name='staffpage',
name='staff_type',
field=models.CharField(choices=[(b'academic', b'Academic'), (b'technical', b'Technical'), (b'administrative', b'Administrative')], help_text=b'', max_length=255),
),
migrations.AlterField(
model_name='staffpagerole',
name='title',
field=models.CharField(help_text=b'', max_length=255, verbose_name=b'Job title'),
),
]
59 changes: 59 additions & 0 deletions django-verdant/rca/migrations/0090_staffpage_move_location_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2017-07-06 21:26
from __future__ import unicode_literals
import json

from django.db import migrations


def move_location_data(apps, schema_editor):
"""
Move StaffPage.location to StaffPageRole.location if the user is
technical.
"""
StaffPage = apps.get_model('rca', 'StaffPage')

# Move location data to roles
records = StaffPage.objects \
.prefetch_related('roles') \
.exclude(staff_location='') \
.filter(staff_type='technical') \

print('Found {} records of technical staff with location data '
'to migrate.'.format(records.count()))

for staff in records:
# Update revisions
if staff.has_unpublished_changes:
# Can't use get_latest_revision() as I am unable to call
# model methods in migrations.
revision = staff.revisions.order_by('-created_at', '-id').first()

if revision:
revision_json = json.loads(revision.content_json)

if revision_json['roles']:
print('Updating draft of {} (#{}).'.format(staff, staff.pk))

revision_json['roles'][0]['location'] = staff.staff_location

revision.content_json = json.dumps(revision_json)
revision.save()

first_role = staff.roles.first()

if first_role is not None:
print('Updating live version of {} (#{}).'.format(staff, staff.pk))

first_role.location = staff.staff_location
first_role.save()


class Migration(migrations.Migration):
dependencies = [
('rca', '0089_staffpage_move_area_and_location_field_to_roles'),
]

operations = [
migrations.RunPython(move_location_data)
]
19 changes: 19 additions & 0 deletions django-verdant/rca/migrations/0091_staffpage_remove_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2017-07-06 21:28
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('rca', '0090_staffpage_move_location_data'),
]

operations = [
migrations.RemoveField(
model_name='staffpage',
name='staff_location',
),
]
35 changes: 17 additions & 18 deletions django-verdant/rca/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from rca_signage.constants import SCREEN_CHOICES
from reachout_choices import REACHOUT_PROJECT_CHOICES, REACHOUT_PARTICIPANTS_CHOICES, REACHOUT_THEMES_CHOICES, REACHOUT_PARTNERSHIPS_CHOICES

from .forms import StaffPageForm
from .help_text import help_text


Expand Down Expand Up @@ -832,12 +833,12 @@ class ProgrammePage(Page, SocialFields, SidebarBehaviourFields):
programme_specification_document = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, related_name='+', on_delete=models.SET_NULL, help_text=help_text('rca.ProgrammePage', 'programme_specification', default="Download the programme specification"))
ma_programme_description_link = models.ForeignKey(Page, null=True, blank=True, on_delete=models.SET_NULL, related_name='+', help_text=help_text('rca.ProgrammePage', 'ma_programme_description_link'))
ma_programme_description_link_text = models.CharField(max_length=255, blank=True, help_text=help_text('rca.ProgrammePage', 'ma_programme_description_link_text'))

ma_programme_staff_link = models.URLField("Programme staff link", blank=True, help_text=help_text('rca.ProgrammePage', 'ma_programme_staff_link'))
ma_programme_staff_link_text = models.CharField(max_length=255, blank=True, help_text=help_text('rca.ProgrammePage', 'ma_programme_staff_link_text'))
ma_programme_overview_link = models.ForeignKey(Page, null=True, blank=True, on_delete=models.SET_NULL, related_name='+', help_text=help_text('rca.ProgrammePage', 'ma_programme_overview_link'))
ma_programme_overview_link_text = models.CharField(max_length=255, blank=True, help_text=help_text('rca.ProgrammePage', 'ma_entry_requirements_link_text'))

ma_entry_requirements_link = models.ForeignKey(Page, null=True, blank=True, on_delete=models.SET_NULL, related_name='+', help_text=help_text('rca.ProgrammePage', 'ma_entry_requirements_link'))
ma_entry_requirements_link_text = models.CharField(max_length=255, blank=True, help_text=help_text('rca.ProgrammePage', 'ma_programme_overview_link_text'))
facilities_link = models.ForeignKey(Page, null=True, blank=True, on_delete=models.SET_NULL, related_name='+', help_text=help_text('rca.ProgrammePage', 'facilities_link'))
Expand Down Expand Up @@ -3015,19 +3016,22 @@ class JobsIndex(Page, SocialFields):
class StaffPageCarouselItem(Orderable, CarouselItemFields):
page = ParentalKey('rca.StaffPage', related_name='carousel_items')


class StaffPageRole(Orderable):
page = ParentalKey('rca.StaffPage', related_name='roles')
title = models.CharField(max_length=255, help_text=help_text('rca.StaffPageRole', 'title'))
title = models.CharField('Job title', max_length=255, help_text=help_text('rca.StaffPageRole', 'title'))
school = models.ForeignKey('taxonomy.School', null=True, blank=True, on_delete=models.SET_NULL, related_name='staff_roles', help_text=help_text('rca.StaffPageRole', 'school'))
programme = models.ForeignKey('taxonomy.Programme', null=True, blank=True, on_delete=models.SET_NULL, related_name='staff_roles', help_text=help_text('rca.StaffPageRole', 'programme'))
area = models.ForeignKey('taxonomy.Area', null=True, blank=True, on_delete=models.SET_NULL, related_name='staff_roles', help_text=help_text('rca.StaffPageRole', 'area'))
location = models.CharField(max_length=255, blank=True, choices=STAFF_LOCATION_CHOICES, help_text=help_text('rca.StaffPageRole', 'location'))
email = models.EmailField(max_length=255, blank=True, help_text=help_text('rca.StaffPageRole', 'email'))

api_fields = [
'title',
'school',
'programme',
'area',
'location'
'email',
]

Expand All @@ -3036,9 +3040,11 @@ class StaffPageRole(Orderable):
FieldPanel('school'),
FieldPanel('programme'),
FieldPanel('area'),
FieldPanel('location'),
FieldPanel('email'),
]


class StaffPageCollaborations(Orderable):
page = ParentalKey('rca.StaffPage', related_name='collaborations')
title = models.CharField(max_length=255, help_text=help_text('rca.StaffPageCollaborations', 'title'))
Expand Down Expand Up @@ -3089,10 +3095,8 @@ class StaffPagePublicationExhibition(Orderable):
]

class StaffPage(Page, SocialFields):
area = models.ForeignKey('taxonomy.Area', null=True, blank=True, on_delete=models.SET_NULL, related_name='staff', help_text=help_text('rca.StaffPage', 'area'))
profile_image = models.ForeignKey('rca.RcaImage', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', help_text=help_text('rca.StaffPage', 'profile_image'))
staff_type = models.CharField(max_length=255, blank=True, choices=STAFF_TYPES_CHOICES, help_text=help_text('rca.StaffPage', 'staff_type'))
staff_location = models.CharField(max_length=255, blank=True, choices=STAFF_LOCATION_CHOICES, help_text=help_text('rca.StaffPage', 'staff_location'))
staff_type = models.CharField(max_length=255, choices=STAFF_TYPES_CHOICES, help_text=help_text('rca.StaffPage', 'staff_type'))
twitter_feed = models.CharField(max_length=255, blank=True, help_text=help_text('rca.StaffPage', 'twitter_feed'))
intro = RichTextField(help_text=help_text('rca.StaffPage', 'intro'), blank=True)
biography = RichTextField(help_text=help_text('rca.StaffPage', 'biography'), blank=True)
Expand All @@ -3114,20 +3118,22 @@ class StaffPage(Page, SocialFields):
feed_image = models.ForeignKey('rca.RcaImage', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', help_text=help_text('rca.StaffPage', 'feed_image', default="The image displayed in content feeds, such as the news carousel. Should be 16:9 ratio."))
ad_username = models.CharField(max_length=255, blank=True, verbose_name='AD username', help_text=help_text('rca.StaffPage', 'ad_username'))

base_form_class = StaffPageForm

search_fields = Page.search_fields + [
index.RelatedFields('area', [
index.SearchField('display_name'),
index.RelatedFields('roles', [
index.RelatedFields('area', [
index.SearchField('display_name'),
]),
]),
index.SearchField('get_staff_type_display'),
index.SearchField('intro'),
index.SearchField('biography'),
]

api_fields = [
'area',
'profile_image',
'staff_type',
'staff_location',
'twitter_feed',
'intro',
'biography',
Expand Down Expand Up @@ -3162,10 +3168,8 @@ class StaffPage(Page, SocialFields):
FieldPanel('first_name'),
FieldPanel('last_name'),
], 'Full name'),
FieldPanel('area'),
ImageChooserPanel('profile_image'),
FieldPanel('staff_type'),
FieldPanel('staff_location'),
InlinePanel('roles', label="Roles"),
FieldPanel('intro', classname="full"),
FieldPanel('biography', classname="full"),
Expand Down Expand Up @@ -3256,8 +3260,6 @@ def serve(self, request):
# Area
area_options = Area.objects.filter(
id__in=StaffPageRole.objects.values_list('area', flat=True)
) | Area.objects.filter(
id__in=StaffPage.objects.values_list('area', flat=True)
)

area = area_options.filter(slug=area_slug).first()
Expand All @@ -3274,10 +3276,7 @@ def serve(self, request):
)

if area:
staff_pages = staff_pages.filter(
models.Q(area=area) |
models.Q(roles__area=area)
)
staff_pages = staff_pages.filter(roles__area=area)

if staff_type:
staff_pages = staff_pages.filter(staff_type=staff_type)
Expand Down
Loading