예제 #1
0
    def send_notifications(self):
        article_link = self.article.get_absolute_url()
        comment_link = "{}#comment-{}".format(article_link, self.pk)
        template_data = {
            "article": self.article.title,
            "created_at": self.created_at.strftime("%I:%M %p, %d %B %Y"),
            # "username": self.username,
            "link": urljoin(settings.INETLOCATION, comment_link),
            "article_owner": self.article.owner.username,
        }
        scheduler_data = build_send_mail_json(
            self.article.owner.email,
            template="comment_notification.html",
            subject="{} commented on your article".format(self.username),
            template_data=template_data,
        )
        Scheduler.objects.create(command="send_email", data=scheduler_data)

        if self.parent and self.parent.user:
            template_data["parent_comment_owner"] = self.parent.username
            scheduler_data = build_send_mail_json(
                self.parent.user.email,
                template="comment_reply_notification.html",
                subject="{} replied to your comment".format(self.username),
                template_data=template_data,
            )
            Scheduler.objects.create(command="send_email", data=scheduler_data)
예제 #2
0
def build_post_blog_reminders(builder):
    data = json.loads(builder.data)
    last_due_date = BlogPostDueDate.objects.last()
    due_date = BlogPostDueDate.objects.get(pk=data['due_date_pk'])
    if due_date == last_due_date:
        blogs_count = 0
    else:
        blogs_count = 1

    gsoc_year = GsocYear.objects.first()
    profiles = UserProfile.objects.filter(gsoc_year=gsoc_year, role=3).all()
    for profile in profiles:
        if profile.current_blog_count > blogs_count and not (
                profile.hidden and profile.reminder_disabled):
            student_template_data = {
                'current_blog_count': profile.current_blog_count,
                'due_date': due_date.date.strftime('%d %B %Y')
            }

            mentors_template_data = {
                'student_username': profile.user.username,
                'student_email': profile.user.email,
                'suborg_name': profile.suborg_full_name.suborg_name,
                'due_date': due_date.date.strftime('%d %B %Y'),
                'current_blog_count': profile.current_blog_count
            }

            suborg = profile.suborg_full_name
            mentors = UserProfile.objects.filter(suborg_full_name=suborg,
                                                 role=2)
            suborg_admins = UserProfile.objects.filter(suborg_full_name=suborg,
                                                       role=1)
            student_email = profile.user.email

            mentors_emails = ['*****@*****.**']
            mentors_emails.extend([_.user.email for _ in mentors])
            mentors_emails.extend([_.user.email for _ in suborg_admins])

            scheduler_data_student = build_send_mail_json(
                student_email,
                template='post_blog_reminder_student.html',
                subject='Reminder for Weekly Blog Post',
                template_data=student_template_data)

            scheduler_data_mentors = build_send_mail_json(
                mentors_emails,
                template='post_blog_reminder_mentors.html',
                subject='Weekly Blog Post missed by a Student of your Sub-Org',
                template_data=mentors_template_data)

            Scheduler.objects.create(command='send_email',
                                     data=scheduler_data_student)

            Scheduler.objects.create(command='send_email',
                                     data=scheduler_data_mentors)
예제 #3
0
 def create_scheduler(self, trigger_time=timezone.now()):
     validate_email(self.email)
     role = {0: "Others", 1: "Suborg Admin", 2: "Mentor", 3: "Student"}
     template_data = {
         "register_link": settings.INETLOCATION + self.url,
         "role": self.user_role,
         "gsoc_year": self.user_gsoc_year.gsoc_year,
     }
     if self.user_role == 0:
         subject = (f"You have been invited to join for GSoC "
                    f"{self.user_gsoc_year.gsoc_year} with PSF")
     else:
         subject = (f"You have been invited to join "
                    f"{self.user_suborg.suborg_name.strip()}"
                    f" as a {role[self.user_role]} for GSoC "
                    f"{self.user_gsoc_year.gsoc_year} with PSF")
         template_data["suborg"] = self.user_suborg.suborg_name.strip()
     scheduler_data = build_send_mail_json(
         self.email,
         template="invite.html",
         subject=subject,
         template_data=template_data,
     )
     s = Scheduler.objects.create(command="send_email",
                                  activation_date=trigger_time,
                                  data=scheduler_data)
     self.scheduler = s
     self.save()
예제 #4
0
def build_pre_blog_reminders(builder):
    try:
        data = json.loads(builder.data)
        due_date = BlogPostDueDate.objects.get(pk=data['due_date_pk'])
        gsoc_year = GsocYear.objects.first()
        profiles = UserProfile.objects.filter(gsoc_year=gsoc_year, role=3).all()
        categories = (
            (0, 'Weekly Check-In'),
            (1, 'Blog Post'),
            )
        category = categories[due_date.category][1]
        for profile in profiles:
            if profile.current_blog_count is not 0 and not (profile.hidden or
                                                            profile.reminder_disabled):
                template_data = {
                    'current_blog_count': profile.current_blog_count,
                    'type': due_date.category,
                    'due_date': due_date.date.strftime('%d %B %Y')
                    }

                scheduler_data = build_send_mail_json(profile.user.email,
                                                      template='pre_blog_reminder.html',
                                                      subject=f'Reminder for {category}',
                                                      template_data=template_data)

                s = Scheduler.objects.create(command='send_email',
                                             data=scheduler_data)
        return None
    except Exception as e:
        return str(e)
예제 #5
0
def build_remove_user_details(builder):
    try:
        gsoc_year = GsocYear.objects.first()
        profiles = UserProfile.objects.filter(gsoc_year=gsoc_year,
                                              role__in=[1, 2, 3]).all()
        for profile in profiles:
            email = profile.user.email
            profile.user.email = None
            profile.user.save()
            _uuid = uuid.uuid4()
            ReaddUser.objects.create(user=profile.user, uuid=_uuid)
            template_data = {
                # TODO: change this after the view is created
                "link": settings.INETLOCATION + "use reverse here"
            }
            scheduler_data = build_send_mail_json(
                email,
                template="readd_email.html",
                subject=
                "Your personal details have been removed from our database",
                template_data=template_data,
            )
            Scheduler.objects.create(command="send_email", data=scheduler_data)
    except Exception as e:
        return str(e)
예제 #6
0
def build_pre_blog_reminders(builder):
    try:
        data = json.loads(builder.data)
        due_date = BlogPostDueDate.objects.get(pk=data["due_date_pk"])
        gsoc_year = GsocYear.objects.first()
        profiles = UserProfile.objects.filter(gsoc_year=gsoc_year,
                                              role=3).all()
        categories = ((0, "Weekly Check-In"), (1, "Blog Post"))
        category = categories[due_date.category][1]
        for profile in profiles:
            if profile.current_blog_count is not 0 and not (
                    profile.hidden or profile.reminder_disabled):
                template_data = {
                    "current_blog_count": profile.current_blog_count,
                    "type": due_date.category,
                    "due_date": due_date.date.strftime("%d %B %Y"),
                }

                scheduler_data = build_send_mail_json(
                    profile.user.email,
                    template="pre_blog_reminder.html",
                    subject=f"Reminder for {category}",
                    template_data=template_data,
                )

                s = Scheduler.objects.create(command="send_email",
                                             data=scheduler_data)
        return None
    except Exception as e:
        return str(e)
예제 #7
0
    def accept(self):
        self.accepted = True
        if not self.suborg:
            self.suborg = SubOrg.objects.create(suborg_name=self.suborg_name)
        self.save()

        template_data = {
            "gsoc_year": self.gsoc_year.gsoc_year,
            "suborg_name": self.suborg.suborg_name,
        }
        scheduler_data = build_send_mail_json(
            self.suborg_admin_email,
            template="suborg_accept.html",
            subject="Acceptance for GSoC@PSF {}".format(
                self.gsoc_year.gsoc_year),
            template_data=template_data,
        )
        Scheduler.objects.create(command="send_email", data=scheduler_data)

        RegLink.objects.create(
            user_role=1,
            user_suborg=self.suborg,
            user_gsoc_year=self.gsoc_year,
            email=self.suborg_admin_email,
            send_notifications=False,
        )

        if self.suborg_admin_2_email:
            RegLink.objects.create(
                user_role=1,
                user_suborg=self.suborg,
                user_gsoc_year=self.gsoc_year,
                email=self.suborg_admin_2_email,
                send_notifications=False,
            )

        if self.suborg_admin_3_email:
            RegLink.objects.create(
                user_role=1,
                user_suborg=self.suborg,
                user_gsoc_year=self.gsoc_year,
                email=self.suborg_admin_3_email,
                send_notifications=False,
            )

        s = Scheduler.objects.filter(
            command="update_site_template",
            data=json.dumps({"template": "index.html"}),
            success=None,
        ).all()
        if len(s) == 0:
            time = timezone.now() + timezone.timedelta(minutes=5)
            Scheduler.objects.create(
                command="update_site_template",
                data=json.dumps({"template": "index.html"}),
                activation_date=time,
            )
예제 #8
0
 def create_scheduler(self, trigger_time=timezone.now()):
     validate_email(self.email)
     scheduler_data = build_send_mail_json(
         self.email,
         template='invite.html',
         subject='Your GSoC 2019 invite',
         template_data={'register_link': settings.INETLOCATION + self.url})
     s = Scheduler.objects.create(command='send_email',
                                  activation_date=trigger_time,
                                  data=scheduler_data)
     self.scheduler = s
     self.save()
예제 #9
0
    def send_update_notification(self):
        if self.suborg:
            suborg_name = self.suborg.suborg_name
        else:
            suborg_name = self.suborg_name

        template_data = {"suborg_name": suborg_name}
        scheduler_data = build_send_mail_json(
            settings.ADMINS,
            template="suborg_application_notification.html",
            subject="Review new/updated SubOrg Application",
            template_data=template_data,
        )
        Scheduler.objects.create(command="send_email", data=scheduler_data)
예제 #10
0
    def send_notifications(self):
        article_link = self.article.get_absolute_url()
        comment_link = '{}#comment-{}'.format(article_link, self.pk)
        template_data = {
            'article': self.article.title,
            'created_at': self.created_at.strftime('%I:%M %p, %d %B %Y'),
            'username': self.username,
            'link': comment_link,
        }
        scheduler_data = build_send_mail_json(
            self.article.owner.email,
            template='comment_notification.html',
            subject='{} commented on your article'.format(self.username),
            template_data=template_data)
        Scheduler.objects.create(command='send_email', data=scheduler_data)

        if self.parent and self.parent.user:
            scheduler_data = build_send_mail_json(
                self.parent.user.email,
                template='comment_reply_notification.html',
                subject='{} replied to your comment'.format(self.username),
                template_data=template_data)
            Scheduler.objects.create(command='send_email', data=scheduler_data)
예제 #11
0
def build_pre_blog_reminders(builder):
    data = json.loads(builder.data)
    due_date = BlogPostDueDate.objects.get(pk=data['due_date_pk'])
    gsoc_year = GsocYear.objects.first()
    profiles = UserProfile.objects.filter(gsoc_year=gsoc_year, role=3).all()
    for profile in profiles:
        if profile.current_blog_count is not 0 and not (
                profile.hidden and profile.reminder_disabled):
            template_data = {
                'current_blog_count': profile.current_blog_count,
                'due_date': due_date.date.strftime('%d %B %Y')
            }

            scheduler_data = build_send_mail_json(
                profile.user.email,
                template='pre_blog_reminder.html',
                subject='Reminder for Weekly Blog Post',
                template_data=template_data)

            s = Scheduler.objects.create(command='send_email',
                                         data=scheduler_data)
예제 #12
0
    def send_review(self):
        self.accepted = False
        self.save()

        if self.suborg:
            suborg_name = self.suborg.suborg_name
        else:
            suborg_name = self.suborg_name

        template_data = {
            "gsoc_year": self.gsoc_year.gsoc_year,
            "suborg_name": suborg_name,
            "message": self.last_message,
        }
        scheduler_data = build_send_mail_json(
            self.suborg_admin_email,
            template="suborg_review.html",
            subject="Review your SubOrg Application"
            " for GSoC@PSF {}".format(self.gsoc_year.gsoc_year),
            template_data=template_data,
        )
        Scheduler.objects.create(command="send_email", data=scheduler_data)
예제 #13
0
    def save(self, *args, **kwargs):
        if not (self.to or self.to_group):
            raise ValidationError(
                message=
                "Any one of the fields 'to' or 'to_group' should be filled.")
        emails = []
        if self.to:
            emails.extend(self.to.split(","))

        gsoc_year = GsocYear.objects.first()

        if self.to_group == "students":
            ups = UserProfile.objects.filter(role=3, gsoc_year=gsoc_year).all()
            emails.extend([_.user.email for _ in ups])
        elif self.to_group == "mentors":
            ups = UserProfile.objects.filter(role=2, gsoc_year=gsoc_year).all()
            emails.extend([_.user.email for _ in ups])
        elif self.to_group == "suborg_admins":
            ups = UserProfile.objects.filter(role=1, gsoc_year=gsoc_year).all()
            emails.extend([_.user.email for _ in ups])
        elif self.to_group == "all":
            ups = UserProfile.objects.filter(gsoc_year=gsoc_year).all()
            emails.extend([_.user.email for _ in ups])

        scheduler_data = build_send_mail_json(
            emails,
            template="generic_email.html",
            subject=self.subject,
            template_data={"body": self.body},
        )
        self.scheduler = Scheduler.objects.create(
            command="send_email",
            data=scheduler_data,
            activation_date=self.activation_date,
        )

        super(SendEmail, self).save(*args, **kwargs)
예제 #14
0
def build_post_blog_reminders(builder):
    try:
        data = json.loads(builder.data)
        last_due_date = BlogPostDueDate.objects.last()
        due_date = BlogPostDueDate.objects.get(pk=data['due_date_pk'])
        if due_date == last_due_date:
            blogs_count = 0
        else:
            blogs_count = 1

        categories = (
            (0, 'Weekly Check-In'),
            (1, 'Blog Post'),
            )
        category = categories[due_date.category][1]

        gsoc_year = GsocYear.objects.first()
        profiles = UserProfile.objects.filter(gsoc_year=gsoc_year, role=3).all()
        for profile in profiles:
            if profile.current_blog_count > blogs_count and not (profile.hidden or
                                                                 profile.reminder_disabled):
                suborg = profile.suborg_full_name
                mentors = UserProfile.objects.filter(suborg_full_name=suborg, role=2)
                suborg_admins = UserProfile.objects.filter(suborg_full_name=suborg, role=1)

                activation_date = builder.activation_date.date()

                if activation_date - due_date.date == timezone.timedelta(days=1):
                    student_template = 'first_post_blog_reminder_student.html'

                elif activation_date - due_date.date == timezone.timedelta(days=3):
                    student_template = 'second_post_blog_reminder_student.html'

                    mentors_emails = ['*****@*****.**']
                    mentors_emails.extend([_.user.email for _ in mentors])
                    mentors_emails.extend([_.user.email for _ in suborg_admins])

                    mentors_template_data = {
                        'student_username': profile.user.username,
                        'student_email': profile.user.email,
                        'suborg_name': profile.suborg_full_name.suborg_name,
                        'due_date': due_date.date.strftime('%d %B %Y'),
                        'current_blog_count': profile.current_blog_count
                        }

                    scheduler_data_mentors = build_send_mail_json(
                        mentors_emails,
                        template='post_blog_reminder_mentors.html',
                        subject=f'{category} missed by a Student of your Sub-Org',
                        template_data=mentors_template_data
                        )

                    Scheduler.objects.create(command='send_email',
                                             data=scheduler_data_mentors)

                student_template_data = {
                    'current_blog_count': profile.current_blog_count,
                    'due_date': due_date.date.strftime('%d %B %Y')
                    }

                scheduler_data_student = build_send_mail_json(
                    profile.user.email,
                    template=student_template,
                    subject=f'Reminder for {category}',
                    template_data=student_template_data
                    )

                Scheduler.objects.create(command='send_email',
                                         data=scheduler_data_student)
        return None
    except Exception as e:
        return str(e)
예제 #15
0
def build_post_blog_reminders(builder):
    try:
        data = json.loads(builder.data)
        last_due_date = BlogPostDueDate.objects.last()
        due_date = BlogPostDueDate.objects.get(pk=data["due_date_pk"])
        if due_date == last_due_date:
            blogs_count = 0
        else:
            blogs_count = 1

        categories = ((0, "Weekly Check-In"), (1, "Blog Post"))
        category = categories[due_date.category][1]

        gsoc_year = GsocYear.objects.first()
        profiles = UserProfile.objects.filter(gsoc_year=gsoc_year,
                                              role=3).all()
        for profile in profiles:
            if profile.current_blog_count > blogs_count and not (
                    profile.hidden or profile.reminder_disabled):
                suborg = profile.suborg_full_name
                mentors = UserProfile.objects.filter(suborg_full_name=suborg,
                                                     role=2)
                suborg_admins = UserProfile.objects.filter(
                    suborg_full_name=suborg, role=1)

                activation_date = builder.activation_date.date()

                if activation_date - due_date.date == timezone.timedelta(
                        days=1):
                    student_template = "first_post_blog_reminder_student.html"

                elif activation_date - due_date.date == timezone.timedelta(
                        days=3):
                    student_template = "second_post_blog_reminder_student.html"

                    mentors_emails = ["*****@*****.**"]
                    mentors_emails.extend([_.user.email for _ in mentors])
                    mentors_emails.extend(
                        [_.user.email for _ in suborg_admins])

                    mentors_template_data = {
                        "student_username": profile.user.username,
                        "student_email": profile.user.email,
                        "suborg_name": profile.suborg_full_name.suborg_name,
                        "due_date": due_date.date.strftime("%d %B %Y"),
                        "current_blog_count": profile.current_blog_count,
                    }

                    scheduler_data_mentors = build_send_mail_json(
                        mentors_emails,
                        template="post_blog_reminder_mentors.html",
                        subject=
                        f"{category} missed by a Student of your Sub-Org",
                        template_data=mentors_template_data,
                    )

                    Scheduler.objects.create(command="send_email",
                                             data=scheduler_data_mentors)

                student_template_data = {
                    "current_blog_count": profile.current_blog_count,
                    "due_date": due_date.date.strftime("%d %B %Y"),
                }

                scheduler_data_student = build_send_mail_json(
                    profile.user.email,
                    template=student_template,
                    subject=f"Reminder for {category}",
                    template_data=student_template_data,
                )

                Scheduler.objects.create(command="send_email",
                                         data=scheduler_data_student)
        return None
    except Exception as e:
        return str(e)