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

[8306] delete apps without models and prepare deletion of apps with models #2689

Merged
merged 13 commits into from
Oct 21, 2024
Merged
5 changes: 0 additions & 5 deletions euth/actions/admin.py

This file was deleted.

16 changes: 16 additions & 0 deletions euth/actions/migrations/0004_delete_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.2.20 on 2024-09-09 13:51

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('euth_actions', '0003_restrict_verbs_by_choices'),
]

operations = [
migrations.DeleteModel(
name='Action',
),
]
68 changes: 0 additions & 68 deletions euth/actions/models.py
Original file line number Diff line number Diff line change
@@ -1,68 +0,0 @@
from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils import timezone

from adhocracy4.projects.models import Project

from . import verbs


class Action(models.Model):

# actor, if actor is None the action was create by the system
actor = models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
blank=True,
null=True)

# target eg. idea
target_content_type = models.ForeignKey(ContentType,
blank=True,
null=True,
on_delete=models.CASCADE,
related_name='target')
target_object_id = models.CharField(max_length=255, blank=True, null=True)
target = GenericForeignKey(
ct_field='target_content_type', fk_field='target_object_id')

# action object eg. comment
action_object_content_type = models.ForeignKey(
ContentType,
blank=True,
null=True,
on_delete=models.CASCADE,
related_name='action_object')
action_object_object_id = models.CharField(
max_length=255, blank=True, null=True)
action_object = GenericForeignKey(
ct_field='action_object_content_type',
fk_field='action_object_object_id')

# project
project = models.ForeignKey(
Project, on_delete=models.CASCADE, blank=True, null=True)

timestamp = models.DateTimeField(default=timezone.now)
public = models.BooleanField(default=True, db_index=True)
verb = models.CharField(max_length=255, db_index=True, choices=verbs.all())
description = models.TextField(blank=True, null=True)

def __str__(self):

ctx = {
'actor': self.actor.username if self.actor else 'system',
'verb': self.verb,
'action_object': self.action_object,
'target': self.target
}

if self.target:
if self.action_object:
return '{actor} {verb} {action_object} on {target}'.format(
**ctx)
return '{actor} {verb} {target}'.format(**ctx)
if self.action_object:
return '{actor} {verb} {action_object}'.format(**ctx)
return '{actor} {verb}'.format(**ctx)
49 changes: 0 additions & 49 deletions euth/actions/signals.py
Original file line number Diff line number Diff line change
@@ -1,49 +0,0 @@
from django.apps import apps
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from adhocracy4.projects.models import Project
from euth.actions import emails

from . import verbs
from .models import Action


def add_action(sender, instance, created, **kwargs):
verb = verbs.CREATE if created else verbs.UPDATE
actor = instance.creator

action = Action(
actor=actor,
verb=verb,
action_object=instance
)

if hasattr(instance, 'project') and instance.project.__class__ is Project:
action.project = instance.project
action.target = instance.project

if hasattr(instance, 'content_object'):
action.target = instance.content_object

action.save()


for app, model in settings.ACTIONABLE:
post_save.connect(add_action, apps.get_model(app, model))


@receiver(post_save, sender=Action)
def send_notification(sender, instance, created, **kwargs):
action = instance

if instance.verb == verbs.CREATE:
emails.NotifyCreatorEmail.send(action)

if action.target_content_type.model_class() is Project:
emails.NotifyModeratorsEmail.send(action)
emails.NotifyFollowersOnNewIdeaCreated.send(action)

if instance.verb == verbs.COMPLETE:
emails.NotifyFollowersOnPhaseIsOverSoonEmail.send(action)
1 change: 0 additions & 1 deletion euth/blueprints/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions euth/blueprints/apps.py

This file was deleted.

Loading
Loading