Ejemplo n.º 1
0
def send_to_manager(request, order_id):
    order = Order.get_by_id(order_id)
    if not order:
        return render_to_response({
            'api':{
                'success': False,
                'msg': 'Order %s not found' % order_id
            }
        }, status=404)
    managers = Manager.query()
    if not managers.count():
        return render_json_response({
            'api':{
                'success': False,
                'msg': 'Managers not found.'
            }
        }, status=404)
    subject = render_to_string('order/msg/subject.html', {'order':order})
    msg = render_to_string('order/msg/body.html', {'order': order})

    email = mail.EmailMessage()
    email.subject = subject
    email.html = msg
    email.sender = settings.DEFAULT_MAIL_FROM
    for manager in managers:
       if manager.communication.email:
           email.to = manager.communication.email
           email.send()
    return render_json_response({
        'api':{
            'success': True,
            'msg': 'Order notifications were sent'
        }
    })
Ejemplo n.º 2
0
def send_order_to_manager(request, order_key):
    order = Order.get(order_key)

    gifts = []
    for gift in order.items:
        gifts.append(OrderItem.get(gift))

    subject = render_to_string('store/order2manager_subject.html', {'order_id':order.key().id()})
    subject = ''.join(subject.splitlines())
    message = render_to_string('store/order2manager_body.html', {'order': order, 'gifts':gifts})

    email = mail.EmailMessage()
    email.subject = subject
    email.html = message
    email.sender = settings.DEFAULT_MAIL_FROM

    try:
        if order.user and order.user.register_user and order.user.register_user.manager:
            email.to = order.user.register_user.manager.email
            email.send()
        else:
            managers = Manager.all()
            for manager in managers:
                email.to = manager.email
                email.send()
    except Exception:
        managers = Manager.all()
        for manager in managers:
            email.to = manager.email
            email.send()

    return Response("OK")
Ejemplo n.º 3
0
def send_reset_password_instruction(request, user_key, session_key):
  user = db.get(user_key)
  subject = render_to_string('auth/reset_password_instruction_subject.txt',
                             {'appname': settings.APP_NAME})
  message = render_to_string('auth/reset_password_instruction.txt',
                             {'appname': settings.APP_NAME,
                              'session_key': session_key})
  mail.send_mail(subject=subject, body=message,
                 sender=settings.DEFAULT_MAIL_FROM, to=user.email)
  return Response("OK")
Ejemplo n.º 4
0
def send_request_to_manager(request, request_key):
    req_request = RegistrationRequest.get(request_key)
    subject = render_to_string("auth5/request_2manager_subject.txt", {"id": req_request.key().id()})
    subject = "".join(subject.splitlines())
    message = render_to_string("auth5/request_2manager_body.txt", {"reg_request": req_request})
    if req_request.manager:
        mail.send_mail(subject=subject, body=message, sender=settings.DEFAULT_MAIL_FROM, to=req_request.manager.email)
    else:
        managers = Manager.all()
        for manager in managers:
            mail.send_mail(subject=subject, body=message, sender=settings.DEFAULT_MAIL_FROM, to=manager.email)
    return Response("OK")
Ejemplo n.º 5
0
def send_reset_password_instruction(request, user_key, session_key):
    user = db.get(user_key)
    subject = render_to_string('auth/reset_password_instruction_subject.txt',
                               {'appname': settings.APP_NAME})
    message = render_to_string('auth/reset_password_instruction.txt', {
        'appname': settings.APP_NAME,
        'session_key': session_key
    })
    mail.send_mail(subject=subject,
                   body=message,
                   sender=settings.DEFAULT_MAIL_FROM,
                   to=user.email)
    return Response("OK")
Ejemplo n.º 6
0
def send_registration_confirm(request, registration_key):
  from kay.registration.models import RegistrationProfile
  import_string(settings.AUTH_USER_MODEL)
  p = db.get(registration_key)
  subject = render_to_string('registration/activation_email_subject.txt',
                             {'appname': settings.APP_NAME})
  subject = ''.join(subject.splitlines())
  message = render_to_string(
    'registration/activation_email.txt',
    {'activation_key': registration_key,
     'appname': settings.APP_NAME})
  mail.send_mail(subject=subject, body=message,
                 sender=settings.DEFAULT_MAIL_FROM, to=p.parent().email)
  return Response("OK")
Ejemplo n.º 7
0
def send_refuse_to_user(request, request_id):
    req =RegistrationRequest.get_by_id(request_id)
    if not  req:
        logging.error("Registraion request #%s not found" % request_id)
        return Response('Ok')
    subject = render_to_string('reguest/admins/to_user_subject.txt')
    body = render_to_string('reguest/admins/refuse_to_user.txt',{
        'email': req.email
    })
    mail.send_mail(
        subject=subject,
        body=body,
        sender=settings.DEFAULT_MAIL_FROM,
        to=req.email)
    return Response('Ok')
Ejemplo n.º 8
0
def send_registration_confirm(request, registration_key):
    from kay.registration.models import RegistrationProfile
    import_string(settings.AUTH_USER_MODEL)
    p = db.get(registration_key)
    subject = render_to_string('registration/activation_email_subject.txt',
                               {'appname': settings.APP_NAME})
    subject = ''.join(subject.splitlines())
    message = render_to_string('registration/activation_email.txt', {
        'activation_key': registration_key,
        'appname': settings.APP_NAME
    })
    mail.send_mail(subject=subject,
                   body=message,
                   sender=settings.DEFAULT_MAIL_FROM,
                   to=p.parent().email)
    return Response("OK")
Ejemplo n.º 9
0
def send_request_to_manager(request, request_id):
    req = RegistrationRequest.get_by_id(request_id)
    if not req:
        logging.error("Registraion request #%s not found" % request_id)
        return Response('Ok')
    subject = render_to_string('reguest/admins/req_to_mng_subject.txt', {
        'id':request_id})
    body = render_to_string('reguest/admins/req_to_mng_body.txt', {
        'reg_request': req
    })
    managers = Manager.query()
    for manager in managers:
        if manager.communication.email:
            mail.send_mail(
                subject=subject, body=body,
                sender=settings.DEFAULT_MAIL_FROM,
                to=manager.communication.email)
    return Response('Ok')
Ejemplo n.º 10
0
Archivo: views.py Proyecto: gmist/f-toy
def send_order_to_manager(request, order_key):
    order = Order.get(order_key)

    subject = render_to_string('cart/notifications/order2manager_subject.html', {'order_id':order.key().id()})
    subject = ''.join(subject.splitlines())
    message = render_to_string('cart/notifications/order2manager_body.html', {'order': order})

    email = mail.EmailMessage()
    email.subject = subject
    email.html = message
    email.sender = settings.DEFAULT_MAIL_FROM

    managers = DatastoreUser.all()
    for manager in managers:
        if manager.email:
            email.to = manager.email
            email.send()

    return Response("OK")
Ejemplo n.º 11
0
def render_to_pdf(template_name, params,
                  font_resolver=font_resolver,
                  image_resolver=image_resolver):
    """Renders PDF from RML, which is rendered from a Django template.
    """
    rml = render_to_string(template_name, params).encode('utf-8')
    try:
        pdf = rml2pdf(rml, font_resolver, image_resolver)
    except Exception, e:
        raise TemplateError(str(e))
Ejemplo n.º 12
0
def render_to_pdf(template_name,
                  params,
                  font_resolver=font_resolver,
                  image_resolver=image_resolver):
    """Renders PDF from RML, which is rendered from a Django template.
    """
    rml = render_to_string(template_name, params).encode('utf-8')
    try:
        pdf = rml2pdf(rml, font_resolver, image_resolver)
    except Exception, e:
        raise TemplateError(str(e))
Ejemplo n.º 13
0
def sitemap(request, section=None):
  logging.info('ff')
  if section is not None:
    if section not in settings.SITEMAPS:
      return NotFound("No sitemap for section: %s" % section)
  else:
    return NotFound()
  logging.info('zz')
  sitemap = import_string(settings.SITEMAPS[section])()

  xml = render_to_string('kay_sitemap/sitemap.xml', {'urlset': sitemap.get_urls()})
  return Response(xml, mimetype='application/xml')
Ejemplo n.º 14
0
def index(request):
    form = RegFormForm()
    if request.method == 'POST':
        if request.form and form.validate(request.form):
            tmp = form.save(commit=False)
            if not tmp.address:
                tmp.put()
                return render_to_response('index/thanks.html')
        else:
            return render_to_response('index/index.html', {'form':form.as_widget()})
    cache_page = memcache.get('index_page')
    if not cache_page:
        cache_page = render_to_string('index/index.html', {'form':form.as_widget()})
        memcache.add('index_page', cache_page, 24 * 60 * 60)
    return Response(cache_page, content_type="text/html; charset=utf-8")
Ejemplo n.º 15
0
def send_newsletter_task(request, user_key, newsletter_key):
    newsletter = Newsletter.get(newsletter_key)
    managers = []
    message = mail.EmailMessage(sender=settings.DEFAULT_MAIL_FROM, subject=newsletter.title)
    user = UserProfile.get(user_key)
    message.to = user.email
    if not message.to:
        return Response("Ok")

    gifts = []
    gifts_images = {}
    if newsletter.gifts:
        gifts_split = newsletter.gifts.split(",")
        for gift in gifts_split:
            try:
                gift = gift.strip()
                obj = Gift.all().filter("uid =", gift).get()
                if obj:
                    gifts.append(obj)
                    if obj.main_thumb:
                        try:
                            img = ThumbImage.get(obj.main_thumb)
                            img = Image.get(img.thumb_200x200)
                            if img:
                                gifts_images[obj.uid] = base64.b64encode(str(img.image))
                        except Exception:
                            pass
            except Exception:
                pass

    message_text = render_to_string(
        "postman/send_newsletter.html",
        {"newsletter": newsletter, "gifts": gifts, "managers": managers, "gifts_images": gifts_images},
    )
    message.html = message_text
    attachments = []
    for file_key in newsletter.n_price_list:
        file_ = File.get(file_key)
        if file_ and file_.blob_key:
            bi = blobstore.BlobInfo.get(file_.blob_key)
            if bi:
                attachments.append(("%s" % file_.title_filename, bi.open().read()))
    message.attachments = attachments
    message.send()
    return Response("OK")
Ejemplo n.º 16
0
 def create_sitemap(cls,query=None,cursor=None,article_ids=None):
     from google.appengine.ext import deferred
     from kay.utils import render_to_string
     if query is None:
         query=cls.all()
     if cursor is not None:
         query.with_cursor(cursor)
     if article_ids is None:
         article_ids=list()
     if query.count(limit=1):
         for q in query.run(limit=50):
             article_ids.extend(q.article_id)
         cursor=query.cursor()
         deferred.defer(cls.create_sitemap,query,cursor,article_ids)
     else:
         sitemaps=list()
         for id in article_id:
             sitemaps.append({'loc':'http://www.2han.be/detail/%s'%id,})
         content = render_to_string('core/sitemap.xml', {
             'sitemaps':sitemaps
         })
         deferred.defer(TextFileData.set_sitemap,content)
Ejemplo n.º 17
0
 def html(clear_subs_, active_category_):
     return render_to_string("catalogue.html", {"active_category": active_category_, "subcategories": clear_subs_})
Ejemplo n.º 18
0
def render_template(template, template_vals):
    """
    render_to_string returns a unicode string, the rendered template needs to
    be a string to be stored in BlobProperty
    """
    return render_to_string(template, template_vals)
Ejemplo n.º 19
0
  def get(self):
    from kay.utils import render_to_string

    version_filter = self.request.args.get('versions', 'all')
    sender = self.request.args.get('sender', settings.DEFAULT_MAIL_FROM)
    to = self.request.args.get('to', None)
    report_date = self.request.args.get('date', None)
    if report_date:
      yesterday = datetime.date(*[int(x) for x in report_date.split('-')])
    else:
      yesterday = datetime.date.today() - datetime.timedelta(days=1)
    app_id = os.environ['APPLICATION_ID']
    version = os.environ['CURRENT_VERSION_ID']
    major_version, minor_version = version.rsplit('.', 1)
    minor_version = int(minor_version)
    max_results = int(self.request.args.get('max_results',
                                                self.DEFAULT_MAX_RESULTS))
    query_args = {
      'query_date': yesterday,
      'major_version': major_version,
    }
    if version_filter.lower() == 'latest':
      query_args['minor_version'] = minor_version

    try:
      exceptions = GetQuery(order='-minor_version', **query_args).fetch(max_results)
    except db.NeedIndexError:
      exceptions = GetQuery(**query_args).fetch(max_results)

    if exceptions:
      # Format the exceptions and generate the report

      exceptions.sort(key=lambda e: (e.minor_version, -e.count))
      versions = [(minor, list(excs)) for minor, excs
                    in itertools.groupby(exceptions, lambda e: e.minor_version)]

      template_values = {
        'version_filter': version_filter,
        'version_count': len(versions),
        'exception_count': sum(len(excs) for _, excs in versions),
        'occurrence_count': sum(y.count for x in versions for y in x[1]),
        'app_id': app_id,
        'major_version': major_version,
        'date': yesterday,
        'versions': versions,
      }
      report = render_to_string('ereporter/report.html', template_values)
      report_text = render_to_string('ereporter/report.txt', template_values)

      if settings.DEBUG:
        return Response(report, mimetype="text/html")
      else:
        # Send the error mail.
        subject = ('Daily exception report for app "%s", major version "%s"'
                   % (app_id, major_version))
        mail_args = {
            'subject': subject,
            'body': report_text,
            'html': report,
        }
        if to:
          mail_args['to'] = to
          mail_args['sender'] = sender
          mail.send_mail(**mail_args)
        else:
          from kay.mail import mail_admins
          mail_admins(**mail_args)

      if isTrue(self.request.args.get('delete', 'true')):
        db.delete(exceptions)

    return Response()
Ejemplo n.º 20
0
    def get(self):
        from kay.utils import render_to_string

        version_filter = self.request.args.get('versions', 'all')
        sender = self.request.args.get('sender', settings.DEFAULT_MAIL_FROM)
        to = self.request.args.get('to', None)
        report_date = self.request.args.get('date', None)
        if report_date:
            yesterday = datetime.date(
                *[int(x) for x in report_date.split('-')])
        else:
            yesterday = datetime.date.today() - datetime.timedelta(days=1)
        app_id = os.environ['APPLICATION_ID']
        version = os.environ['CURRENT_VERSION_ID']
        major_version, minor_version = version.rsplit('.', 1)
        minor_version = int(minor_version)
        max_results = int(
            self.request.args.get('max_results', self.DEFAULT_MAX_RESULTS))
        query_args = {
            'query_date': yesterday,
            'major_version': major_version,
        }
        if version_filter.lower() == 'latest':
            query_args['minor_version'] = minor_version

        try:
            exceptions = GetQuery(order='-minor_version',
                                  **query_args).fetch(max_results)
        except db.NeedIndexError:
            exceptions = GetQuery(**query_args).fetch(max_results)

        if exceptions:
            # Format the exceptions and generate the report

            exceptions.sort(key=lambda e: (e.minor_version, -e.count))
            versions = [(minor, list(excs))
                        for minor, excs in itertools.groupby(
                            exceptions, lambda e: e.minor_version)]

            template_values = {
                'version_filter': version_filter,
                'version_count': len(versions),
                'exception_count': sum(len(excs) for _, excs in versions),
                'occurrence_count':
                sum(y.count for x in versions for y in x[1]),
                'app_id': app_id,
                'major_version': major_version,
                'date': yesterday,
                'versions': versions,
            }
            report = render_to_string('ereporter/report.html', template_values)
            report_text = render_to_string('ereporter/report.txt',
                                           template_values)

            if settings.DEBUG:
                return Response(report, mimetype="text/html")
            else:
                # Send the error mail.
                subject = (
                    'Daily exception report for app "%s", major version "%s"' %
                    (app_id, major_version))
                mail_args = {
                    'subject': subject,
                    'body': report_text,
                    'html': report,
                }
                if to:
                    mail_args['to'] = to
                    mail_args['sender'] = sender
                    mail.send_mail(**mail_args)
                else:
                    from kay.mail import mail_admins
                    mail_admins(**mail_args)

            if isTrue(self.request.args.get('delete', 'true')):
                db.delete(exceptions)

        return Response()
Ejemplo n.º 21
0
def send_newsletter_task2(request, email, newsletter_key_id):
    newsletter = Newsletter2.get_by_id(newsletter_key_id)

    managers = []
    for mgr_id in newsletter.managers:
        mgr = Manager.get_by_id(mgr_id)
        if mgr:
            managers.append(mgr)

    message = mail.EmailMessage(sender=settings.DEFAULT_MAIL_FROM, subject=newsletter.title)
    message.to = email
    if not message.to:
        return Response("Ok")
    mangers_emails = [manager.email for manager in managers]
    if mangers_emails:
        message.reply_to = ",".join(mangers_emails)

    gifts = []
    gifts_images = {}
    if newsletter.gifts:
        gifts_split = newsletter.gifts.split(",")
        for gift in gifts_split:
            try:
                gift = gift.strip()
                obj = Gift.all().filter("uid =", gift).get()
                if obj:
                    gifts.append(obj)
                    if obj.main_thumb:
                        try:
                            img = ThumbImage.get(obj.main_thumb)
                            img = Image.get(img.thumb_200x200)
                            if img:
                                gifts_images[obj.uid] = base64.b64encode(str(img.image))
                        except Exception:
                            pass
            except Exception:
                pass

    message_text = render_to_string(
        "postman/send_newsletter2.html",
        {"newsletter": newsletter, "gifts": gifts, "managers": managers, "gifts_images": gifts_images},
    )
    message.html = message_text
    attachments = []
    for file_key in newsletter.n_price_list:
        file_ = File.get(file_key)
        if file_ and file_.blob_key:
            bi = blobstore.BlobInfo.get(file_.blob_key)
            if bi:
                attachments.append(("%s" % file_.title_filename, bi.open().read()))
    if attachments:
        message.attachments = attachments
    try:
        message.send()
    except apiproxy_errors.OverQuotaError:

        def txn():
            taskqueue.add(
                url=url_for("postman/send_newsletter_task2", email=email, newsletter_key_id=newsletter_key_id),
                transactional=True,
            )

        db.run_in_transaction(txn)
    return Response("OK")
Ejemplo n.º 22
0
    def get(self):
        from kay.utils import render_to_string

        version_filter = self.request.args.get("versions", "all")
        sender = self.request.args.get("sender", settings.DEFAULT_MAIL_FROM)
        to = self.request.args.get("to", None)
        report_date = self.request.args.get("date", None)
        if report_date:
            yesterday = datetime.date(*[int(x) for x in report_date.split("-")])
        else:
            yesterday = datetime.date.today() - datetime.timedelta(days=1)
        app_id = os.environ["APPLICATION_ID"]
        version = os.environ["CURRENT_VERSION_ID"]
        major_version, minor_version = version.rsplit(".", 1)
        minor_version = int(minor_version)
        max_results = int(self.request.args.get("max_results", self.DEFAULT_MAX_RESULTS))
        query_args = {"query_date": yesterday, "major_version": major_version}
        if version_filter.lower() == "latest":
            query_args["minor_version"] = minor_version

        try:
            exceptions = GetQuery(order="-minor_version", **query_args).fetch(max_results)
        except db.NeedIndexError:
            exceptions = GetQuery(**query_args).fetch(max_results)

        if exceptions:
            # Format the exceptions and generate the report

            exceptions.sort(key=lambda e: (e.minor_version, -e.count))
            versions = [(minor, list(excs)) for minor, excs in itertools.groupby(exceptions, lambda e: e.minor_version)]

            template_values = {
                "version_filter": version_filter,
                "version_count": len(versions),
                "exception_count": sum(len(excs) for _, excs in versions),
                "occurrence_count": sum(y.count for x in versions for y in x[1]),
                "app_id": app_id,
                "major_version": major_version,
                "date": yesterday,
                "versions": versions,
            }
            report = render_to_string("ereporter/report.html", template_values)
            report_text = render_to_string("ereporter/report.txt", template_values)

            if settings.DEBUG:
                return Response(report, mimetype="text/html")
            else:
                # Send the error mail.
                subject = 'Daily exception report for app "%s", major version "%s"' % (app_id, major_version)

                if to:
                    mail.send_mail(to=to, sender=sender, subject=subject, body=report_text, html=report)
                else:
                    from kay.mail import mail_admins

                    mail_admins(subject=subject, message=report_text)

            if isTrue(self.request.args.get("delete", "true")):
                db.delete(exceptions)

        return Response()
Ejemplo n.º 23
0
def index(request):
  sites = []
  for section in settings.SITEMAPS.keys():
    sites.append(url_for('sitemap/sitemap', section=section, _external=True))
  xml = render_to_string('kay_sitemap/sitemap_index.xml', {'sitemaps': sites})
  return Response(xml, mimetype='application/xml')
Ejemplo n.º 24
0
def render_paginator(paginator_page):
    return render_to_string('app/paginator.html', {'page': paginator_page})
Ejemplo n.º 25
0
def index(request):
  logging.info(render_to_string('mainapp/index.html', {'message': 'Hello'}))
  return render_to_response('mainapp/index.html', {'message': 'Hello'})