Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROD] Clean old Network models #1101

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions foundation/organisation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
13 changes: 0 additions & 13 deletions foundation/organisation/cms_apps.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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',
),
]
127 changes: 0 additions & 127 deletions foundation/organisation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -114,129 +110,6 @@ def __repr__(self):
return "<NowDoing: {}, {}>".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)
Expand Down
15 changes: 1 addition & 14 deletions foundation/organisation/search_indexes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from haystack import indexes
from .models import Person, NetworkGroup
from .models import Person


class PersonIndex(indexes.SearchIndex, indexes.Indexable):
Expand All @@ -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'
22 changes: 0 additions & 22 deletions foundation/organisation/templates/organisation/board_details.html

This file was deleted.

42 changes: 0 additions & 42 deletions foundation/organisation/templates/organisation/member.html

This file was deleted.

46 changes: 0 additions & 46 deletions foundation/organisation/templates/organisation/member_detail.html

This file was deleted.

Loading
Loading