Skip to content

Commit

Permalink
Merge pull request #1102 from okfn/remove-people-model
Browse files Browse the repository at this point in the history
Remove people model
  • Loading branch information
pdelboca authored Nov 7, 2024
2 parents aaba84f + 0455ae5 commit faad252
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 273 deletions.
15 changes: 1 addition & 14 deletions foundation/organisation/admin.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 0 additions & 6 deletions foundation/organisation/forms.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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',
),
]
103 changes: 0 additions & 103 deletions foundation/organisation/models.py
Original file line number Diff line number Diff line change
@@ -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 "<NowDoing: {}, {}>".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)
Expand Down
14 changes: 0 additions & 14 deletions foundation/organisation/search_indexes.py

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

28 changes: 0 additions & 28 deletions foundation/organisation/templates/search/organisation/person.html

This file was deleted.

Empty file.
1 change: 0 additions & 1 deletion foundation/organisation/tests/test_admin.py

This file was deleted.

22 changes: 0 additions & 22 deletions foundation/organisation/tests/test_api.py

This file was deleted.

17 changes: 0 additions & 17 deletions foundation/organisation/tests/test_search_indexes.py

This file was deleted.

21 changes: 0 additions & 21 deletions foundation/organisation/utils.py

This file was deleted.

13 changes: 0 additions & 13 deletions foundation/organisation/views.py

This file was deleted.

0 comments on commit faad252

Please sign in to comment.