Ejemplo n.º 1
0
def warn_unpublished(warn_date, archive_date):
    ideas = Idea.objects.filter(
        Q(status=Idea.STATUS_DRAFT) &
        Q(visibility=Idea.VISIBILITY_PUBLIC) &
        Q(created__lt=warn_date + timedelta(days=1)) &
        Q(created__gte=warn_date)
    )

    unpublished_days = (date.today() - warn_date).days
    archive_days = (warn_date - archive_date).days

    for idea in ideas:
        for receiver in idea_receivers(idea):
            send_email(
                _("Idea '{name}' on ollut julkaisematon {days} päivää.".format(
                    name=idea.title, days=unpublished_days)),
                "content/email/unpublished_warning.txt",
                {
                    "idea": idea,
                    "unpublished_days": unpublished_days,
                    "archive_days": archive_days,
                },
                [receiver.settings.email],
                receiver.settings.language
            )
            logger.info("Varoitus julkaisemattoman idean %d arkistoinnista lähetetetty "
                        "osoitteeseen %s.", idea.pk, receiver.settings.email)
Ejemplo n.º 2
0
def archive_unpublished(archive_date):
    ideas = Idea.objects.filter(
        status=Idea.STATUS_DRAFT, created__lt=archive_date + timedelta(days=1)
    ).exclude(
        visibility=Idea.VISIBILITY_ARCHIVED
    )

    for idea in ideas:
        idea.visibility = Idea.VISIBILITY_ARCHIVED
        close_idea_target_gallups(idea)
        close_idea_target_surveys(idea)
        idea.save()
        logger.info("Idea %s arkistoitu.", idea.pk)
        for receiver in idea_receivers(idea):
            send_email(
                _("Idea '%s' on arkistoitu.") % idea,
                "content/email/unpublished_archived.txt",
                {
                    "idea": idea,
                    "published_days": (date.today() - archive_date).days,
                },
                [receiver.settings.email],
                receiver.settings.language
            )
            logger.info("Sähköposti idean %d arkistoimisesta lähetetetty "
                        "osoitteeseen %s.", idea.pk, receiver.settings.email)
Ejemplo n.º 3
0
 def send_email_notification(self):
     receivers = set(self.initial["owners"]) | set(
         self.cleaned_data["owners"])
     for receiver in receivers:
         send_email(_("Idean omistajia muutettu."),
                    "content/email/owner_change.txt", {"idea": self.idea},
                    [receiver.settings.email], receiver.settings.language)
Ejemplo n.º 4
0
 def send_email_notification(self):
     receivers = set(self.initial["admins"]) | set(
         self.cleaned_data["admins"])
     for receiver in receivers:
         send_email(_("Organisaation yhteyshenkilöitä on muutettu."),
                    "organization/email/owner_change.txt",
                    {"organization": self.organization},
                    [receiver.settings.email], receiver.settings.language)
Ejemplo n.º 5
0
 def send_email_notification(self, user):
     send_email(
         _("Käyttäjätilisi on suljettu."),
         'account/email/account_closed.txt',
         {'user': user},
         [user.settings.email],
         user.settings.language
     )
Ejemplo n.º 6
0
def receivers_added(sender, **kwargs):
    # TODO: siirrä tämä ilmoitustoiminnallisuuteen
    if kwargs['action'] == 'post_add':
        to = kwargs['model'].objects.filter(pk__in=kwargs['pk_set'])
        for user in to:
            if user.settings.message_notification:
                send_email(_("Uusi viesti"),
                           'nkmessages/email/new_message.txt', {'user': user},
                           [user.settings.email], user.settings.language)
Ejemplo n.º 7
0
 def save(self, commit=True):
     changed = self.has_changed() and "groups" in self.changed_data
     super(EditUserForm, self).save(commit)
     if changed:
         send_email(_("Käyttöoikeuksiisi tehtiin muutoksia"),
                    "nkadmin/email/group_change.txt",
                    {"target_user": self.target_user},
                    [self.target_user.settings.email],
                    self.target_user.settings.language)
Ejemplo n.º 8
0
def send_notification_emails(user, notifications):
    subject_part_1 = _("Nuortenideat.fi")
    subject_part_2 = _("kooste tapahtumista")
    send_email(string_concat(subject_part_1, ' - ', subject_part_2),
               msg_template='notifications/email/collection.txt',
               msg_ctx={'user': user, 'notifications': notifications},
               receivers=[user.settings.email, ])

    obj = SentEmails(notification=None, email=user.settings.email)
    obj.save()
Ejemplo n.º 9
0
 def send_email_notification(self):
     receivers = set(self.initial["admins"]) | set(self.cleaned_data["admins"])
     for receiver in receivers:
         send_email(
             _("Organisaation yhteyshenkilöitä on muutettu."),
             "organization/email/owner_change.txt",
             {"organization": self.organization},
             [receiver.settings.email],
             receiver.settings.language
         )
Ejemplo n.º 10
0
 def send_email_notification(self):
     receivers = set(self.initial["owners"]) | set(self.cleaned_data["owners"])
     for receiver in receivers:
         send_email(
             _("Idean omistajia muutettu."),
             "content/email/owner_change.txt",
             {"idea": self.idea},
             [receiver.settings.email],
             receiver.settings.language
         )
Ejemplo n.º 11
0
 def save(self, commit=True):
     changed = self.has_changed() and "groups" in self.changed_data
     super(EditUserForm, self).save(commit)
     if changed:
         send_email(
             _("Käyttöoikeuksiisi tehtiin muutoksia"),
             "nkadmin/email/group_change.txt",
             {"target_user": self.target_user},
             [self.target_user.settings.email],
             self.target_user.settings.language
         )
Ejemplo n.º 12
0
def receivers_added(sender, **kwargs):
    # TODO: siirrä tämä ilmoitustoiminnallisuuteen
    if kwargs['action'] == 'post_add':
        to = kwargs['model'].objects.filter(pk__in=kwargs['pk_set'])
        for user in to:
            if user.settings.message_notification:
                send_email(
                    _("Uusi viesti"),
                    'nkmessages/email/new_message.txt',
                    {'user': user},
                    [user.settings.email],
                    user.settings.language
                )
Ejemplo n.º 13
0
def send_notification_emails(user, notifications):
    subject_part_1 = _("Nuortenideat.fi")
    subject_part_2 = _("kooste tapahtumista")
    send_email(string_concat(subject_part_1, ' - ', subject_part_2),
               msg_template='notifications/email/collection.txt',
               msg_ctx={
                   'user': user,
                   'notifications': notifications
               },
               receivers=[
                   user.settings.email,
               ])

    obj = SentEmails(notification=None, email=user.settings.email)
    obj.save()
Ejemplo n.º 14
0
def send_sms_log_as_email():

    ld = dt.today().replace(day=1) - timedelta(days=1)
    start_date = ld.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
    end_date = ld.replace(hour=23, minute=59, second=59, microsecond=0)

    messages = SentTxtMessages.objects.filter(created__range=(start_date, end_date))

    context = {'start_date': start_date, 'end_date': end_date, 'count': messages.count()}

    send_email(
        'Tekstiviestiraportti',
        'smslog/email/sent_txt_messages.txt',
        context,
        [settings.SMS_LOG_EMAIL_RECEIVER, ],
    )
Ejemplo n.º 15
0
def remind_untransferred(remind_date, archive_date):
    ideas = Idea.objects.filter(published__startswith=remind_date, status=Idea.STATUS_PUBLISHED,
                                visibility=Idea.VISIBILITY_PUBLIC)

    published_days = (date.today() - remind_date).days
    archive_days = (remind_date - archive_date).days
    for idea in ideas:
        for receiver in idea_receivers(idea, contact_persons=True):
            send_email(
                _("Muistutus idean '%s' viemisestä eteenpäin.") % idea.title,
                "content/email/untransferred_reminder.txt",
                {
                    "idea": idea,
                    "published_days": published_days,
                    "archive_days": archive_days,
                },
                [receiver.settings.email],
                receiver.settings.language
            )
            logger.info("Muistutus idean %d viemisestä eteenpäin lähetetetty "
                        "osoitteeseen %s.", idea.pk, receiver.settings.email)
Ejemplo n.º 16
0
def send_sms_log_as_email():

    ld = dt.today().replace(day=1) - timedelta(days=1)
    start_date = ld.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
    end_date = ld.replace(hour=23, minute=59, second=59, microsecond=0)

    messages = SentTxtMessages.objects.filter(created__range=(start_date,
                                                              end_date))

    context = {
        'start_date': start_date,
        'end_date': end_date,
        'count': messages.count()
    }

    send_email(
        'Tekstiviestiraportti',
        'smslog/email/sent_txt_messages.txt',
        context,
        [
            settings.SMS_LOG_EMAIL_RECEIVER,
        ],
    )
Ejemplo n.º 17
0
 def send_test_email(self):
     send_email(self.subject, self.template, {"body": self.body},
                [self.recipient.settings.email], self.language)