From f03b4dfcbeec574669a363da8fe4a128760810b8 Mon Sep 17 00:00:00 2001 From: pdelboca Date: Tue, 11 Jun 2024 11:36:41 +0200 Subject: [PATCH 1/2] Remove old Network models --- foundation/organisation/admin.py | 20 +- foundation/organisation/cms_apps.py | 13 - ...networkgrouplist_cmsplugin_ptr_and_more.py | 34 +++ foundation/organisation/models.py | 127 --------- foundation/organisation/search_indexes.py | 15 +- .../templates/organisation/board_details.html | 22 -- .../templates/organisation/member.html | 42 --- .../templates/organisation/member_detail.html | 46 --- .../organisation/networkgroup_detail.html | 91 ------ .../templates/organisation/unit_list.html | 16 -- .../search/organisation/networkgroup.html | 47 --- .../organisation/tests/test_cms_plugins.py | 53 ---- foundation/organisation/tests/test_views.py | 268 ------------------ foundation/organisation/urls/__init__.py | 0 foundation/organisation/urls/networkgroups.py | 24 -- foundation/organisation/views.py | 72 +---- .../search/templates/search/results.html | 5 - 17 files changed, 37 insertions(+), 858 deletions(-) delete mode 100644 foundation/organisation/cms_apps.py create mode 100644 foundation/organisation/migrations/0026_remove_networkgrouplist_cmsplugin_ptr_and_more.py delete mode 100644 foundation/organisation/templates/organisation/board_details.html delete mode 100644 foundation/organisation/templates/organisation/member.html delete mode 100644 foundation/organisation/templates/organisation/member_detail.html delete mode 100644 foundation/organisation/templates/organisation/networkgroup_detail.html delete mode 100644 foundation/organisation/templates/organisation/unit_list.html delete mode 100644 foundation/organisation/templates/search/organisation/networkgroup.html delete mode 100644 foundation/organisation/tests/test_cms_plugins.py delete mode 100644 foundation/organisation/tests/test_views.py delete mode 100644 foundation/organisation/urls/__init__.py delete mode 100644 foundation/organisation/urls/networkgroups.py diff --git a/foundation/organisation/admin.py b/foundation/organisation/admin.py index 258e0b24..96c53725 100644 --- a/foundation/organisation/admin.py +++ b/foundation/organisation/admin.py @@ -2,10 +2,7 @@ from django.contrib import admin from .forms import PersonForm -from .models import ( - Person, NetworkGroup, - NetworkGroupMembership, SideBarExtension -) +from .models import Person, SideBarExtension from cms.extensions import PageExtensionAdmin @@ -20,21 +17,6 @@ class PersonAdmin(reversion.admin.VersionAdmin): admin.site.register(Person, PersonAdmin) -class NetworkGroupMembershipInline(admin.TabularInline): - model = NetworkGroupMembership - - -class NetworkGroupAdmin(reversion.admin.VersionAdmin): - list_display = ('name', 'country',) - ordering = ('country', 'name') - exclude = ('country_slug', 'region_slug') - - inlines = [NetworkGroupMembershipInline] - - -admin.site.register(NetworkGroup, NetworkGroupAdmin) - - class SideBarExtensionAdmin(PageExtensionAdmin): pass diff --git a/foundation/organisation/cms_apps.py b/foundation/organisation/cms_apps.py deleted file mode 100644 index 5092b495..00000000 --- a/foundation/organisation/cms_apps.py +++ /dev/null @@ -1,13 +0,0 @@ -from cms.app_base import CMSApp -from cms.apphook_pool import apphook_pool -from django.utils.translation import gettext_lazy as _ - - -class NetworkGroupsAppHook(CMSApp): - name = _("Network Groups") - - def get_urls(self, page=None, language=None, **kwargs): - return ["foundation.organisation.urls.networkgroups"] - - -apphook_pool.register(NetworkGroupsAppHook) diff --git a/foundation/organisation/migrations/0026_remove_networkgrouplist_cmsplugin_ptr_and_more.py b/foundation/organisation/migrations/0026_remove_networkgrouplist_cmsplugin_ptr_and_more.py new file mode 100644 index 00000000..1853d561 --- /dev/null +++ b/foundation/organisation/migrations/0026_remove_networkgrouplist_cmsplugin_ptr_and_more.py @@ -0,0 +1,34 @@ +# Generated by Django 4.2.3 on 2024-06-11 09:35 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('organisation', '0025_remove_boardmembership_board_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='networkgrouplist', + name='cmsplugin_ptr', + ), + migrations.RemoveField( + model_name='networkgroupmembership', + name='networkgroup', + ), + migrations.RemoveField( + model_name='networkgroupmembership', + name='person', + ), + migrations.DeleteModel( + name='NetworkGroup', + ), + migrations.DeleteModel( + name='NetworkGroupList', + ), + migrations.DeleteModel( + name='NetworkGroupMembership', + ), + ] diff --git a/foundation/organisation/models.py b/foundation/organisation/models.py index 172f0180..eaaefe6b 100644 --- a/foundation/organisation/models.py +++ b/foundation/organisation/models.py @@ -3,11 +3,7 @@ from cms.models.pluginmodel import CMSPlugin from cms.extensions import PageExtension -from django.urls import reverse -from django.urls.exceptions import NoReverseMatch from django.db import models -from django.utils.text import slugify -from django_countries.fields import CountryField logger = logging.getLogger(__name__) @@ -114,129 +110,6 @@ def __repr__(self): return "".format(self.person.name, self.doing_type) -class NetworkGroupManager(models.Manager): - def countries(self): - return self.get_queryset().filter(region_slug="") - - def regions(self, country): - return self.get_queryset().exclude(region_slug="").filter(country_slug=country) - - -class NetworkGroup(models.Model): - objects = NetworkGroupManager() - - GROUP_TYPES = ( - (0, "Local group"), - (1, "Chapter"), - (2, "Established group"), - (3, "Incubating group"), - (4, "Hibernated group"), - (5, "Affiliate"), - ) - - created_at = models.DateTimeField(auto_now_add=True) - updated_at = models.DateTimeField(auto_now=True) - - name = models.CharField(max_length=100) - - group_type = models.IntegerField(default=0, choices=GROUP_TYPES) - description = models.TextField(blank=True, null=True) - - country = CountryField() - country_slug = models.SlugField() - country_flag = models.ImageField( - upload_to="organisation/network/chapter", - blank=True - ) - - region = models.CharField(max_length=100, blank=True) - region_slug = models.SlugField(default=None) - - mailinglist_url = models.URLField(blank=True) - homepage_url = models.URLField(blank=True) - twitter = models.CharField(max_length=18, blank=True) - facebook_url = models.URLField(blank=True) - linkedin_url = models.URLField(blank=True) - mastodon_url = models.URLField(blank=True) - forum_group_url = models.URLField(blank=True) - - extra_information = models.TextField(blank=True, null=True) - - members = models.ManyToManyField("Person", through="NetworkGroupMembership") - - def __str__(self): - return self.name - - def save(self, *args, **kwargs): - if self.twitter and self.twitter.startswith("@"): - self.twitter = self.twitter[1:] - - # Slug is either the country slugified or the region - # Therefore we cannot force slug to be unique - # (regions might have same name in different countries) - self.country_slug = slugify(self.get_country_display()) - self.region_slug = slugify(self.region) - - super().save(*args, **kwargs) - - def get_absolute_url(self): - # Because reverse can't be smart about conditional parameters - # we have to have two different urls depending on if it is a - # country or a region group - if self.region: - try: - url = reverse( - "network-region", - kwargs={"country": self.country_slug, "region": self.region_slug}, - ) - except NoReverseMatch: - logger.error( - f"NetworkGroup.get_absolute_url ERROR: {self.region} :: {self.country}" - ) - url = "/" - else: - # Some countries are missing (?) - try: - url = reverse("network-country", kwargs={"country": self.country_slug}) - except NoReverseMatch: - logger.error(f"NetworkGroup.get_absolute_url ERROR: {self.country}") - url = "/" - - return url - - class Meta: - unique_together = ("country", "region") - ordering = ("country", "region") - - -class NetworkGroupMembership(models.Model): - created_at = models.DateTimeField(auto_now_add=True) - updated_at = models.DateTimeField(auto_now=True) - - title = models.CharField(max_length=100, blank=True) - order = models.IntegerField( - blank=True, - null=True, - help_text="The lower the number the higher on the" - " page this Person will be shown.", - ) - networkgroup = models.ForeignKey("NetworkGroup", on_delete=models.CASCADE) - person = models.ForeignKey("Person", on_delete=models.CASCADE) - - def __str__(self): - return self.person.name + " - " + self.networkgroup.name - - class Meta: - ordering = ["-order", "person__name"] - - -class NetworkGroupList(CMSPlugin): - group_type = models.IntegerField(default=0, choices=NetworkGroup.GROUP_TYPES) - - def __str__(self): - return self.get_group_type_display() - - class SignupForm(CMSPlugin): title = models.CharField(max_length=50, default="Get Connected to Open Knowledge") description = models.TextField(blank=True) diff --git a/foundation/organisation/search_indexes.py b/foundation/organisation/search_indexes.py index 4ea3815c..333011c3 100644 --- a/foundation/organisation/search_indexes.py +++ b/foundation/organisation/search_indexes.py @@ -1,5 +1,5 @@ from haystack import indexes -from .models import Person, NetworkGroup +from .models import Person class PersonIndex(indexes.SearchIndex, indexes.Indexable): @@ -12,16 +12,3 @@ def get_model(self): def get_updated_field(self): return 'updated_at' - - -class NetworkGroupIndex(indexes.SearchIndex, indexes.Indexable): - text = indexes.CharField(document=True, use_template=True) - twitter = indexes.CharField(model_attr='twitter') - homepage_url = indexes.CharField(model_attr='homepage_url') - mailinglist_url = indexes.CharField(model_attr='mailinglist_url') - - def get_model(self): - return NetworkGroup - - def get_updated_field(self): - return 'updated_at' diff --git a/foundation/organisation/templates/organisation/board_details.html b/foundation/organisation/templates/organisation/board_details.html deleted file mode 100644 index 47346a8a..00000000 --- a/foundation/organisation/templates/organisation/board_details.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends "cms_apphook.html" %} -{% load cms_tags %} - -{% block title %}{{ object.name }}{% endblock %} - -{% block custom_sidebar %} -

Members

- - {% static_placeholder object.placeholder %} -{% endblock %} - -{% block main %} - {% static_placeholder "board content" %} - - {% with skip_email=True %} - {% for member in object.boardmembership_set.all %} - {% include "organisation/member.html" %} - {% endfor %} - {% endwith %} -{% endblock %} diff --git a/foundation/organisation/templates/organisation/member.html b/foundation/organisation/templates/organisation/member.html deleted file mode 100644 index 47096db3..00000000 --- a/foundation/organisation/templates/organisation/member.html +++ /dev/null @@ -1,42 +0,0 @@ - -{% load markdown_deux_tags %} -{% load static %} - -{% with person=member.person %} -
-
-
-
- {{ person.name }} -
-
-

{{ person.name }}

-
- {{ member.title }} - {% if person.url %} - - - {{ person.url }} - - {% endif %} - {% if person.email %} - - - {{ person.email }} - - {% endif %} - {% if person.twitter %} - - - @{{ person.twitter }} - - {% endif %} -
-
-
-
- {{ person.description|markdown }} -
-
-
-{% endwith %} diff --git a/foundation/organisation/templates/organisation/member_detail.html b/foundation/organisation/templates/organisation/member_detail.html deleted file mode 100644 index af550b4e..00000000 --- a/foundation/organisation/templates/organisation/member_detail.html +++ /dev/null @@ -1,46 +0,0 @@ -{% extends 'cms_apphook.html' %} -{% load markdown_deux_tags %} -{% load static %} - -{% load i18n %} - -{% block main %} -

- {{ person.name }} -

-
-
-
-
- {{ person.name }} -
-
-
- {{ member.title }} - {% if person.url %} - - - {{ person.url }} - - {% endif %} - {% if person.email %} - - - {{ person.email }} - - {% endif %} - {% if person.twitter %} - - - {{ person.twitter }} - - {% endif %} -
-
-
-
- {{ person.description|markdown }} -
-
-
-{% endblock %} diff --git a/foundation/organisation/templates/organisation/networkgroup_detail.html b/foundation/organisation/templates/organisation/networkgroup_detail.html deleted file mode 100644 index 660e34cf..00000000 --- a/foundation/organisation/templates/organisation/networkgroup_detail.html +++ /dev/null @@ -1,91 +0,0 @@ -{% extends "cms_apphook.html" %} -{% load i18n %} -{% load markdown_deux_tags %} -{% load cms_tags %} -{% block title %}{{ object.name }}{% endblock %} - -{% block main %} - -{% static_placeholder "Network Group Header" %} - -
-
-
-
-
- {% if object.country_flag %} - {{ object.country.name }} Flag - {% endif %} -
-
-
-

- {{ object.name }} -

-
-
-
-
- - -
-
-

{{ object.description }}

-
-
- -
- {% if object.homepage_url %} - - Website - - {% endif %} - {% if object.forum_group_url %} - - Forum - - {% endif %} - {% if object.mastodon_url %} - - Mastodon - - {% endif %} - {% if object.linkedin_url %} - - Linkedin - - {% endif %} - - {% if object.twitter %} - - Twitter - - {% endif %} - {% if object.facebook_url %} - - Facebook - - {% endif %} -
- - -

Core Team

- {% for member in group_members %} - {% include "organisation/member.html" %} - {% endfor %} - - - {% if object.extra_information %} -
-

More Information

- -
- {{ object.extra_information|markdown }} -
-
- {% endif %} - - -{% static_placeholder "Network Group Footer" %} - -{% endblock %} diff --git a/foundation/organisation/templates/organisation/unit_list.html b/foundation/organisation/templates/organisation/unit_list.html deleted file mode 100644 index 0ca2e487..00000000 --- a/foundation/organisation/templates/organisation/unit_list.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends "cms_apphook.html" %} - -{% load i18n %} -{% load cms_tags %} -{% load markdown_deux_tags %} - -{% block main %} - -{% static_placeholder "unit content" %} - {% for unit in unit_list %} -

{{ unit.name }}

- {% for member in unit.unitmembership_set.all %} - {% include "organisation/member.html" %} - {% endfor %} - {% endfor %} -{% endblock %} diff --git a/foundation/organisation/templates/search/organisation/networkgroup.html b/foundation/organisation/templates/search/organisation/networkgroup.html deleted file mode 100644 index 94f3b638..00000000 --- a/foundation/organisation/templates/search/organisation/networkgroup.html +++ /dev/null @@ -1,47 +0,0 @@ -{% load markdown_deux_tags %} -{% load static %} - - -

- {{networkgroup.get_group_type_display }}: {{ networkgroup.name }} -

-
- -

{{ networkgroup.description|markdown|truncatewords_html:50 }}

- - - - diff --git a/foundation/organisation/tests/test_cms_plugins.py b/foundation/organisation/tests/test_cms_plugins.py deleted file mode 100644 index bf9a9693..00000000 --- a/foundation/organisation/tests/test_cms_plugins.py +++ /dev/null @@ -1,53 +0,0 @@ -from cms.test_utils.testcases import CMSTestCase - -from ..models import (NetworkGroup, - NetworkGroupList) - - -class NetworkGroupPluginTest(CMSTestCase): - - def setUp(self): - super().setUp() - - self.britain = NetworkGroup.objects.create( - name='Open Knowledge Foundation Britain', - group_type=0, # local group - description='Bisquits, tea, and open data', - country='GB', - mailinglist_url='http://lists.okfn.org/okfn-britain', - homepage_url='http://gb.okfn.org/', - twitter='OKFNgb' - ) - - self.buckingham = NetworkGroup.objects.create( - name='Open Knowledge Buckingham', - group_type=0, # local group - description='We run the Open Palace project', - country='GB', - region='Buckingham', - homepage_url='http://queen.okfn.org/', - twitter='buckingham', - facebook_url='http://facebook.com/queenthepersonnottheband', - ) - - self.germany = NetworkGroup.objects.create( - name='Open Knowledge Foundation Germany', - group_type=1, # chapter - description='Haben Sie ein Kugelschreiber bitte?', - country='DE', - mailinglist_url='http://lists.okfn.org/okfn-de', - homepage_url='http://de.okfn.org/', - twitter='OKFNde' - ) - - self.switzerland = NetworkGroup.objects.create( - name='Open Knowledge Foundation Switzerland', - group_type=1, # chapter - description='Switzerland loves open data', - country='CH', - mailinglist_url='http://lists.okfn.org/okfn-ch', - homepage_url='http://opendata.ch', - ) - - self.localgroups = NetworkGroupList(group_type=0) - self.chapters = NetworkGroupList(group_type=1) diff --git a/foundation/organisation/tests/test_views.py b/foundation/organisation/tests/test_views.py deleted file mode 100644 index c1f5a07a..00000000 --- a/foundation/organisation/tests/test_views.py +++ /dev/null @@ -1,268 +0,0 @@ -from io import StringIO - -from django.urls import reverse -from django_webtest import WebTest - -from iso3166 import countries -import csv - -from ..models import ( - Person, - NetworkGroup, - NetworkGroupMembership, - NowDoing, -) - - -class NetworkGroupDetailViewTest(WebTest): - def setUp(self): - self.otto = Person.objects.create( - name="Otto von Bismarck", - description="The oldest member and Duke of Lauenburg", - email="bismarck@bismarck.org", - twitter="busymark", - url="http://betterthanwinston.de", - ) - - self.winston = Person.objects.create( - name="Sir Winston Churchill", - description="Grandson of the 7th Duke of Marlborough", - email="winston@okfn.org", - twitter="ftw_stn", - url="http://forthewinston.org", - ) - - self.elizabeth = Person.objects.create( - name="Elizabeth Angela Marguerite Bowes-Lyon", - description="I am no duke, I am the queen", - email="queen@monarch.me", - twitter="thequeen", - url="http://monarch.me/", - ) - - self.britain = NetworkGroup.objects.create( - name="Open Knowledge Foundation Britain", - group_type=0, # local group - description="Bisquits, tea, and open data", - country="GB", - mailinglist_url="http://lists.okfn.org/okfn-britain", - homepage_url="http://gb.okfn.org/", - twitter="OKFNgb", - ) - - self.buckingham = NetworkGroup.objects.create( - name="Open Knowledge Buckingham", - group_type=0, # local group - description="We run the Open Palace project", - country="GB", - region="Buckingham", - homepage_url="http://queen.okfn.org/", - twitter="buckingham", - facebook_url="http://facebook.com/queenthepersonnottheband", - ) - - self.germany = NetworkGroup.objects.create( - name="Open Knowledge Foundation Germany", - group_type=1, # chapter - description="Haben Sie ein Kugelschreiber bitte?", - country="DE", - mailinglist_url="http://lists.okfn.org/okfn-de", - homepage_url="http://de.okfn.org/", - twitter="OKFNde", - ) - - self.otto_germany = NetworkGroupMembership.objects.create( - networkgroup=self.germany, person=self.otto, title="First chancellor" - ) - - self.winston_britain = NetworkGroupMembership.objects.create( - networkgroup=self.britain, - person=self.winston, - title="Prime minister with intervals", - ) - - self.elizabeth_britain = NetworkGroupMembership.objects.create( - networkgroup=self.buckingham, person=self.elizabeth, title="Regent maker" - ) - - def test_country_group(self): - response = self.app.get( - reverse("network-country", kwargs={"country": self.britain.country_slug}) - ) - - self.assertIn(self.britain.name, response.text) - # TODO test skipped until we define if "britain" must be - # included here - # self.assertIn(self.britain.get_group_type_display().lower(), - # response.text.lower()) - # self.assertIn(self.britain.description, response.text) - # self.assertIn(self.britain.get_country_display(), response.text) - # self.assertIn(self.britain.homepage_url, response.text) - # self.assertIn(self.britain.mailinglist_url, response.text) - # self.assertIn(self.britain.twitter, response.text) - - self.assertNotIn( - self.germany.get_group_type_display().lower(), response.text.lower() - ) - - self.assertIn(self.winston.name, response.text) - self.assertIn(self.winston_britain.title, response.text) - self.assertIn(self.elizabeth.name, response.text) - self.assertIn(self.elizabeth_britain.title, response.text) - self.assertNotIn(self.otto.name, response.text) - - # TODO test skipped until we define if "buckingham" must be - # included here - # self.assertIn(self.buckingham.name, response.text) - # self.assertNotIn(self.buckingham.description, response.text) - self.assertNotIn(self.germany.name, response.text) - - def test_regional_group(self): - response = self.app.get( - reverse( - "network-region", - kwargs={ - "country": self.buckingham.country_slug, - "region": self.buckingham.region_slug, - }, - ) - ) - - self.assertIn(self.buckingham.name, response.text) - - # TODO test skipped until we define if "buckingham" must be - # included here - # self.assertIn(self.buckingham.description, response.text) - # self.assertIn(self.buckingham.get_country_display(), response.text) - # self.assertIn(self.buckingham.region, response.text) - # self.assertIn(self.buckingham.homepage_url, response.text) - # self.assertIn(self.buckingham.twitter, response.text) - # self.assertIn(self.buckingham.facebook_url, response.text) - # self.assertIn( - # reverse( - # 'network-country', - # kwargs={'country': self.buckingham.country_slug} - # ), - # response.text - # ) - self.assertNotIn(self.britain.homepage_url, response.text) - self.assertNotIn(self.britain.mailinglist_url, response.text) - self.assertNotIn(self.britain.twitter, response.text) - - self.assertIn(self.elizabeth.name, response.text) - self.assertIn(self.elizabeth_britain.title, response.text) - self.assertNotIn(self.winston.name, response.text) - self.assertNotIn(self.otto.name, response.text) - - self.assertNotIn(self.britain.description, response.text) - self.assertNotIn(self.germany.name, response.text) - - def test_csv_output(self): - response = self.app.get(reverse("networkgroups-csv")) - reader = csv.reader(StringIO(response.text)) - - header_row = next(reader) - - # Headers need to be on a specific form - headers = [ - "ISO3", - "Country", - "Map location", - "Local Groups status", - "Community Leaders", - "Website", - "Mailing List", - "Twitter handle", - "Facebook page", - ] - - self.assertEqual(header_row, headers) - - germany = next(reader) - germany_data = [ - countries.get(self.germany.country.code).alpha3, - self.germany.get_country_display(), - "", - self.germany.get_group_type_display(), - ", ".join([m.name for m in self.germany.members.all()]), - self.germany.homepage_url, - self.germany.mailinglist_url, - self.germany.twitter, - "", - ] - self.assertEqual(germany, germany_data) - - britain = next(reader) - britain_data = [ - countries.get(self.britain.country.code).alpha3, - self.britain.get_country_display(), - "", - self.britain.get_group_type_display(), - ", ".join([m.name for m in self.britain.members.all()]), - self.britain.homepage_url, - self.britain.mailinglist_url, - self.britain.twitter, - "", - ] - self.assertEqual(britain, britain_data) - - buckingham = next(reader) - buckingham_data = [ - countries.get(self.buckingham.country.code).alpha3, - self.buckingham.get_country_display(), - "{region}, {country}".format( - region=self.buckingham.region, - country=self.buckingham.get_country_display(), - ), - self.buckingham.get_group_type_display(), - ", ".join([m.name for m in self.buckingham.members.all()]), - self.buckingham.homepage_url, - self.buckingham.mailinglist_url, - self.buckingham.twitter, - self.buckingham.facebook_url, - ] - self.assertEqual(buckingham, buckingham_data) - - def test_NowDoing_icon_name_works(self, *args): # noqa - donatello = Person.objects.create( - name="Donatello (Donnie)", - username_on_slack="donnie", - description="Turtle with a purple mask", - email="donatello@tmnt.org", - ) - donatello.save() - - watching = NowDoing.objects.create( - person=donatello, doing_type="watching", text="a movie" - ) - watching.save() - - location = NowDoing.objects.create( - person=donatello, doing_type="location", text="Berlin" - ) - watching.save() - - self.assertEqual(watching.icon_name, "playing") - self.assertEqual(location.icon_name, "location") - - def test_NowDoing_display_name(self, *args): # noqa - donatello = Person.objects.create( - name="Donatello (Donnie)", - username_on_slack="donnie", - description="Turtle with a purple mask", - email="donatello@tmnt.org", - ) - donatello.save() - - watching = NowDoing.objects.create( - person=donatello, doing_type="watching", text="a movie" - ) - watching.save() - - listening = NowDoing.objects.create( - person=donatello, doing_type="listening", text="The beatles" - ) - watching.save() - - self.assertEqual(listening.display_name, "Listening to") - self.assertEqual(watching.display_name, "Watching") diff --git a/foundation/organisation/urls/__init__.py b/foundation/organisation/urls/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/foundation/organisation/urls/networkgroups.py b/foundation/organisation/urls/networkgroups.py deleted file mode 100644 index 6d0cce8e..00000000 --- a/foundation/organisation/urls/networkgroups.py +++ /dev/null @@ -1,24 +0,0 @@ -from django.urls import re_path -from django.utils.text import slugify - -from django_countries import countries -from ..views import NetworkGroupDetailView, networkgroup_csv_output - - -# Generate countries list for the regular expression (it shouldn't be greedy) -COUNTRY_SLUGS = '|'.join([slugify(str(name)) for code, name in countries]) - - -urlpatterns = [ - re_path( - r'^(?P' + COUNTRY_SLUGS + r')/$', - NetworkGroupDetailView.as_view(), - name='network-country' - ), - re_path( - r'^(?P' + COUNTRY_SLUGS + r')/(?P[^/]+)/$', - NetworkGroupDetailView.as_view(), - name='network-region' - ), - re_path(r'^csv$', networkgroup_csv_output, name='networkgroups-csv'), -] diff --git a/foundation/organisation/views.py b/foundation/organisation/views.py index 1c185d9a..b68ab88e 100644 --- a/foundation/organisation/views.py +++ b/foundation/organisation/views.py @@ -1,77 +1,7 @@ -from django.views.decorators.cache import cache_page from django.views.generic.detail import DetailView from django.shortcuts import get_object_or_404 -from django.http import HttpResponse -from iso3166 import countries -import csv - -from .models import NetworkGroup, NetworkGroupMembership, Person - - -class NetworkGroupDetailView(DetailView): - model = NetworkGroup - - def get_object(self): - country = self.kwargs.get('country', '') - region = self.kwargs.get('region', '') - return get_object_or_404(NetworkGroup, - country_slug=country, - region_slug=region) - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - - # For country we want all members but only regional members for regions - country = self.kwargs.get('country', None) - region = self.kwargs.get('region', None) - if region is None: - context['regional_groups'] = NetworkGroup.objects.regions(country) - members = NetworkGroupMembership.objects.filter( - networkgroup__country_slug=country) - else: - members = NetworkGroupMembership.objects.filter( - networkgroup__country_slug=country, - networkgroup__region_slug=region) - - context['group_members'] = members.order_by('order', 'person__name') - return context - - -@cache_page(60 * 30) -def networkgroup_csv_output(request): - response = HttpResponse(content_type='text/csv; charset=utf-8') - response['Content-Disposition'] = 'attachment; filename="network.csv"' - - writer = csv.writer(response) - header_row = ['ISO3', 'Country', 'Map location', - 'Local Groups status', 'Community Leaders', 'Website', - 'Mailing List', 'Twitter handle', 'Facebook page'] - - writer.writerow(header_row) - - for group in NetworkGroup.objects.all(): - if not countries.get(group.country.code, None): - code = '' - else: - code = countries.get(group.country.code).alpha3 - row = [code, # ISO3 - group.get_country_display(), # Country - '{region}, {country}'.format( - region=group.region, - country=group.get_country_display() - ) if group.region else '', # Map location - group.get_group_type_display(), # Local group status - ', '.join([member.name - for member in group.members.all()]), # Leaders - group.homepage_url, # Website - group.mailinglist_url, - group.twitter if group.twitter else '', - group.facebook_url] - - writer.writerow(row) - - return response +from .models import Person class PersonView(DetailView): diff --git a/foundation/search/templates/search/results.html b/foundation/search/templates/search/results.html index 05fc062e..3c7c2e61 100644 --- a/foundation/search/templates/search/results.html +++ b/foundation/search/templates/search/results.html @@ -4,11 +4,6 @@ {% include "search/cms/page.html" %} {% endwith %} {% endif %} -{% if search_result.content_type == 'organisation.networkgroup' %} - {% with networkgroup=search_result.object %} - {% include "search/organisation/networkgroup.html" %} - {% endwith %} -{% endif %} {% if search_result.content_type == 'jobs.job' %} {% with job=search_result.object %} {% include "search/jobs/job.html" %} From 976df0fa3bafddf59f3eec4b05072de25e7bff85 Mon Sep 17 00:00:00 2001 From: pdelboca Date: Tue, 11 Jun 2024 11:42:42 +0200 Subject: [PATCH 2/2] Remove network url from tests --- foundation/tests/urls.py | 1 - 1 file changed, 1 deletion(-) diff --git a/foundation/tests/urls.py b/foundation/tests/urls.py index 3ca1248a..d94ccf2c 100644 --- a/foundation/tests/urls.py +++ b/foundation/tests/urls.py @@ -7,6 +7,5 @@ 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"^network/", include("foundation.organisation.urls.networkgroups")), re_path(r"^", include("cms.urls")), ]