diff --git a/foundation/organisation/admin.py b/foundation/organisation/admin.py index 96c53725..f49ab6d4 100644 --- a/foundation/organisation/admin.py +++ b/foundation/organisation/admin.py @@ -1,22 +1,9 @@ -import reversion - from django.contrib import admin -from .forms import PersonForm -from .models import Person, SideBarExtension +from .models import SideBarExtension from cms.extensions import PageExtensionAdmin -class PersonAdmin(reversion.admin.VersionAdmin): - list_display = ('name', 'email', 'twitter', 'username_on_slack') - ordering = ('name',) - search_fields = ('name', 'email') - form = PersonForm - - -admin.site.register(Person, PersonAdmin) - - class SideBarExtensionAdmin(PageExtensionAdmin): pass diff --git a/foundation/organisation/forms.py b/foundation/organisation/forms.py deleted file mode 100644 index 9f67f394..00000000 --- a/foundation/organisation/forms.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.forms import ModelForm -from foundation.core.svg import SvgAndImageFormField - - -class PersonForm(ModelForm): - photo = SvgAndImageFormField() diff --git a/foundation/organisation/migrations/0027_delete_nowdoing_delete_person.py b/foundation/organisation/migrations/0027_delete_nowdoing_delete_person.py new file mode 100644 index 00000000..21f5bc0e --- /dev/null +++ b/foundation/organisation/migrations/0027_delete_nowdoing_delete_person.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.3 on 2024-06-11 12:24 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('organisation', '0026_remove_networkgrouplist_cmsplugin_ptr_and_more'), + ] + + operations = [ + migrations.DeleteModel( + name='NowDoing', + ), + migrations.DeleteModel( + name='Person', + ), + ] diff --git a/foundation/organisation/models.py b/foundation/organisation/models.py index eaaefe6b..1e618291 100644 --- a/foundation/organisation/models.py +++ b/foundation/organisation/models.py @@ -1,115 +1,12 @@ import logging -from hashlib import md5 from cms.models.pluginmodel import CMSPlugin from cms.extensions import PageExtension from django.db import models - logger = logging.getLogger(__name__) -class Person(models.Model): - created_at = models.DateTimeField(auto_now_add=True) - updated_at = models.DateTimeField(auto_now=True) - - name = models.CharField(max_length=100) - username_on_slack = models.CharField(max_length=100, blank=True, null=True) - description = models.TextField(blank=True, null=True) - email = models.EmailField(blank=True) - photo = models.ImageField(upload_to="organisation/people/photos", blank=True) - twitter = models.CharField(max_length=18, blank=True) - url = models.URLField(blank=True) - - NOWDOING_DEFAULT_ORDER = ( - "working", - "location", - "reading", - "listening", - "watching", - "eating", - ) - - def __str__(self): - return self.name - - @property - def gravatar_url(self): - """Returns the gravatar url for this user (constructed from email)""" - base = "https://gravatar.com/avatar/{hash}?s=132" - md5_hash = md5(self.email.strip().lower().encode("utf-8")).hexdigest() - return base.format(hash=md5_hash) - - @property - def nowdoing_with_latest(self): - """All NowDoing attributes of the user with the most recently - updated one marked with `is_newest_update`""" - nowdoings = self.nowdoing_set.all().extra(order_by=["-updated_at"]) - if nowdoings: - nowdoings[0].is_newest_update = True - return nowdoings - - @property - def nowdoing_by_custom_order(self, custom_order=None): - custom_order = custom_order or self.NOWDOING_DEFAULT_ORDER - nowdoings = self.nowdoing_with_latest - ordered_nowdoings = list() - for doing_type in custom_order: - if nowdoings.filter(doing_type=doing_type): - ordered_nowdoings.append( - nowdoings.filter(doing_type=doing_type).first() - ) - return ordered_nowdoings - - @property - def has_anything_to_show(self): - """Is there anything that we can show for this person in the - template (other then email which is checked separately)""" - return self.url or self.twitter or self.nowdoing_set.count() - - class Meta: - ordering = ["name"] - verbose_name_plural = "people" - - -class NowDoing(models.Model): - ACTIVITIES = ( - ("reading", "reading"), - ("listening", "listening"), - ("working", "working"), - ("location", "location"), - ("watching", "watching"), - ("eating", "eating"), - ) - person = models.ForeignKey(Person, on_delete=models.CASCADE) - doing_type = models.CharField(max_length=10, choices=ACTIVITIES) - link = models.URLField(blank=True, null=True) - text = models.TextField(blank=True, null=True) - updated_at = models.DateTimeField(auto_now=True) - - @property - def icon_name(self): - """The name of the corresponding css icon class""" - matching = {"watching": "playing"} - return matching.get(self.doing_type, self.doing_type) - - @property - def display_name(self): - """The human readable string to be displayed in templates""" - matching = { - "reading": "Reading", - "listening": "Listening to", - "working": "Working on", - "location": "Location", - "watching": "Watching", - "eating": "Eating", - } - return matching.get(self.doing_type, self.doing_type) - - def __repr__(self): - return "".format(self.person.name, self.doing_type) - - 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 deleted file mode 100644 index 333011c3..00000000 --- a/foundation/organisation/search_indexes.py +++ /dev/null @@ -1,14 +0,0 @@ -from haystack import indexes -from .models import Person - - -class PersonIndex(indexes.SearchIndex, indexes.Indexable): - text = indexes.CharField(document=True, use_template=True) - twitter = indexes.CharField(model_attr='twitter') - url = indexes.CharField(model_attr='url') - - def get_model(self): - return Person - - def get_updated_field(self): - return 'updated_at' diff --git a/foundation/organisation/templates/search/indexes/organisation/networkgroup_text.txt b/foundation/organisation/templates/search/indexes/organisation/networkgroup_text.txt deleted file mode 100644 index c1ef14c9..00000000 --- a/foundation/organisation/templates/search/indexes/organisation/networkgroup_text.txt +++ /dev/null @@ -1,13 +0,0 @@ -{{ object.name }} -{{ object.description }} -{{ object.get_group_type_display }} -{{ object.get_country_display }} -{% if object.region %} -{{ object.region }} -{% endif %} -{{ object.extra_information }} -{% for group in object.working_group.all %} -{{ group.name }} -{{ group.description }} -{% endfor %} - diff --git a/foundation/organisation/templates/search/indexes/organisation/person_text.txt b/foundation/organisation/templates/search/indexes/organisation/person_text.txt deleted file mode 100644 index 833aebfd..00000000 --- a/foundation/organisation/templates/search/indexes/organisation/person_text.txt +++ /dev/null @@ -1,12 +0,0 @@ -{{ object.name }} -{% for member in object.unitmembership_set.all %} -{{ member.title }} -{{ member.unit.name }} -{% endfor %} -{% for member in object.boardmembership_set.all %} -{{ member.title }} -{{ member.board.name }} -{% endfor %} -{{ object.description }} -{{ object.twitter }} -{{ object.url }} diff --git a/foundation/organisation/templates/search/indexes/organisation/project_text.txt b/foundation/organisation/templates/search/indexes/organisation/project_text.txt deleted file mode 100644 index eba4d80f..00000000 --- a/foundation/organisation/templates/search/indexes/organisation/project_text.txt +++ /dev/null @@ -1,9 +0,0 @@ -{{ object.name }} -{{ object.description }} -{{ object.twitter }} -{{ object.homepage_url }} -{{ object.forum_url }} -{{ object.sourcecode_url }} -{% for type in object.types.all %} -{{ type.name }} -{% endfor %} diff --git a/foundation/organisation/templates/search/organisation/person.html b/foundation/organisation/templates/search/organisation/person.html deleted file mode 100644 index 1d6dc981..00000000 --- a/foundation/organisation/templates/search/organisation/person.html +++ /dev/null @@ -1,28 +0,0 @@ -{% load markdown_deux_tags %} -{% load thumbnail %} -{% load static %} - - -

{{ person.name }}

-
- -{% for membership in person.unitmembership_set.all %} - - {{ membership.unit.name }} {% if membership.title %} ({{ membership.title }}) {% endif %} - -{% endfor %} - -{% for membership in person.boardmembership_set.all %} - - {{ membership.board.name }} {% if membership.title %} ({{ membership.title }}) {% endif %} - -{% endfor %} - -{% for membership in person.networkgroupmembership_set.all %} - - {{ membership.networkgroup.name }} {% if membership.title %} ({{ membership.title }}) {% endif %} - -{% endfor %} - -

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

- \ No newline at end of file diff --git a/foundation/organisation/tests/__init__.py b/foundation/organisation/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/foundation/organisation/tests/test_admin.py b/foundation/organisation/tests/test_admin.py deleted file mode 100644 index fdddd233..00000000 --- a/foundation/organisation/tests/test_admin.py +++ /dev/null @@ -1 +0,0 @@ -from .. import admin # noqa diff --git a/foundation/organisation/tests/test_api.py b/foundation/organisation/tests/test_api.py deleted file mode 100644 index 79852a13..00000000 --- a/foundation/organisation/tests/test_api.py +++ /dev/null @@ -1,22 +0,0 @@ -from unittest import TestCase - -from ..utils import get_activity - - -class HelpersTest(TestCase): - def test_get_activity_extracts_type(self): - text = '#reading http://goodreads.com/123' - self.assertEqual(get_activity(text), 'reading') - - text2 = '#watching http://goodreads.com/123' - self.assertEqual(get_activity(text2), 'watching') - - text3 = '#eating http://goodreads.com/123' - self.assertEqual(get_activity(text3), 'eating') - - text4 = '#working http://goodreads.com/123' - self.assertEqual(get_activity(text4), 'working') - - def test_get_activity_returns_none_when_no_match(self): - text = '#foobaring http://goodreads.com/123' - self.assertEqual(get_activity(text), None) diff --git a/foundation/organisation/tests/test_search_indexes.py b/foundation/organisation/tests/test_search_indexes.py deleted file mode 100644 index bd6523df..00000000 --- a/foundation/organisation/tests/test_search_indexes.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.test import TestCase - -from ..models import Person -from ..search_indexes import PersonIndex - - -class PersonIndexTest(TestCase): - def setUp(self): - self.leonardo = Person.objects.create( - name="Leonardo (Leo)", - description='Turtle with a blue mask', - email='leonardo@tmnt.org') - - def test_queryset_includes_person(self): - index = PersonIndex() - - self.assertIn(self.leonardo, index.index_queryset()) diff --git a/foundation/organisation/utils.py b/foundation/organisation/utils.py deleted file mode 100644 index 41da0cb8..00000000 --- a/foundation/organisation/utils.py +++ /dev/null @@ -1,21 +0,0 @@ -import re - -from django.http import JsonResponse - -from foundation.organisation.models import NowDoing - - -def get_activity(text): - options = '|'.join([a[0] for a in NowDoing.ACTIVITIES]) - pattern = '^#({}).*'.format(options) - matches = re.findall(pattern, text) - if matches: - return matches[0] - return None - - -def fail_json(message, status_code=400): - response = JsonResponse({'success': False, - 'message': message}) - response.status_code = status_code - return response diff --git a/foundation/organisation/views.py b/foundation/organisation/views.py deleted file mode 100644 index b68ab88e..00000000 --- a/foundation/organisation/views.py +++ /dev/null @@ -1,13 +0,0 @@ -from django.views.generic.detail import DetailView -from django.shortcuts import get_object_or_404 - -from .models import Person - - -class PersonView(DetailView): - model = Person - template_name = 'organisation/member_detail.html' - - def get_object(self, *args, **kwargs): - person_id = self.kwargs.get('person_id', '') - return get_object_or_404(Person, id=person_id)