Example #1
0
def get_doc_template(context, template):
    lang = getattr(context['request'], 'LANG', 'en-US')
    if lang in settings.AMO_LANGUAGES:
        try:
            template = env.get_template('%s/%s.html' % (template, lang))
        except jinja2.TemplateNotFound:
            pass
        else:
            return jinja2.Markup(template.render(context))
    template = env.get_template('%s/en-US.html' % template)
    return jinja2.Markup(template.render(context))
Example #2
0
def device_list(product):
    device_types = product.device_types
    if device_types:
        t = env.get_template('detail/helpers/device_list.html')
        return jinja2.Markup(t.render({
            'device_types': device_types,
            'all_device_types': DEVICE_TYPES.values()}))
Example #3
0
def form_field(field,
               label=None,
               tag='div',
               req=None,
               opt=False,
               hint=False,
               tooltip=False,
               some_html=False,
               cc_startswith=None,
               cc_for=None,
               cc_maxlength=None,
               grid=False,
               cls=None,
               validate=False):
    attrs = {}
    # Add a `required` attribute so we can do form validation.
    # TODO(cvan): Write tests for kumar some day.
    if validate and field.field.required:
        attrs['required'] = ''
    c = dict(field=field,
             label=label or field.label,
             tag=tag,
             req=req,
             opt=opt,
             hint=hint,
             tooltip=tooltip,
             some_html=some_html,
             cc_startswith=cc_startswith,
             cc_for=cc_for,
             cc_maxlength=cc_maxlength,
             grid=grid,
             cls=cls,
             attrs=attrs)
    t = env.get_template('site/helpers/simple_field.html').render(c)
    return jinja2.Markup(t)
Example #4
0
def mkt_breadcrumbs(context, product=None, items=None, crumb_size=40,
                    add_default=True, cls=None):
    """
    Wrapper function for ``breadcrumbs``.

    **items**
        list of [(url, label)] to be inserted after Add-on.
    **product**
        Adds the App/Add-on name to the end of the trail.  If items are
        specified then the App/Add-on will be linked.
    **add_default**
        Prepends trail back to home when True.  Default is True.
    """
    if add_default:
        crumbs = [(reverse('home'), _('Home'))]
    else:
        crumbs = []

    if product:
        if items:
            url_ = product.get_detail_url()
        else:
            # The Product is the end of the trail.
            url_ = None
        crumbs += [(None, _('Apps')), (url_, product.name)]
    if items:
        crumbs.extend(items)

    if len(crumbs) == 1:
        crumbs = []

    crumbs = [(u, truncate(label, crumb_size)) for (u, label) in crumbs]
    t = env.get_template('site/helpers/breadcrumbs.html').render(
        {'breadcrumbs': crumbs, 'cls': cls})
    return jinja2.Markup(t)
Example #5
0
def device_list_es(product):
    device_types = [VISIBLE_DEVICE_TYPES[id] for id in product.device]
    t = env.get_template('detail/helpers/device_list.html')
    return jinja2.Markup(
        t.render({
            'device_types': device_types,
            'all_device_types': VISIBLE_DEVICE_TYPES.values()
        }))
Example #6
0
def send_html_mail_jinja(subject, html_template, text_template, context, *args,
                         **kwargs):
    """Sends HTML mail using a Jinja template with autoescaping turned off."""
    autoescape_orig = env.autoescape
    env.autoescape = False

    html_template = env.get_template(html_template)
    text_template = env.get_template(text_template)

    msg = send_mail(subject,
                    text_template.render(context),
                    html_message=html_template.render(context),
                    *args,
                    **kwargs)

    env.autoescape = autoescape_orig

    return msg
Example #7
0
def all_locales(addon, field_name, nl2br=False, prettify_empty=False):
    field = getattr(addon, field_name, None)
    if not addon or field is None:
        return
    trans = field.__class__.objects.filter(id=field.id,
                                           localized_string__isnull=False)
    ctx = dict(addon=addon, field=field, field_name=field_name,
               translations=trans, nl2br=nl2br, prettify_empty=prettify_empty)
    t = env.get_template('translations/all-locales.html')
    return jinja2.Markup(t.render(ctx))
Example #8
0
def file_tree(files, selected):
    depth = 0
    output = ['<ul class="root">']
    t = env.get_template('fileviewer/node.html')
    for k, v in files.items():
        if v['depth'] > depth:
            output.append('<ul class="js-hidden">')
        elif v['depth'] < depth:
            output.extend(['</ul>' for x in range(v['depth'], depth)])
        output.append(t.render({'value': v, 'selected': selected}))
        depth = v['depth']
    output.extend(['</ul>' for x in range(depth, -1, -1)])
    return jinja2.Markup('\n'.join(output))
Example #9
0
def file_tree(files, selected):
    depth = 0
    output = ['<ul class="root">']
    t = env.get_template('fileviewer/node.html')
    for k, v in files.items():
        if v['depth'] > depth:
            output.append('<ul class="js-hidden">')
        elif v['depth'] < depth:
            output.extend(['</ul>' for x in range(v['depth'], depth)])
        output.append(t.render({'value': v, 'selected': selected}))
        depth = v['depth']
    output.extend(['</ul>' for x in range(depth, -1, -1)])
    return jinja2.Markup('\n'.join(output))
Example #10
0
def send_mail_jinja(subject, template, context, *args, **kwargs):
    """Sends mail using a Jinja template with autoescaping turned off.

    Jinja is especially useful for sending email since it has whitespace
    control.
    """
    # Get a jinja environment so we can override autoescaping for text emails.
    autoescape_orig = env.autoescape
    env.autoescape = False
    template = env.get_template(template)
    msg = send_mail(subject, template.render(context), *args, **kwargs)
    env.autoescape = autoescape_orig
    return msg
Example #11
0
def app_header(context, app, page_type=''):
    t = env.get_template('lookup/helpers/app_header.html')

    is_author = acl.check_ownership(context['request'], app)
    is_operator = any(g.name == 'Operators' for g in context['request'].groups)
    is_admin = acl.action_allowed(context['request'], 'Users', 'Edit')
    is_staff = acl.action_allowed(context['request'], 'Apps', 'Configure')
    is_reviewer = acl.check_reviewer(context['request'])
    return jinja2.Markup(t.render({'app': app, 'page_type': page_type,
                                   'is_admin': is_admin, 'is_staff': is_staff,
                                   'is_reviewer': is_reviewer,
                                   'is_author': is_author,
                                   'is_operator': is_operator}))
Example #12
0
def form_field(field, label=None, tag='div', req=None, opt=False, hint=False,
               tooltip=False, some_html=False, cc_startswith=None, cc_for=None,
               cc_maxlength=None, grid=False, cls=None, validate=False):
    attrs = {}
    # Add a `required` attribute so we can do form validation.
    # TODO(cvan): Write tests for kumar some day.
    if validate and field.field.required:
        attrs['required'] = ''
    c = dict(field=field, label=label or field.label, tag=tag, req=req,
             opt=opt, hint=hint, tooltip=tooltip, some_html=some_html,
             cc_startswith=cc_startswith, cc_for=cc_for,
             cc_maxlength=cc_maxlength, grid=grid, cls=cls, attrs=attrs)
    t = env.get_template('site/helpers/simple_field.html').render(c)
    return jinja2.Markup(t)
Example #13
0
def all_locales(addon, field_name, nl2br=False, prettify_empty=False):
    field = getattr(addon, field_name, None)
    if not addon or field is None:
        return
    trans = field.__class__.objects.filter(id=field.id,
                                           localized_string__isnull=False)
    ctx = dict(addon=addon,
               field=field,
               field_name=field_name,
               translations=trans,
               nl2br=nl2br,
               prettify_empty=prettify_empty)
    t = env.get_template('translations/all-locales.html')
    return jinja2.Markup(t.render(ctx))
Example #14
0
def market_button(context, product, receipt_type=None, classes=None):
    request = context['request']
    purchased = False
    classes = (classes or []) + ['button', 'product']
    reviewer = receipt_type == 'reviewer'
    data_attrs = {
        'manifest_url': product.get_manifest_url(reviewer),
        'is_packaged': jsonlib.dumps(product.is_packaged)
    }

    installed = None

    if request.user.is_authenticated():
        installed_set = request.user.installed_set
        installed = installed_set.filter(addon=product).exists()

    # Handle premium apps.
    if product.has_premium():
        # User has purchased app.
        purchased = (request.user.is_authenticated()
                     and product.pk in request.user.purchase_ids())

        # App authors are able to install their apps free of charge.
        if (not purchased
                and request.check_ownership(product, require_author=True)):
            purchased = True

    if installed or purchased or not product.has_premium():
        label = _('Install')
    else:
        label = product.get_tier_name()

    # Free apps and purchased apps get active install buttons.
    if not product.is_premium() or purchased:
        classes.append('install')

    c = dict(product=product,
             label=label,
             purchased=purchased,
             data_attrs=data_attrs,
             classes=' '.join(classes))
    t = env.get_template('site/helpers/webapp_button.html')
    return jinja2.Markup(t.render(c))
Example #15
0
def progress(request, addon, step):
    steps = list(mkt.APP_STEPS)

    completed = []

    # TODO: Hide "Developer Account" step if user already read Dev Agreement.
    # if request.user.read_dev_agreement:
    #    steps = del_by_key(steps, 'terms')

    if addon:
        try:
            completed = addon.appsubmissionchecklist.get_completed()
        except AppSubmissionChecklist.DoesNotExist:
            pass

    # We don't yet have a checklist yet if we just read the Dev Agreement.
    if not completed and step and step != "terms":
        completed = ["terms"]

    c = dict(steps=steps, current=step, completed=completed)
    t = env.get_template("submit/helpers/progress.html").render(c)
    return jinja2.Markup(t)
Example #16
0
def progress(request, addon, step):
    steps = list(mkt.APP_STEPS)

    completed = []

    # TODO: Hide "Developer Account" step if user already read Dev Agreement.
    # if request.user.read_dev_agreement:
    #    steps = del_by_key(steps, 'terms')

    if addon:
        try:
            completed = addon.appsubmissionchecklist.get_completed()
        except AppSubmissionChecklist.DoesNotExist:
            pass

    # We don't yet have a checklist yet if we just read the Dev Agreement.
    if not completed and step and step != 'terms':
        completed = ['terms']

    c = dict(steps=steps, current=step, completed=completed)
    t = env.get_template('submit/helpers/progress.html').render(c)
    return jinja2.Markup(t)
Example #17
0
def market_button(context, product, receipt_type=None, classes=None):
    request = context['request']
    purchased = False
    classes = (classes or []) + ['button', 'product']
    reviewer = receipt_type == 'reviewer'
    data_attrs = {'manifest_url': product.get_manifest_url(reviewer),
                  'is_packaged': jsonlib.dumps(product.is_packaged)}

    installed = None

    if request.user.is_authenticated():
        installed_set = request.user.installed_set
        installed = installed_set.filter(addon=product).exists()

    # Handle premium apps.
    if product.has_premium():
        # User has purchased app.
        purchased = (request.user.is_authenticated() and
                     product.pk in request.user.purchase_ids())

        # App authors are able to install their apps free of charge.
        if (not purchased and
                request.check_ownership(product, require_author=True)):
            purchased = True

    if installed or purchased or not product.has_premium():
        label = _('Install')
    else:
        label = product.get_tier_name()

    # Free apps and purchased apps get active install buttons.
    if not product.is_premium() or purchased:
        classes.append('install')

    c = dict(product=product, label=label, purchased=purchased,
             data_attrs=data_attrs, classes=' '.join(classes))
    t = env.get_template('site/helpers/webapp_button.html')
    return jinja2.Markup(t.render(c))
Example #18
0
def no_results():
    # This prints a "No results found" message. That's all. Carry on.
    t = env.get_template('site/helpers/no_results.html').render()
    return jinja2.Markup(t)
Example #19
0
def impala_paginator(pager):
    t = env.get_template('site/impala_paginator.html')
    return jinja2.Markup(t.render({'pager': pager}))
Example #20
0
def mobile_reviewers_paginator(pager):
    # Paginator for non-responsive version of Reviewer Tools.
    t = env.get_template('reviewers/includes/reviewers_paginator.html')
    return jinja2.Markup(t.render({'pager': pager}))
Example #21
0
def timelabel(context, time):
    t = env.get_template('site/helpers/timelabel.html').render(
        {'time': time})
    return jinja2.Markup(t)
Example #22
0
def user_header(account, title, is_admin=False, page_type=''):
    t = env.get_template('lookup/helpers/user_header.html')
    return jinja2.Markup(t.render({'account': account, 'is_admin': is_admin,
                                   'title': title, 'page_type': page_type}))
Example #23
0
 def _mail(self, template, subject, context):
     template = env.get_template(template)
     body = template.render(context)
     send_mail(subject, body, settings.MARKETPLACE_EMAIL,
               [self.user.email], fail_silently=True)
Example #24
0
def mobile_reviewers_paginator(pager):
    # Paginator for non-responsive version of Reviewer Tools.
    t = env.get_template('reviewers/includes/reviewers_paginator.html')
    return jinja2.Markup(t.render({'pager': pager}))
Example #25
0
def website_header(context, website, page_type=''):
    t = env.get_template('lookup/helpers/website_header.html')

    return jinja2.Markup(t.render({'website': website,
                                   'page_type': page_type}))
Example #26
0
def device_list_es(product):
    device_types = [VISIBLE_DEVICE_TYPES[id] for id in product.device]
    t = env.get_template('detail/helpers/device_list.html')
    return jinja2.Markup(t.render({
        'device_types': device_types,
        'all_device_types': VISIBLE_DEVICE_TYPES.values()}))