Пример #1
0
 def save(self, domain_override=None, email_template_name='registration/password_reset_email.html',
          use_https=False, token_generator=default_token_generator):
     """
     Generates a one-use only link for resetting password and sends to the user
     """
     for user in self.users_cache:
         if not domain_override:
             current_site = Site.objects.get_current()
             site_name = current_site.name
             domain = current_site.domain
         else:
             site_name = domain = domain_override
         t = loader.get_template(email_template_name)
         c = {
             'email': user.email,
             'domain': domain,
             'site_name': site_name,
             'uid': int_to_base36(user.id),
             'user': user,
             'token': token_generator.make_token(user),
             'protocol': use_https and 'https' or 'http',
         }
         task = SendEmailTask(dict(subject=u"[%s] パスワードをリセット" % site_name, 
                                   body=t.render(Context(c)), 
                                   from_address=settings.EMAIL_FROM,
                                   to_list=[user.email]))
         get_taskqueue().send_task(task, queue_name=settings.QUEUENAME_EMAIL)
Пример #2
0
def mail_recipe(request, recipe_id=None):
    """
    指定されたIDのレシピの情報をPOSTのalter_emailで指定されたアドレスにメールで送信します。
    ログインユーザだけが行うことができます。
    alter_emailの値がprofile.alter_emailと異なる場合はprofile.alter_emailを変更します。
    
    @param recipe_id: レシピID
    @return: 302レスポンス (ログインページへ。ログインしていない場合)
    @return: 404レスポンス (指定されたIDのレシピが存在しない場合)
    @return: 200レスポンス (レシピのJSONデータを返す。成功した場合)
    """
    site = Site.objects.get_current()
    recipe = get_object_or_404(Recipe, pk=recipe_id)
    profile = request.user.get_profile()
    email = request.POST.get("alter_email", profile.alter_email)
    if email != profile.alter_email:
        profile.alter_email = email
        profile.save()
    c = Context({"user":request.user, "recipe":recipe})
    t = loader.get_template("recipes/email/mail_recipe.txt")
    subject = u"[%s] %s" % (site.name, recipe.name)
    body = t.render(c)
    task = SendEmailTask(dict(subject=subject, body=body, 
                              from_address=settings.EMAIL_FROM,
                              to_list=[email]))
    get_taskqueue().send_task(task, queue_name=settings.QUEUENAME_EMAIL)
    json = serializers.serialize("json", [recipe]) # TODO: 情報削減
    return HttpResponse(json, mimetype="application/json")
Пример #3
0
def send_email(template_path, context, subject, to_list):
    """
    メールを作成し、タスクに登録します。(この関数はビュー関数ではありません。)
    """
    t = loader.get_template(template_path)
    body = t.render(context)
    task = SendEmailTask(dict(subject=subject, body=body, 
                              from_address=settings.EMAIL_FROM,
                              to_list=to_list))
    get_taskqueue().send_task(task, queue_name=settings.QUEUENAME_EMAIL)
Пример #4
0
def send_task(method_name, sender, **kwargs):
    instance = kwargs.get("instance")
    taskmaker = getattr(instance, method_name, None)
    if taskmaker is not None:
        task = taskmaker()
        if type(task) in (list, tuple):
            queue_name = task[1]
            task = task[0]
        else:
            queue_name = sender.__module__
        if task: get_taskqueue().send_task(task, queue_name)
Пример #5
0
def _create_unique_photo_path(instance, filename, path):
    if instance.photo:
        # instance.photo.delete()
        if instance.photo_s3:
            get_taskqueue().send_task(DeleteS3Task({"name":instance.photo_s3.name}),
                                      settings.QUEUENAME_SENDS3)
        instance.photo_s3 = None
        instance.photo_s3_sync = False
        get_taskqueue().send_task(SyncS3Task.from_model(instance), settings.QUEUENAME_SENDS3)
    return os.path.join(path, 
            u"%s%s" % (uuid.uuid4(), os.path.splitext(filename)[1]))
Пример #6
0
 def make_icon_filepath(self, filename):
     ext = os.path.splitext(filename)[1]
     path = "users/icon/%s%s" % (self.user.id, ext)
     self.icon.storage.delete(path)
     if self.icon_s3:
         get_taskqueue().send_task(DeleteS3Task({"name":path}),
                                   settings.QUEUENAME_SENDS3)
     self.icon_s3 = None
     self.icon_s3_sync = False
     get_taskqueue().send_task(SyncS3Task.from_model(self), settings.QUEUENAME_SENDS3)
     return path
Пример #7
0
def send_email(template_path, cdata, subject, to_list):
    """
    メールを作成し、タスクに登録します。
    """
    from django.conf import settings
    from django.template import loader, Context
    from recipebook.maricilib.django.apps.taskqueue.queue import get_taskqueue
    from recipebook.maricilib.django.apps.taskqueue.tasks import SendEmailTask
    
    t = loader.get_template(template_path)
    body = t.render(Context(cdata))
    task = SendEmailTask(dict(subject=subject, body=body, 
                              from_address=settings.EMAIL_FROM,
                              to_list=to_list))
    get_taskqueue().send_task(task, queue_name=settings.QUEUENAME_EMAIL)
Пример #8
0
    def handle(self, *args, **opts):
        start_time = datetime.now()

        taskqueue = get_taskqueue()
        queue_name = default_queue
        if 0 < len(args):
            queue_name = args[0]

        tasklogs = {}
        for task in taskqueue.receive_tasks(queue_name):
            name, module, kwargs = task.get_task_info()
            if not tasklogs.has_key(name):
                log = DoTaskLog()
                log.start = start_time
                log.task_name = name
                log.module_name = module
                log.success_count = 0
                log.error_count = 0
                tasklogs.update({name:log})
            try:
                task.do()
            except Exception, e:
                # エラー件数をタスク別にカウント
                # エラーログを保存
                log.error_count+=1
                elog = ErrorLog()
                elog.task_name = name
                elog.module_name = module
                elog.args = str(task.kwargs)
                elog.text = str(e)
                elog.reported_at = datetime.now()
                elog.save()
            else:
                # 成功件数をタスク別にカウント
                log.success_count+=1
Пример #9
0
def mail_recipe_template(request, contest_id=None):
    """
    レシピテンプレートをPOSTのalter_emailで指定されたアドレスにメールで送信します。
    ログインユーザだけが行うことができます。
    alter_emailの値がprofile.alter_emailと異なる場合はprofile.alter_emailを変更します。
    
    @param contest_id: お題ID
    @return: 302レスポンス (ログインページへ。ログインしていない場合)
    @return: 404レスポンス (指定されたIDのお題が存在しない場合)
    @return: 200レスポンス (レシピのJSONデータを返す。成功した場合)
    """
    site = Site.objects.get_current()
    profile = request.user.get_profile()
    contest = get_object_or_404(Contest, pk=contest_id) if contest_id else None
    email = request.POST.get("alter_email", profile.alter_email)
    if email != profile.alter_email:
        profile.alter_email = email
    if profile.has_available_token():
        profile.token_issued_at = datetime.now()
    else:
        profile.issue_recipe_token()
    profile.save()
    c = Context({"user":request.user, "contest":contest,
                 "token":profile.recipe_token})
    t = loader.get_template("recipes/email/recipe_template.txt")
    if contest:
        subject = u"[%s] %s へのレシピ投稿" % (site.name, contest.name)
    else:
        subject = u"[%s] レシピ投稿" % site.name
    body = t.render(c)
    task = SendEmailTask(dict(subject=subject, body=body, 
                              from_address=settings.EMAIL_FROM,
                              to_list=[email]))
    get_taskqueue().send_task(task, queue_name=settings.QUEUENAME_EMAIL)
    json = serializers.serialize("json", [])
    return HttpResponse(json, mimetype="application/json")