Пример #1
0
    def save_model(self, request, model, form, change):
        '''
        Will send activation emails when appropiate
        '''
        if not change:
            model.save()
            return

        old_model = Profile.objects.filter(id=model.id)[0]
        if model.is_active == True and old_model.is_active == False:
            # user activated, send activation email
            current_site = Site.objects.get_current()
            title = I18nString(_("Welcome to %(site_name)s, %(username)s"), {
                'site_name': settings.SITE_NAME,
                'username': model.username
            })
            message = I18nString(_(u"Congratulations %(username)s!\n"
            u"The admins have accepted your registration request, "
            u"now you can start collaborating in our community in  "
            u"http://%(url)s/.\n\n- The team of %(site_name)s."), {
                'username': model.username,
                'url': current_site.domain,
                'site_name': settings.SITE_NAME
            })
            send_mail(title, message, settings.DEFAULT_FROM_EMAIL,
                [model], fail_silently=True)

        model.save()
Пример #2
0
def new_message_email(sender, instance, signal,
        subject_prefix=_(u'New Message: %(subject)s'),
        template_name="messages/new_message.html",
        default_protocol=None,
        *args, **kwargs):
    """
    This function sends an email and is called via Django's signal framework.
    Optional arguments:
        ``template_name``: the template to use
        ``subject_prefix``: prefix for the email subject.
        ``default_protocol``: default protocol in site URL passed to template
    """
    if default_protocol is None:
        default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')

    if 'created' in kwargs and kwargs['created']:
        try:
            current_domain = Site.objects.get_current().domain
            subject = I18nString(subject_prefix, {'subject': instance.subject})
            message = I18nString(template_name, {
                'site_url': '%s://%s' % (default_protocol, current_domain),
                'message': instance,
            }, True)
            if instance.recipient.email != "":
                send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                    [instance,], fail_silently=True)
        except Exception, e:
            print e
            pass #fail silently
Пример #3
0
def new_transfer_email(sender, instance, signal, *args, **kwargs):

    if 'created' not in kwargs or not kwargs['created']:
        update_transfer_email(sender, instance, signal, *args, **kwargs)
        return

    current_domain = Site.objects.get_current().domain
    default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')

    recipient = instance.recipient()
    if instance.service:
        subject = I18nString(_('New transfer request from %s'),
                             instance.creator().username)
    else:
        subject = I18nString(_('New direct transfer from %s'),
                             instance.creator().username)
    message = I18nString(
        "serv/new_transfer_email.html", {
            'site_url': '%s://%s' % (default_protocol, current_domain),
            'transfer': instance
        }, True)
    send_mail(subject,
              message,
              settings.DEFAULT_FROM_EMAIL, [
                  recipient,
              ],
              fail_silently=True)
Пример #4
0
def reset_password_user_action(profile_admin, request, queryset):
    import random
    from string import letters
    from django.core.urlresolvers import reverse

    for u in queryset:
        pwd = ''.join(random.choice(letters) for i in range(8))
        u.set_password(pwd)
        u.save()

        current_site = Site.objects.get_current()
        title = I18nString(_("Your password has been reset for %(site_name)s"), {
            'site_name': settings.SITE_NAME,
            'username': u.username
        })
        message = I18nString(_(u" %(username)s!\n"
        u"The admins have reset your password, "
        u"You can enter in "
        u"http://%(url)s/ with the following credentials:\n\n"
        u"username: %(username)s\n"
        u"password: %(password)s\n\n"
        u"You can change your password in your profile:\n"
        u"http://%(url)s%(pwdchange)s"
        u"\n\n- The team of %(site_name)s."), {
            'username': u.username,
            'password': pwd,
            'url': current_site.domain,
            'pwdchange': reverse("user-password-change"),
            'site_name': settings.SITE_NAME
        })

        send_mail(title, message, settings.DEFAULT_FROM_EMAIL,
            [u], fail_silently=True)
Пример #5
0
    def save_model(self, request, model, form, change):
        '''
        Will send activation emails when appropiate
        '''
        if not change:
            model.save()
            return

        old_model = Profile.objects.filter(id=model.id)[0]
        if model.is_active == True and old_model.is_active == False:
            # user activated, send activation email
            current_site = Site.objects.get_current()
            title = I18nString(_("Welcome to %(site_name)s, %(username)s"), {
                'site_name': settings.SITE_NAME,
                'username': model.username
            })
            message = I18nString(_(u"Congratulations %(username)s!\n"
            u"The admins have accepted your registration request, "
            u"now you can start collaborating in our community in  "
            u"http://%(url)s/.\n\n- The team of %(site_name)s."), {
                'username': model.username,
                'url': current_site.domain,
                'site_name': settings.SITE_NAME
            })
            send_mail(title, message, settings.DEFAULT_FROM_EMAIL,
                [model], fail_silently=True)

        model.save()
Пример #6
0
def reset_password_user_action(profile_admin, request, queryset):
    import random
    from string import letters
    from django.core.urlresolvers import reverse

    for u in queryset:
        pwd = ''.join(random.choice(letters) for i in range(8))
        u.set_password(pwd)
        u.save()

        current_site = Site.objects.get_current()
        title = I18nString(_("Your password has been reset for %(site_name)s"), {
            'site_name': settings.SITE_NAME,
            'username': u.username
        })
        message = I18nString(_(u" %(username)s!\n"
        u"The admins have reset your password, "
        u"You can enter in "
        u"http://%(url)s/ with the following credentials:\n\n"
        u"username: %(username)s\n"
        u"password: %(password)s\n\n"
        u"You can change your password in your profile:\n"
        u"http://%(url)s%(pwdchange)s"
        u"\n\n- The team of %(site_name)s."), {
            'username': u.username,
            'password': pwd,
            'url': current_site.domain,
            'pwdchange': reverse("user-password-change"),
            'site_name': settings.SITE_NAME
        })

        send_mail(title, message, settings.DEFAULT_FROM_EMAIL,
            [u], fail_silently=True)
Пример #7
0
def update_transfer_email(sender, instance, signal, *args, **kwargs):
    current_domain = Site.objects.get_current().domain
    default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')

    if instance.status == 'q':
        recipients = [
            instance.creator(),
        ]
        subject = I18nString(_('Transfer from %s edited'),
                             instance.creator().username)
        template = "serv/edit_transfer_email.html"
    elif instance.status == 'a':
        recipients = [
            instance.creator(),
        ]
        if instance.service:
            subject = I18nString(_('Transfer of the service from %s accepted'),
                                 instance.service.creator.username)
        else:
            subject = I18nString(_('Direct transfer from %s accepted'),
                                 instance.creator().username)
        template = "serv/accept_transfer_email.html"
    elif instance.status == 'r':
        if not instance.is_direct():
            subject = I18nString(
                _('Transfer to %(user1)s from a service of %(user2)s'
                  ' cancelled'), {
                      'user1': instance.creator().username,
                      'user2': instance.service.creator.username
                  })
        else:
            subject = I18nString(_('Direct transfer from %s cancelled'),
                                 instance.creator().username)
        template = "serv/cancel_transfer_email.html"
        recipients = [instance.credits_debtor, instance.credits_payee]
    elif instance.status == 'd':
        subject = I18nString(
            _('Transfer of the service you did to %s confirmed'),
            instance.credits_debtor.email)
        template = "serv/done_transfer_email.html"
        recipients = [
            instance.credits_payee,
        ]
    else:
        print "error, invalid updated transfer status " + instance.service.status
        return

    message = I18nString(
        template, {
            'site_url': '%s://%s' % (default_protocol, current_domain),
            'transfer': instance
        }, True)
    send_mail(subject,
              message,
              settings.DEFAULT_FROM_EMAIL,
              recipients,
              fail_silently=True)
Пример #8
0
    def __execute(self, task):
        '''
        Sends an email update when needed. We will send for each user only one
        update email each time, with all the the user update info. Updates will
        be sent in periods.
        '''
        for user in Profile.objects.all():
            if not user.email_updates:
                continue
            unread_messages = Message.objects.inbox_for(user).filter(
                read_at__isnull=True)
            unread_comments = Message.objects.public_inbox_for(user).\
                filter(read_at__isnull=True)
            transfers_pending = user.transfers_pending()
            send_update_data = [
                {
                    "data": unread_messages,
                    "date_field": "sent_at"
                },
                {
                    "data": unread_comments,
                    "date_field": "sent_at"
                },
                {
                    "data": transfers_pending,
                    "date_field": "request_date"
                },
            ]

            if self.__should_send_update(task, send_update_data):
                subject = I18nString(_(u"Updates from %s"), settings.SITE_NAME)
                default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL',
                                           'http')
                new_services = Service.objects.filter(is_active=True)
                paginator = Paginator(new_services, 5)
                new_services = paginator.page(1)

                message = I18nString(
                    "tasks/email_update.html",
                    dict(site_url='%s://%s' %
                         (default_protocol, Site.objects.get_current().domain),
                         site_name=settings.SITE_NAME,
                         unread_messages=unread_messages,
                         unread_comments=unread_comments,
                         transfers_pending=transfers_pending,
                         new_services=new_services,
                         recipient=user,
                         context_instance=RequestContext(self.request)), True)
                send_mail(subject,
                          message,
                          settings.DEFAULT_FROM_EMAIL, [user],
                          fail_silently=True)
                return
Пример #9
0
    def POST(self):
        form = RemoveForm(self.request.POST)
        if not form.is_valid():
            return self.context_response('user/remove.html', {'form': form})

        # TODO: do not remove user, only marks it as inactive
        user = self.request.user
        user.is_active = False
        user.save()

        # Send an email to admins and another to the user
        subject = I18nString(_("[%(site_name)s] User %(username)s disabled"), {
            'site_name': settings.SITE_NAME,
            'username': user.username
        })
        message = I18nString(_("The user %(username)s has requested being removed from the"
            " website. The reason given was:\n\n%(reason)s"), {
                'username': user.username,
                'reason': form.cleaned_data["reason"]
            })
        mail_owners(subject, message)

        current_site = Site.objects.get_current()
        subject = I18nString(_("You removed your profile %(username)s in %(site_name)s"), {
            'username': user.username,
            'site_name': settings.SITE_NAME
            })
        message = I18nString(_("Hello %(username)s!\n You removed your profile in"
            " http://%(url)s/ . We regret your decision to take this"
            " step. We'll read the reason why you removed yourself from this"
            " community that you provided to us and we'll have it in mind to"
            " improve our service in the future."
            "\n\n- The team of %(site_name)s."), {
                'username': user.username,
                'url': current_site.domain,
                'site_name': settings.SITE_NAME
            })
        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [user],
            fail_silently=True)

        self.flash(_("We regret your decision to take this step.We'll read the"
            " reason why you removed yourself from this community that you"
            " provided to us and we'll have it in mind to improve our service"
            " in the future."), title=_("User removed"))

        return redirect("user-logout")
Пример #10
0
def update_transfer_email(sender, instance, signal, *args, **kwargs):
    current_domain = Site.objects.get_current().domain
    default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')

    if instance.status == 'q':
        recipients = [instance.creator(),]
        subject=I18nString(_('Transfer from %s edited'),
            instance.creator().username)
        template = "serv/edit_transfer_email.html"
    elif instance.status == 'a':
        recipients = [instance.creator(),]
        if instance.service:
            subject=I18nString(_('Transfer of the service from %s accepted'),
                instance.service.creator.username)
        else:
            subject=I18nString(_('Direct transfer from %s accepted'),
                instance.creator().username)
        template = "serv/accept_transfer_email.html"
    elif instance.status == 'r':
        if not instance.is_direct():
            subject=I18nString(_('Transfer to %(user1)s from a service of %(user2)s'
                ' cancelled'), {
                        'user1': instance.creator().username,
                        'user2': instance.service.creator.username
                    })
        else:
            subject=I18nString(_('Direct transfer from %s cancelled'),
                instance.creator().username)
        template = "serv/cancel_transfer_email.html"
        recipients = [instance.credits_debtor, instance.credits_payee]
    elif instance.status == 'd':
        subject=I18nString(_('Transfer of the service you did to %s confirmed'),
                instance.credits_debtor.email)
        template = "serv/done_transfer_email.html"
        recipients = [instance.credits_payee,]
    else:
        print "error, invalid updated transfer status " + instance.service.status
        return

    message = I18nString(template, {
        'site_url': '%s://%s' % (default_protocol, current_domain),
        'transfer': instance
    }, True)
    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipients,
        fail_silently=True)
Пример #11
0
    def __execute(self, task):
        '''
        Sends an email update when needed. We will send for each user only one
        update email each time, with all the the user update info. Updates will
        be sent in periods.
        '''
        for user in Profile.objects.all():
            if not user.email_updates:
                continue
            unread_messages = Message.objects.inbox_for(user).filter(read_at__isnull=True)
            unread_comments = Message.objects.public_inbox_for(user).\
                filter(read_at__isnull=True)
            transfers_pending = user.transfers_pending()
            send_update_data = [
                {"data": unread_messages, "date_field": "sent_at"},
                {"data": unread_comments, "date_field": "sent_at"},
                {"data": transfers_pending, "date_field": "request_date"},
            ]

            if self.__should_send_update(task, send_update_data):
                subject = I18nString(_(u"Updates from %s"), settings.SITE_NAME)
                default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')
                new_services = Service.objects.filter(is_active=True)
                paginator = Paginator(new_services, 5)
                new_services = paginator.page(1)

                message = I18nString("tasks/email_update.html", dict(
                    site_url='%s://%s' % (default_protocol, Site.objects.get_current().domain),
                    site_name=settings.SITE_NAME,
                    unread_messages=unread_messages,
                    unread_comments=unread_comments,
                    transfers_pending=transfers_pending,
                    new_services=new_services,
                    recipient=user,
                    context_instance=RequestContext(self.request)
                ), True)
                send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                    [user], fail_silently=True)
                return
Пример #12
0
def new_transfer_email(sender, instance, signal, *args, **kwargs):

    if 'created' not in kwargs or not kwargs['created']:
        update_transfer_email(sender, instance, signal, *args, **kwargs)
        return

    current_domain = Site.objects.get_current().domain
    default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')

    recipient = instance.recipient()
    if instance.service:
        subject=I18nString(_('New transfer request from %s'),
            instance.creator().username)
    else:
        subject=I18nString(_('New direct transfer from %s'),
            instance.creator().username)
    message = I18nString("serv/new_transfer_email.html", {
            'site_url': '%s://%s' % (default_protocol, current_domain),
            'transfer': instance
        }, True)
    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
        [recipient,], fail_silently=True)
Пример #13
0
def new_message_email(sender,
                      instance,
                      signal,
                      subject_prefix=_(u'New Message: %(subject)s'),
                      template_name="messages/new_message.html",
                      default_protocol=None,
                      *args,
                      **kwargs):
    """
    This function sends an email and is called via Django's signal framework.
    Optional arguments:
        ``template_name``: the template to use
        ``subject_prefix``: prefix for the email subject.
        ``default_protocol``: default protocol in site URL passed to template
    """
    if default_protocol is None:
        default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')

    if 'created' in kwargs and kwargs['created']:
        try:
            current_domain = Site.objects.get_current().domain
            subject = I18nString(subject_prefix, {'subject': instance.subject})
            message = I18nString(
                template_name, {
                    'site_url': '%s://%s' % (default_protocol, current_domain),
                    'message': instance,
                }, True)
            if instance.recipient.email != "":
                send_mail(subject,
                          message,
                          settings.DEFAULT_FROM_EMAIL, [
                              instance,
                          ],
                          fail_silently=True)
        except Exception, e:
            print e
            pass  #fail silently
Пример #14
0
    def POST(self):
        form = RegisterForm(self.request.POST)
        if not form.is_valid():
            return self.context_response('user/register.html', {'form': form,
            'current_tab': 'register'})

        # Register user
        new_user = form.save(commit=False)
        new_user.is_active = settings.AUTOACCEPT_REGISTRATION
        new_user.save()

        if not settings.AUTOACCEPT_REGISTRATION:
            # Send an email to admins and another to the user
            subject = I18nString(_("[%(site_name)s] User %(username)s joined"), {
                'site_name': settings.SITE_NAME,
                'username': new_user.username
            })
            message = I18nString(_("A new user has joined with the name %s . Please review his"
                " data and make it active."), new_user.username)
            mail_owners(subject, message)

            current_site = Site.objects.get_current()
            subject = I18nString(_("You have joined as %(username)s in %(site_name)s"), {
                'username': new_user.username,
                'site_name': settings.SITE_NAME
                })
            message = I18nString(_("Hello %(username)s!\n You just joined to http://%(url)s/ ."
                " Soon the creation of your user will be reviewed by one of our"
                " admins and if everything is ok, we will enable your user and you"
                " will be able to start participating in our community."
                u"\n\n- The team of %(site_name)s."), {
                    'username': new_user.username,
                    'url': current_site.domain,
                    'site_name': settings.SITE_NAME
                })
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                [new_user], fail_silently=True)

            self.flash(_("You just joined us, <strong>%(username)s</strong>. We"
                " have sent you an email to <strong>%(email)s</strong> confirming"
                " your inscription request. As soon as our admins review your"
                " request we will send you an email and you will be able to start"
                " to participate in our community.") % {
                    'username': new_user.username,
                    'email': new_user.email
                },
                title=_("User created successfully"))
        else:
            current_site = Site.objects.get_current()
            subject = I18nString(_("You have joined as %(username)s in %(site_name)s"), {
                'username': new_user.username,
                'site_name': settings.SITE_NAME
                })
            message = I18nString(_("Hello %(username)s!\n You just joined to http://%(url)s/ ."
                " Now you can start participating in our community!"
                u"\n\n- The team of %(site_name)s."), {
                    'username': new_user.username,
                    'url': current_site.domain,
                    'site_name': settings.SITE_NAME
                })
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                [new_user], fail_silently=True)

            self.flash(_("You just joined us, <strong>%(username)s</strong>. We"
                " have sent you a confirmation email to"
                " <strong>%(email)s</strong>. Now you can start to participate"
                " in our community.") % {
                    'username': new_user.username,
                    'email': new_user.email
                },
                title=_("User created successfully"))

        return redirect('main.views.index')