Skip to content

Commit

Permalink
Merge pull request #1099 from okfn/develop
Browse files Browse the repository at this point in the history
[PROD] Clean old Board/Advisory models
  • Loading branch information
pdelboca authored Jun 11, 2024
2 parents 60c8d4d + 4708211 commit 79c6960
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 216 deletions.
19 changes: 2 additions & 17 deletions foundation/organisation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.contrib import admin
from .forms import PersonForm
from .models import (
Person, Board, NetworkGroup,
BoardMembership, NetworkGroupMembership, SideBarExtension
Person, NetworkGroup,
NetworkGroupMembership, SideBarExtension
)

from cms.extensions import PageExtensionAdmin
Expand All @@ -20,21 +20,6 @@ class PersonAdmin(reversion.admin.VersionAdmin):
admin.site.register(Person, PersonAdmin)


class BoardMembershipInline(admin.TabularInline):
model = BoardMembership


class BoardAdmin(reversion.admin.VersionAdmin):
list_display = ('name',)
ordering = ('name',)

prepopulated_fields = {"slug": ("name",)}
inlines = [BoardMembershipInline]


admin.site.register(Board, BoardAdmin)


class NetworkGroupMembershipInline(admin.TabularInline):
model = NetworkGroupMembership

Expand Down
20 changes: 0 additions & 20 deletions foundation/organisation/cms_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@
from django.utils.translation import gettext_lazy as _


class BoardAppHook(CMSApp):
name = _("Board of Directors")

def get_urls(self, page=None, language=None, **kwargs):
return ["foundation.organisation.urls.board"]


apphook_pool.register(BoardAppHook)


class AdvisoryBoardAppHook(CMSApp):
name = _("Advisory Board")

def get_urls(self, page=None, language=None, **kwargs):
return ["foundation.organisation.urls.advisoryboard"]


apphook_pool.register(AdvisoryBoardAppHook)


class NetworkGroupsAppHook(CMSApp):
name = _("Network Groups")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.3 on 2024-06-11 08:43

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('organisation', '0024_remove_unitmembership_person_and_more'),
]

operations = [
migrations.RemoveField(
model_name='boardmembership',
name='board',
),
migrations.RemoveField(
model_name='boardmembership',
name='person',
),
migrations.DeleteModel(
name='Board',
),
migrations.DeleteModel(
name='BoardMembership',
),
]
41 changes: 1 addition & 40 deletions foundation/organisation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.urls import reverse
from django.urls.exceptions import NoReverseMatch
from django.db import models
from django.utils.text import slugify, Truncator
from django.utils.text import slugify
from django_countries.fields import CountryField


Expand Down Expand Up @@ -114,45 +114,6 @@ def __repr__(self):
return "<NowDoing: {}, {}>".format(self.person.name, self.doing_type)


class Board(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

name = models.CharField(max_length=100)
slug = models.SlugField(max_length=100, unique=True)
description = models.TextField()

members = models.ManyToManyField("Person", through="BoardMembership")

@property
def placeholder(self):
return Truncator(self.name).chars(10, truncate="...") + " (sidebar)"

def get_absolute_url(self):
return reverse("board")

def __str__(self):
return self.name


class BoardMembership(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

title = models.CharField(max_length=100)
person = models.ForeignKey("Person", on_delete=models.CASCADE)
board = models.ForeignKey("Board", on_delete=models.CASCADE)
order = models.IntegerField(
blank=True, null=True, help_text="Higher numbers mean higher up in the list"
)

def __str__(self):
return self.person.name + " - " + self.title

class Meta:
ordering = ["-order", "person__name"]


class NetworkGroupManager(models.Manager):
def countries(self):
return self.get_queryset().filter(region_slug="")
Expand Down
107 changes: 0 additions & 107 deletions foundation/organisation/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,126 +1,19 @@
from io import StringIO

from django.urls import reverse
from django.utils.html import escape
from django_webtest import WebTest
from unittest import skip

from iso3166 import countries
import csv

from ..models import (
Board,
Person,
NetworkGroup,
NetworkGroupMembership,
BoardMembership,
NowDoing,
)


class BoardViewTest(WebTest):
def setUp(self):
self.leonardo = Person.objects.create(
name="Leonardo (Leo)",
description="Turtle with a blue mask",
email="[email protected]",
)
self.april = Person.objects.create(
name="April O'Neil",
description="Computer Programmer",
email="[email protected]",
twitter="april",
url="http://oneil.me",
)
self.casey = Person.objects.create(
name="Casey Jones",
description="Hockey mask wearing vigilante",
email="[email protected]",
twitter="arnold",
)
self.splinter = Person.objects.create(
name="Splinter", description="Ninja rat", email="[email protected]"
)

self.board = Board.objects.create(
name="Board of directors",
slug="board",
description="The board consists of a rat",
)
self.council = Board.objects.create(
name="Advisory Council",
slug="advisory-board",
description="Get a room you two!",
)

self.rat_board = BoardMembership.objects.create(
title="Director", person=self.splinter, board=self.board
)

self.april_council = BoardMembership.objects.create(
title="Technical consultant", person=self.april, board=self.council, order=2
)
self.casey_council = BoardMembership.objects.create(
title="Sport utilities consultant",
person=self.casey,
board=self.council,
order=1,
)
self.leonardo_council = BoardMembership.objects.create(
title="Medical consultant",
person=self.leonardo,
board=self.council,
order=3,
)

@skip("Broken after the 2019 update")
def test_board(self):
response = self.app.get(reverse("board"))
self.assertTrue(self.board.name in response.text)
self.assertTrue(self.board.description in response.text)

self.assertTrue(self.council.name not in response.text)

self.assertTrue(self.splinter.name in response.text)
self.assertTrue(self.rat_board.title in response.text)
self.assertTrue(self.splinter.description in response.text)
self.assertTrue(self.splinter.email not in response.text)

self.assertTrue(self.casey.name not in response.text)
self.assertTrue(self.april.name not in response.text)

@skip("Broken after the 2019 update")
def test_advisory_council(self):
response = self.app.get(reverse("advisory-board"))
self.assertTrue(self.council.name in response.text)
self.assertTrue(self.council.description in response.text)

self.assertTrue(self.board.name not in response.text)

# April's name must be escaped because of the single quote in O'Neil
self.assertTrue(escape(self.april.name) in response.text)
self.assertTrue(self.april_council.title in response.text)
self.assertTrue(self.april.description in response.text)
self.assertTrue(self.april.email not in response.text)
self.assertTrue(self.april.twitter in response.text)
self.assertTrue(self.april.url in response.text)

self.assertTrue(self.casey.name in response.text)
self.assertTrue(self.casey_council.title in response.text)
self.assertTrue(self.casey.description in response.text)
self.assertTrue(self.casey.email not in response.text)
self.assertTrue(self.casey.twitter in response.text)

self.assertTrue(self.splinter.name not in response.text)

def test_manual_order_of_units(self):
response = self.app.get(reverse("advisory-board"))
april = response.text.find(escape(self.april.name))
leonardo = response.text.find(self.leonardo.name)
casey = response.text.find(self.casey.name)
self.assertTrue(leonardo < april < casey)


class NetworkGroupDetailViewTest(WebTest):
def setUp(self):
self.otto = Person.objects.create(
Expand Down
10 changes: 0 additions & 10 deletions foundation/organisation/urls/advisoryboard.py

This file was deleted.

7 changes: 0 additions & 7 deletions foundation/organisation/urls/board.py

This file was deleted.

12 changes: 1 addition & 11 deletions foundation/organisation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@
from iso3166 import countries
import csv

from .models import Board, NetworkGroup, NetworkGroupMembership, Person


class BoardView(DetailView):
model = Board
template_name = 'organisation/board_details.html'
board = None

def get_object(self, *args, **kwargs):
# Try to find the board based on the slug or 404
return get_object_or_404(Board, slug=self.board)
from .models import NetworkGroup, NetworkGroupMembership, Person


class NetworkGroupDetailView(DetailView):
Expand Down
4 changes: 0 additions & 4 deletions foundation/tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
re_path(r"^login/", lambda x: x, name="login"),
re_path(r"^search/", include("haystack.urls")),
re_path(r"^jobs/", include("foundation.jobs.urls")),
re_path(r"^about/board", include("foundation.organisation.urls.board")),
re_path(
r"^about/advisory-board", include("foundation.organisation.urls.advisoryboard")
),
re_path(r"^network/", include("foundation.organisation.urls.networkgroups")),
re_path(r"^", include("cms.urls")),
]

0 comments on commit 79c6960

Please sign in to comment.