From 68383d25935491f0ba2d85934c17f52f9effb726 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Tue, 10 Dec 2013 15:57:41 +0100 Subject: [PATCH] add testimonial cleanup script --- .../teleforma-cleanup-testimonials.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 teleforma/management/commands/teleforma-cleanup-testimonials.py diff --git a/teleforma/management/commands/teleforma-cleanup-testimonials.py b/teleforma/management/commands/teleforma-cleanup-testimonials.py new file mode 100644 index 00000000..b21b2d63 --- /dev/null +++ b/teleforma/management/commands/teleforma-cleanup-testimonials.py @@ -0,0 +1,44 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from django.contrib.auth.forms import PasswordResetForm +from django.contrib.auth.tokens import default_token_generator +from django.template.defaultfilters import slugify +from django.template.loader import render_to_string +from django.core.mail import send_mail, mail_admins +from django.utils import translation +from telemeta.models import * +from telemeta.util.unaccent import unaccent +from teleforma.models import * +import logging +import datetime + + +class Command(BaseCommand): + help = """Cleanup mutiple generated testimonials per user""" + + def handle(self, *args, **kwargs): + users = User.objects.all() + + for user in users: + auditor = user.auditor.all() + professor = user.professor.all() + seminars = [] + + if auditor and not professor and user.is_active and user.email: + auditor = auditor[0] + context = {} + all_seminars = auditor.seminars.all() + + for seminar in all_seminars: + testimonials = user.testimonial.filter(seminar=seminar) + if len(testimonials) > 1: + for testimonial1 in testimonials: + for testimonial2 in testimonials: + if testimonial2.date_added < testimonial1.date_added: + #testimonial2.delete() + print ('kept', testimonial1.title, testimonial1.date_added) + print ('deleted', testimonial2.title, testimonial2.date_added) + + -- 2.39.5