Exemplo n.º 1
0
def build_subsribe_query(subscribe_id):
    try:
        subscribe = Subscribe.objects.get(pk=subscribe_id)
    except Exception:
        raise Exception("Subscribe not found")
    usersubscribes = UserSubscribes.objects.filter(subscribe=subscribe)
    subscribe.last_send_date = datetime.now()
    if usersubscribes.count() > 0:
        objects = subscribe.get_modelname().objects.all()
        data_objects = serializers.serialize("json", objects)
        message = {"objects": json.loads(data_objects)}
        mail_ids = []
        for usersub in usersubscribes:
            data_user = {"unsubscribe": usersub.unsubscribe_link, "username": usersub.user.username}
            vars = message
            vars.update({"user": data_user})
            mail = create_mailqueue(
                subject=subscribe.subject,
                template=subscribe.message,
                send_to=usersub.user.email,
                content_type=subscribe.content_type,
                message=vars,
            )
            mail_ids.append(mail.id)
        send_concrete_mailqueue.delay(mail_ids)
Exemplo n.º 2
0
def send_email(subject,template,send_to,content_type,message=None,send_from=None,attachment=None):
    attach_t = {}
    if attachment is not None:
        att_file_path = ATTACHMENT_PATH + u'/' + attachment['att_file_name']
        with open(att_file_path, 'w') as f:
            f.write(attachment['att_file'])
            f.closed
            attach_t.update({'att_file_name': attachment['att_file_name'], 'att_file_path': att_file_path, 'att_file_type': attachment['att_file_type']})

    from sq_subscribe.mailqueue.tasks import send_concrete_mailqueue
    mail = create_mailqueue(subject,template,send_to,content_type,message,send_from,attach_t)
    #TODO нужно придумать, как сделать проверку - отправлять ли письмо по таску или мгновенно.
    send_concrete_mailqueue.delay([mail.id])
Exemplo n.º 3
0
 def create_sometime_subscribe(self,users):
     content_type = self.content_type if self.content_type == 'html' else 'plain'
     template = load_template(content_type,type='sometime')
     self.template = template
     self.save()
     if users is not None:
         message = {'message':self.message}
         mail_ids = []
         for user in users:
             data_user = {'username':user.username}
             vars = message
             vars.update({'user':data_user})
             mail = create_mailqueue(subject=self.subject,template=self.template,send_to=user.email,
                              content_type=self.content_type,message=vars)
             mail_ids.append(mail.id)
         send_concrete_mailqueue.delay(mail_ids)
     if self.delete_after_sending:
         self.delete()
     return self
Exemplo n.º 4
0
def send_email(subject,template,send_to,content_type,message=None,send_from=None,attachment=None):
    from django.conf import settings
    from apps.user.models import User
    try:
        user = User.objects.get(email=send_to)
    except:
        user = None
    import datetime
    import pytz
    datestart = datetime.datetime(year=2013, month=12, day=2, hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.utc)
    if not settings.DEBUG or user is None or (settings.DEBUG and (user.is_staff or user.date_joined > datestart)):
        attach_t = {}
        if attachment is not None:
            att_file_path = ATTACHMENT_PATH + u'/' + attachment['att_file_name']
            with open(att_file_path, 'w') as f:
                f.write(attachment['att_file'])
                f.closed
                attach_t.update({'att_file_name': attachment['att_file_name'], 'att_file_path': att_file_path, 'att_file_type': attachment['att_file_type']})

        from sq_subscribe.mailqueue.tasks import send_concrete_mailqueue
        mail = create_mailqueue(subject,template,send_to,content_type,message,send_from,attach_t)
        #TODO нужно придумать, как сделать проверку - отправлять ли письмо по таску или мгновенно.
        send_concrete_mailqueue.delay([mail.id])