Skip to content

Commit

Permalink
Merge pull request #1097 from okfn/develop
Browse files Browse the repository at this point in the history
[PROD] Remove old Unit/UnitMembership structure
  • Loading branch information
pdelboca authored Jun 11, 2024
2 parents 033ee8c + 80df3a4 commit 60c8d4d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 234 deletions.
17 changes: 1 addition & 16 deletions foundation/organisation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from django.contrib import admin
from .forms import PersonForm
from .models import (
Person, Unit, Board,
NetworkGroup, UnitMembership,
Person, Board, NetworkGroup,
BoardMembership, NetworkGroupMembership, SideBarExtension
)

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


class UnitMembershipInline(admin.TabularInline):
model = UnitMembership


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

inlines = [UnitMembershipInline]


admin.site.register(Unit, UnitAdmin)


class BoardMembershipInline(admin.TabularInline):
model = BoardMembership

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


class UnitsAppHook(CMSApp):
name = _("Units")

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


apphook_pool.register(UnitsAppHook)


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

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 07:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('organisation', '0023_sidebarextension_image'),
]

operations = [
migrations.RemoveField(
model_name='unitmembership',
name='person',
),
migrations.RemoveField(
model_name='unitmembership',
name='unit',
),
migrations.DeleteModel(
name='Unit',
),
migrations.DeleteModel(
name='UnitMembership',
),
]
35 changes: 0 additions & 35 deletions foundation/organisation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,41 +114,6 @@ def __repr__(self):
return "<NowDoing: {}, {}>".format(self.person.name, self.doing_type)


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

name = models.CharField(max_length=100)
members = models.ManyToManyField("Person", through="UnitMembership")
order = models.IntegerField(
blank=True, null=True, help_text="Higher numbers mean higher up in the list"
)

def __str__(self):
return self.name

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


class UnitMembership(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)
unit = models.ForeignKey("Unit", 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 Board(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
Expand Down
157 changes: 0 additions & 157 deletions foundation/organisation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,170 +11,13 @@
from ..models import (
Board,
Person,
Unit,
NetworkGroup,
NetworkGroupMembership,
BoardMembership,
UnitMembership,
NowDoing,
)


class UnitListViewTest(WebTest):
def setUp(self):
self.donatello = Person.objects.create(
name="Donatello (Donnie)",
description="Turtle with a purple mask",
email="[email protected]",
)
self.leonardo = Person.objects.create(
name="Leonardo (Leo)",
description="Turtle with a blue mask",
email="[email protected]",
)
self.raphael = Person.objects.create(
name="Raphael (Raph)",
description="Turtle with a red mask",
email="[email protected]",
twitter="raph",
url="http://tmnt.org/raphael",
)
self.rocksteady = Person.objects.create(
name="Rocksteady",
description="Mutant rhinoceros",
email="[email protected]",
twitter="rocksteady",
url="http://beboprocksteady.com",
)
self.april = Person.objects.create(
name="April O'Neil",
description="Computer Programmer",
email="[email protected]",
twitter="april",
url="http://oneil.me",
)
self.splinter = Person.objects.create(
name="Splinter", description="Ninja rat", email="[email protected]"
)

self.turtles = Unit.objects.create(name="Turtles")
self.footclan = Unit.objects.create(name="Foot Clan")
self.masters = Unit.objects.create(name="Ninja Masters", order=1)

self.turtle_donatello = UnitMembership.objects.create(
title="Hacker", person=self.donatello, unit=self.turtles
)

self.turtle_leonardo = UnitMembership.objects.create(
title="Leader", person=self.leonardo, unit=self.turtles, order=1
)

self.turtle_raphael = UnitMembership.objects.create(
title="Bad boy", person=self.raphael, unit=self.turtles
)

self.evil_rocksteady = UnitMembership.objects.create(
title="Comic relief", person=self.rocksteady, unit=self.footclan
)

self.master_splinter = UnitMembership.objects.create(
title="Master", person=self.splinter, unit=self.masters
)

def test_units_in_response(self):
response = self.app.get(reverse("units"))
self.assertTrue(self.turtles.name in response)
self.assertTrue(self.footclan.name in response)

def test_unit_member_in_response(self):
response = self.app.get(reverse("units"))
self.assertTrue(self.leonardo.name in response)
self.assertTrue(self.raphael.name in response)
self.assertTrue(self.rocksteady.name in response)

def test_non_unit_member_not_in_response(self):
response = self.app.get(reverse("units"))
self.assertTrue(self.april.name not in response)

def test_unit_members_in_units(self):
response = self.app.get(reverse("units"))

# Units are ordered alphabetically
footclan = response.text.find(self.footclan.name)
turtles = response.text.find(self.turtles.name)
self.assertTrue(footclan < turtles)

# Unit members are ordered alphabetically
# unless order is overwritten
donatello = response.text.find(self.donatello.name)
leonardo = response.text.find(self.leonardo.name)
raphael = response.text.find(self.raphael.name)
rocksteady = response.text.find(self.rocksteady.name)
self.assertTrue(footclan < rocksteady < turtles)
self.assertTrue(turtles < leonardo < donatello < raphael)

def test_description_in_response(self):
response = self.app.get(reverse("units"))
self.assertTrue(self.leonardo.description in response)
self.assertTrue(self.raphael.description in response)
self.assertTrue(self.rocksteady.description in response)
self.assertTrue(self.april.description not in response)

def test_email_in_response(self):
response = self.app.get(reverse("units"))
self.assertTrue(self.leonardo.email in response)
self.assertTrue(self.raphael.email in response)
self.assertTrue(self.rocksteady.email in response)
self.assertTrue(self.april.email not in response)

def test_twitter_in_response(self):
response = self.app.get(reverse("units"))
twitter_url = "https://twitter.com/{handle}"
twitter_raphael = twitter_url.format(handle=self.raphael.twitter)
twitter_rocksteady = twitter_url.format(handle=self.rocksteady.twitter)
twitter_april = twitter_url.format(handle=self.april.twitter)
self.assertTrue(twitter_raphael in response)
self.assertTrue(twitter_rocksteady in response)
self.assertTrue(twitter_april not in response)

# Raphael is the last turtle. We assume that the unit list will be
# where the first occurance of the names come up (since main content
# should come before sidebars).
# Leonardo doesn't use Twitter so there shouldn't be a twitter url
# between the last Leo's name and Raph's name
leonardo = response.text.find(self.leonardo.name)
raphael = response.text.find(self.raphael.name)
twitter = response.text.find("https://twitter.com/", leonardo, raphael)
self.assertTrue(twitter == -1)

@skip("Broken after the 2019 update")
def test_url_in_response(self):
response = self.app.get(reverse("units"))

self.assertTrue(self.raphael.url in response)
self.assertTrue(self.rocksteady.url in response)
self.assertTrue(self.april.url not in response)

# Raphael is the last turtle. We assume that the unit list will be
# where the first occurance of the names come up (since main content
# should come before sidebars).
# Leonardo doesn't have a website so there shouldn't be a
# 'Personal website' between the last Leo's name and Raph's name

leonardo = response.text.find(self.leonardo.name)
raphael = response.text.find(self.raphael.name)
website = response.text.find("Personal website", leonardo, raphael)
self.assertTrue(website == -1)

def test_manual_order_of_units(self):
response = self.app.get(reverse("units"))
masters = response.text.find(self.masters.name)
turtles = response.text.find(self.turtles.name)
footclan = response.text.find(self.footclan.name)

self.assertTrue(masters < footclan < turtles)


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

This file was deleted.

5 changes: 0 additions & 5 deletions foundation/search/templates/search/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
{% include "search/cms/page.html" %}
{% endwith %}
{% endif %}
{% if search_result.content_type == 'organisation.person' %}
{% with person=search_result.object %}
{% include "search/organisation/person.html" %}
{% endwith %}
{% endif %}
{% if search_result.content_type == 'organisation.networkgroup' %}
{% with networkgroup=search_result.object %}
{% include "search/organisation/networkgroup.html" %}
Expand Down
1 change: 0 additions & 1 deletion foundation/tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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/team", include("foundation.organisation.urls.units")),
re_path(r"^about/board", include("foundation.organisation.urls.board")),
re_path(
r"^about/advisory-board", include("foundation.organisation.urls.advisoryboard")
Expand Down

0 comments on commit 60c8d4d

Please sign in to comment.