示例#1
0
def products_block(context, products, product):
    latest_versions = dict((prod.short, Version(v).simplified) for prod, v in
                            LATEST_VERSION().items())
    version_choices = {}
    for prod in VERSION_CHOICES[get_channel()]:
        version_choices = json.dumps(
            dict((prod.short,
                  [map(unicode, v) for v
                   in VERSION_CHOICES[get_channel()][prod]]) for prod in
                 VERSION_CHOICES[get_channel()]))
    return new_context(**locals())
示例#2
0
    def __init__(self, *args, **kwargs):
        """Pick version choices and initial product based on site ID."""
        super(ReporterSearchForm, self).__init__(*args, **kwargs)
        self.fields["version"].choices = VERSION_CHOICES[get_channel()][FIREFOX]

        # Show Mobile versions if that was picked by the user.
        picked = None
        if self.is_bound:
            try:
                picked = self.fields["product"].clean(self.data.get("product"))
            except forms.ValidationError:
                pass
        if picked == MOBILE.short or not self.is_bound and settings.SITE_ID == settings.MOBILE_SITE_ID:
            # We default to Firefox. Only change if this is the mobile site.
            self.fields["product"].initial = MOBILE.short
            self.fields["version"].choices = VERSION_CHOICES[get_channel()][MOBILE]
示例#3
0
def search_url(context, defaults=None, extra=None, feed=False, **kwargs):
    """Build a search URL with default values unless specified otherwise."""
    channel = input.get_channel()
    if channel == 'release':
        search = reverse('dashboard')
    elif feed:
        search = reverse('search.feed')
    else:
        search = reverse('search')
    if not defaults:
        defaults = {}
    data = []

    # fallbacks other than None
    fallbacks = {'version': '--'}
    if not 'product' in defaults and not 'product' in kwargs:
        prod = context['request'].default_prod
        fallbacks['product'] = prod.short
        fallbacks['version'] = Version(input.LATEST_VERSION()[prod]).simplified

    # get field data from keyword args or defaults
    for field in ReporterSearchForm.base_fields:
        val = kwargs.get(field, defaults.get(
            field, fallbacks.get(field, None)))
        if val:
            data.append((field, unicode(val).encode('utf-8')))

    # append extra fields
    if extra:
        data = dict(data)
        data.update(extra)

    return u'%s?%s' % (search, urlencode(data))
示例#4
0
def product_versions(request):
    return {
        'PROD_VERSIONS_JSON': json.dumps(dict(
            [(p.short, [(v[0], unicode(v[1])) for v in
             VERSION_CHOICES[get_channel()][p]]) for
             p in PRODUCT_USAGE]))
    }
示例#5
0
    def clean(self):
        cleaned = super(WebsiteIssuesSearchForm, self).clean()

        for field_name, field_def in FIELD_DEFS.items():
            if field_name not in cleaned:
                cleaned[field_name] = field_def.default
                continue
            if BooleanField == type(field_def.field) and cleaned.get(field_name) not in (True, False):
                cleaned[field_name] = field_def.default
            if ChoiceField == type(field_def.field) and cleaned.get(field_name) not in field_def.keys:
                cleaned[field_name] = field_def.default

        if cleaned.get("product") and cleaned.get("platform"):
            product = PRODUCTS[cleaned.get("product")]
            possible_platforms = [platform for platform in PLATFORMS.values() if product in platform.prods]
            if PLATFORMS[cleaned.get("platform")] not in possible_platforms:
                cleaned["platform"] = FIELD_DEFS["platform"].default

        if not cleaned.get("version"):
            product = cleaned.get("product", FIREFOX)
            cleaned["version"] = VERSION_CHOICES[get_channel()][product][0][0]

        if cleaned.get("page") is not None:
            cleaned["page"] = max(1, int(cleaned["page"]))
        else:
            cleaned["page"] = FIELD_DEFS["page"].default

        return cleaned
示例#6
0
def _common_data(form):
    platforms = PLATFORMS.values()
    product_name = form.cleaned_data["product"]
    if product_name:
        product = PRODUCTS[product_name]
        platforms = [platform for platform in platforms if product in platform.prods]
    return {"form": form,
            "platforms": platforms,
            "products": form.fields["product"].choices,
            "product": product,
            "versions": VERSION_CHOICES[get_channel()][product],
            "version": form.cleaned_data["version"]}
示例#7
0
 def __init__(self, *args, **kwargs):
     """Set available products/versions based on selected channel/product"""
     super(WebsiteIssuesSearchForm, self).__init__(*args, **kwargs)
     choices = VERSION_CHOICES[get_channel()]
     product_choices = [(p.short, p.pretty) for p in (FIREFOX, MOBILE) if choices[p]]
     self.fields["product"].choices = product_choices
     FIELD_DEFS["product"] = field_def(ChoiceField, product_choices[0][0], choices=product_choices)
     product = self.data.get("product", FIREFOX)
     try:
         if not choices[product]:
             product = FIREFOX
     except KeyError:
         product = FIREFOX
     version_choices = choices[product]
     self.fields["version"].choices = version_choices
     self.fields["version"].initial = version_choices[0][0]
     FIELD_DEFS["version"] = field_def(ChoiceField, version_choices[0][0], choices=version_choices)
     self.cleaned_data = {}
示例#8
0
def theme(request, theme_id):
    try:
        theme = Theme.objects.get(id=theme_id, channel=get_channel())
    except Theme.DoesNotExist:
        raise http.Http404

    pager = Paginator(theme.opinions.all(), settings.SEARCH_PERPAGE)
    try:
        page = pager.page(request.GET.get('page', 1))
    except (EmptyPage, InvalidPage):
        page = pager.page(pager.num_pages)

    return jingo.render(request,
                        'themes/theme.html',
                        {"theme": theme,
                         "opinions": page.object_list,
                         "page": page,
                         "exit_url": reverse("themes")})
示例#9
0
def input(request):
    return dict(settings=settings, CHANNEL=get_channel(),
                CHANNELS=CHANNELS, CHANNEL_USAGE=CHANNEL_USAGE)
示例#10
0
def field_def(FieldType, default, widget=HiddenInput, choices=None):
    field_args = {"required": False, "label": "", "widget": widget}
    keys = None
    if choices is not None:
        field_args.update({"choices": choices})
        keys = set([key for key, value in choices])
    return FieldDef(default, FieldType(**field_args), keys)


FIELD_DEFS = {
    "q": field_def(
        CharField, "", widget=SearchInput(attrs={"placeholder": _lazy("Search for domain", "website_issues_search")})
    ),
    "sentiment": field_def(ChoiceField, "", choices=SENTIMENT_CHOICES),
    "version": field_def(
        ChoiceField, VERSION_CHOICES[get_channel()][FIREFOX][0][0], choices=VERSION_CHOICES[get_channel()][FIREFOX]
    ),
    "product": field_def(ChoiceField, FIREFOX.short, choices=PROD_CHOICES),
    "platform": field_def(ChoiceField, "", choices=PLATFORM_CHOICES),
    "show_one_offs": field_def(BooleanField, False),
    "page": field_def(IntegerField, 1),
    "site": field_def(IntegerField, None),
    "cluster": field_def(IntegerField, None),
}


class WebsiteIssuesSearchForm(forms.Form):

    # Fields that are submitted on text search:
    q = FIELD_DEFS["q"].field
    sentiment = FIELD_DEFS["sentiment"].field