Beispiel #1
0
def widgets(request, project):
    obj = get_project(request, project)

    # Parse possible language selection
    form = EngageForm(request.user, obj, request.GET)
    lang = None
    component = None
    if form.is_valid():
        if form.cleaned_data["lang"]:
            lang = Language.objects.get(code=form.cleaned_data["lang"]).code
        if form.cleaned_data["component"]:
            component = Component.objects.get(
                slug=form.cleaned_data["component"], project=obj
            ).slug

    kwargs = {"project": obj.slug}
    if lang is not None:
        kwargs["lang"] = lang
    engage_url = get_site_url(reverse("engage", kwargs=kwargs))
    engage_link = mark_safe(
        '<a href="{0}" id="engage-link">{0}</a>'.format(escape(engage_url))
    )
    widget_base_url = get_site_url(reverse("widgets", kwargs={"project": obj.slug}))
    widget_list = []
    for widget_name in sorted(WIDGETS, key=widgets_sorter):
        widget_class = WIDGETS[widget_name]
        if not widget_class.show:
            continue
        color_list = []
        for color in widget_class.colors:
            kwargs = {
                "project": obj.slug,
                "widget": widget_name,
                "color": color,
                "extension": widget_class.extension,
            }
            if lang is not None:
                kwargs["lang"] = lang
            if component is not None:
                kwargs["component"] = component
            color_url = reverse("widget-image", kwargs=kwargs)
            color_list.append({"name": color, "url": get_site_url(color_url)})
        widget_list.append(
            {"name": widget_name, "colors": color_list, "verbose": widget_class.verbose}
        )

    return render(
        request,
        "widgets.html",
        {
            "engage_url": engage_url,
            "engage_link": engage_link,
            "widget_list": widget_list,
            "widget_base_url": widget_base_url,
            "object": obj,
            "project": obj,
            "image_src": widget_list[0]["colors"][0]["url"],
            "form": form,
        },
    )
Beispiel #2
0
def widgets(request, project):
    obj = get_project(request, project)

    # Parse possible language selection
    form = EngageForm(obj, request.GET)
    lang = None
    component = None
    if form.is_valid():
        if form.cleaned_data['lang']:
            lang = Language.objects.get(code=form.cleaned_data['lang']).code
        if form.cleaned_data['component']:
            component = SubProject.objects.get(
                slug=form.cleaned_data['component'], project=obj).slug

    kwargs = {'project': obj.slug}
    if lang is not None:
        kwargs['lang'] = lang
    engage_url = get_site_url(reverse('engage', kwargs=kwargs))
    engage_url_track = '{0}?utm_source=widget'.format(engage_url)
    widget_base_url = get_site_url(
        reverse('widgets', kwargs={'project': obj.slug}))
    widget_list = []
    for widget_name in sorted(WIDGETS, key=widgets_sorter):
        widget_class = WIDGETS[widget_name]
        if not widget_class.show:
            continue
        color_list = []
        for color in widget_class.colors:
            kwargs = {
                'project': obj.slug,
                'widget': widget_name,
                'color': color,
                'extension': widget_class.extension,
            }
            if lang is not None:
                kwargs['lang'] = lang
            if component is not None:
                kwargs['subproject'] = component
            color_url = reverse('widget-image', kwargs=kwargs)
            color_list.append({
                'name': color,
                'url': get_site_url(color_url),
            })
        widget_list.append({
            'name': widget_name,
            'colors': color_list,
        })

    return render(
        request, 'widgets.html', {
            'engage_url': engage_url,
            'engage_url_track': engage_url_track,
            'widget_list': widget_list,
            'widget_base_url': widget_base_url,
            'object': obj,
            'project': obj,
            'image_src': widget_list[0]['colors'][0]['url'],
            'form': form,
        })
Beispiel #3
0
def widgets(request, project):
    obj = get_project(request, project)

    # Parse possible language selection
    form = EngageForm(obj, request.GET)
    lang = None
    component = None
    if form.is_valid():
        if form.cleaned_data['lang']:
            lang = Language.objects.get(code=form.cleaned_data['lang']).code
        if form.cleaned_data['component']:
            component = Component.objects.get(
                slug=form.cleaned_data['component'],
                project=obj
            ).slug

    kwargs = {'project': obj.slug}
    if lang is not None:
        kwargs['lang'] = lang
    engage_url = get_site_url(reverse('engage', kwargs=kwargs))
    engage_url_track = '{0}?utm_source=widget'.format(engage_url)
    engage_link = mark_safe(
        '<a href="{0}" id="engage-link">{0}</a>'.format(escape(engage_url))
    )
    widget_base_url = get_site_url(
        reverse('widgets', kwargs={'project': obj.slug})
    )
    widget_list = []
    for widget_name in sorted(WIDGETS, key=widgets_sorter):
        widget_class = WIDGETS[widget_name]
        if not widget_class.show:
            continue
        color_list = []
        for color in widget_class.colors:
            kwargs = {
                'project': obj.slug,
                'widget': widget_name,
                'color': color,
                'extension': widget_class.extension,
            }
            if lang is not None:
                kwargs['lang'] = lang
            if component is not None:
                kwargs['component'] = component
            color_url = reverse('widget-image', kwargs=kwargs)
            color_list.append({
                'name': color,
                'url': get_site_url(color_url),
            })
        widget_list.append({
            'name': widget_name,
            'colors': color_list,
        })

    return render(
        request,
        'widgets.html',
        {
            'engage_url': engage_url,
            'engage_link': engage_link,
            'engage_url_track': engage_url_track,
            'widget_list': widget_list,
            'widget_base_url': widget_base_url,
            'object': obj,
            'project': obj,
            'image_src': widget_list[0]['colors'][0]['url'],
            'form': form,
        }
    )