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

    # Parse possible language selection
    form = EnageLanguageForm(obj, request.GET)
    lang = None
    if form.is_valid() and form.cleaned_data["lang"] != "":
        lang = Language.objects.get(code=form.cleaned_data["lang"])

    if lang is None:
        engage_base = reverse("engage", kwargs={"project": obj.slug})
    else:
        engage_base = reverse("engage-lang", kwargs={"project": obj.slug, "lang": lang.code})
    engage_url = get_site_url(engage_base)
    engage_url_track = "%s?utm_source=widget" % engage_url
    widget_base_url = get_site_url(reverse("widgets", kwargs={"project": obj.slug}))
    widget_list = []
    for widget_name in WIDGETS:
        widget_class = WIDGETS[widget_name]
        color_list = []
        for color in widget_class.colors:
            if lang is None:
                color_url = reverse("widget-image", kwargs={"project": obj.slug, "widget": widget_name, "color": color})
            else:
                color_url = reverse(
                    "widget-image-lang",
                    kwargs={"project": obj.slug, "widget": widget_name, "color": color, "lang": lang.code},
                )
            color_list.append({"name": color, "url": get_site_url(color_url)})
        widget_list.append({"name": widget_name, "colors": color_list})

    return render_to_response(
        "widgets.html",
        RequestContext(
            request,
            {
                "engage_url": engage_url,
                "engage_url_track": engage_url_track,
                "widget_list": widget_list,
                "widget_base_url": widget_base_url,
                "object": 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 = EnageLanguageForm(obj, request.GET)
    lang = None
    if form.is_valid() and form.cleaned_data['lang'] != '':
        lang = Language.objects.get(code=form.cleaned_data['lang'])

    if lang is None:
        engage_base = reverse('engage', kwargs={'project': obj.slug})
    else:
        engage_base = reverse(
            'engage-lang',
            kwargs={'project': obj.slug, 'lang': lang.code}
        )
    engage_url = get_site_url(engage_base)
    engage_url_track = '%s?utm_source=widget' % 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]
        color_list = []
        for color in widget_class.colors:
            if lang is None:
                color_url = reverse(
                    'widget-image',
                    kwargs={
                        'project': obj.slug,
                        'widget': widget_name,
                        'color': color,
                        'extension': widget_class.extension,
                    }
                )
            else:
                color_url = reverse(
                    'widget-image-lang',
                    kwargs={
                        'project': obj.slug,
                        'widget': widget_name,
                        'color': color,
                        'lang': lang.code,
                        'extension': widget_class.extension,
                    }
                )
            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,
            '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 = EnageLanguageForm(obj, request.GET)
    lang = None
    if form.is_valid() and form.cleaned_data['lang'] != '':
        lang = Language.objects.get(code=form.cleaned_data['lang'])

    if lang is None:
        engage_base = reverse('engage', kwargs={'project': obj.slug})
    else:
        engage_base = reverse(
            'engage-lang',
            kwargs={'project': obj.slug, 'lang': lang.code}
        )
    engage_url = get_site_url(engage_base)
    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]
        color_list = []
        for color in widget_class.colors:
            if lang is None:
                color_url = reverse(
                    'widget-image',
                    kwargs={
                        'project': obj.slug,
                        'widget': widget_name,
                        'color': color,
                        'extension': widget_class.extension,
                    }
                )
            else:
                color_url = reverse(
                    'widget-image-lang',
                    kwargs={
                        'project': obj.slug,
                        'widget': widget_name,
                        'color': color,
                        'lang': lang.code,
                        'extension': widget_class.extension,
                    }
                )
            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 #4
0
def widgets(request, project):

    obj = get_object_or_404(Project, slug=project)

    # Parse possible language selection
    form = EnageLanguageForm(obj, request.GET)
    lang = None
    if form.is_valid():
        if form.cleaned_data['lang'] != '':
            lang = Language.objects.get(code=form.cleaned_data['lang'])

    site = Site.objects.get_current()
    if lang is None:
        engage_base = reverse('engage', kwargs={'project': obj.slug})
    else:
        engage_base = reverse(
            'engage-lang',
            kwargs={'project': obj.slug, 'lang': lang.code}
        )
    engage_url = 'http://%s%s' % (
        site.domain,
        engage_base,
    )
    engage_url_track = '%s?utm_source=widget' % engage_url
    widget_base_url = 'http://%s%s' % (
        site.domain,
        reverse('widgets', kwargs={'project': obj.slug}),
    )
    widget_list = []
    for widget_name in WIDGETS:
        widget = WIDGETS[widget_name]
        color_list = []
        for color in widget['colors']:
            if lang is None:
                color_url = reverse(
                    'widget-image',
                    kwargs={
                        'project': obj.slug,
                        'widget': widget_name,
                        'color': color,
                    }
                )
            else:
                color_url = reverse(
                    'widget-image-lang',
                    kwargs={
                        'project': obj.slug,
                        'widget': widget_name,
                        'color': color,
                        'lang': lang.code
                    }
                )
            color_list.append({
                'name': color,
                'url': 'http://%s%s' % (
                    site.domain,
                    color_url,
                ),
            })
        widget_list.append({
            'name': widget_name,
            'colors': color_list,
        })

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