train spam on state change to 'closed_spam'

This commit is contained in:
j3d1 2024-11-09 01:00:53 +01:00
parent a6a8b0defe
commit e2d56d016d
3 changed files with 32 additions and 3 deletions

View file

@ -0,0 +1,27 @@
# Generated by Django 4.2.7 on 2024-06-23 02:17
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('mail', '0006_email_raw_file'),
('tickets', '0010_issuethread_event_itemrelation_and_more'),
]
def train_old_mails(apps, schema_editor):
IssueThread = apps.get_model('tickets', 'IssueThread')
for t in IssueThread.objects.all():
state = t.state
i = 0
for e in t.emails.all():
if state == 'closed_spam' and i == 0:
e.train_spam()
else:
e.train_ham()
i += 1
operations = [
migrations.RunPython(train_old_mails),
]

View file

@ -60,6 +60,8 @@ class IssueThread(SoftDeleteModel):
if self.state == value:
return
self.state_changes.create(state=value)
if value == 'closed_spam' and self.emails.exists():
self.emails.first().train_spam()
@property
def assigned_to(self):