train spam on state change to 'closed_spam'
This commit is contained in:
parent
a6a8b0defe
commit
5a6349c5d3
3 changed files with 36 additions and 3 deletions
31
core/tickets/migrations/0011_train_old_spam.py
Normal file
31
core/tickets/migrations/0011_train_old_spam.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# 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):
|
||||
from tickets.models import IssueThread
|
||||
for t in IssueThread.objects.all():
|
||||
try:
|
||||
state = t.state
|
||||
i = 0
|
||||
for e in t.emails.all():
|
||||
if e.raw_file:
|
||||
if state == 'closed_spam' and i == 0:
|
||||
e.train_spam()
|
||||
else:
|
||||
e.train_ham()
|
||||
i += 1
|
||||
except:
|
||||
pass
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(train_old_mails),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue