Esempio n. 1
0
    def handle(self, *args, **options):
        versions = version_list(product_details.firefox_history_major_releases)
        versions += version_list(
            product_details.firefox_history_stability_releases)

        for version in versions:
            AddonGroup.objects.get_or_create(browser_version=version)
Esempio n. 2
0
def fetch_render_snippets(request, **kwargs):
    """Fetch snippets for the client and render them immediately."""
    client = Client(**kwargs)
    matching_snippets = (Snippet.cached_objects
                         .filter(disabled=False)
                         .match_client(client)
                         .order_by('priority')
                         .select_related('template')
                         .filter_by_available())

    current_firefox_version = (
        version_list(product_details.firefox_history_major_releases)[0].split('.', 1)[0])

    metrics_url = settings.METRICS_URL
    if ((settings.ALTERNATE_METRICS_URL and
         client.channel in settings.ALTERNATE_METRICS_CHANNELS)):
        metrics_url = settings.ALTERNATE_METRICS_URL

    response = render(request, 'base/fetch_snippets.jinja', {
        'snippet_ids': [snippet.id for snippet in matching_snippets],
        'snippets_json': json.dumps([s.to_dict() for s in matching_snippets]),
        'client': client,
        'locale': client.locale,
        'current_firefox_version': current_firefox_version,
        'metrics_url': metrics_url,
    })

    # ETag will be a hash of the response content.
    response['ETag'] = hashlib.sha256(response.content).hexdigest()
    patch_vary_headers(response, ['If-None-Match'])

    return response
Esempio n. 3
0
    def __init__(self, *args, **kwargs):
        super(SnippetAdminForm, self).__init__(*args, **kwargs)

        version_choices = [
            (x, x) for x in version_list(product_details.firefox_history_major_releases)
        ]
        self.fields['client_option_version_lower_bound'].choices += version_choices
        self.fields['client_option_version_upper_bound'].choices += version_choices
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        super(SnippetAdminForm, self).__init__(*args, **kwargs)

        version_choices = [(x, x) for x in version_list(
            product_details.firefox_history_major_releases)]
        self.fields[
            'client_option_version_lower_bound'].choices += version_choices
        self.fields[
            'client_option_version_upper_bound'].choices += version_choices
Esempio n. 5
0
class MOBILE:
    id = 60
    short = 'mobile'
    pretty = _(u'Mobile')
    guid = '{a23983c0-fd0e-11dc-95ff-0800200c9a66}'
    extra_versions = ['6.0a1', '5.0a2']
    beta_versions = version_list(
        dict(product_details.mobile_history_major_releases.items() +
             product_details.mobile_history_stability_releases.items() +
             product_details.mobile_history_development_releases.items()),
        hide_below='4.0b1',
        filter=(lambda v: v.is_beta))
    release_versions = version_list(
        dict(product_details.mobile_history_major_releases.items() +
             product_details.mobile_history_stability_releases.items() +
             product_details.mobile_history_development_releases.items()),
        hide_below='4.0',
        filter=(lambda v: v.is_release))
Esempio n. 6
0
class FIREFOX:
    id = 1
    short = 'firefox'
    pretty = _(u'Firefox')
    guid = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'
    extra_versions = ['6.0a1', '5.0a2']
    beta_versions = version_list(
        dict(product_details.firefox_history_major_releases.items() +
             product_details.firefox_history_stability_releases.items() +
             product_details.firefox_history_development_releases.items()),
        hide_below='4.0b12',
        filter=(lambda v: v.is_beta))
    release_versions = version_list(
        dict(product_details.firefox_history_major_releases.items() +
             product_details.firefox_history_stability_releases.items() +
             product_details.firefox_history_development_releases.items()),
        hide_below='4.0',
        filter=(lambda v: v.is_release))
Esempio n. 7
0
class MOBILE:
    id = 60
    short = 'mobile'
    pretty = _(u'Mobile')
    guid = '{a23983c0-fd0e-11dc-95ff-0800200c9a66}'
    extra_versions = ['10.0a1', '9.0a2', '8.0', '7.0']
    default_version = '7.0'
    min_version = '4.0'  # Minimum version for which we'll accept feedback
    beta_versions = version_list(
        dict(product_details.mobile_history_major_releases.items() +
             product_details.mobile_history_stability_releases.items() +
             product_details.mobile_history_development_releases.items()),
        hide_below='4.0b1',
        filter=(lambda v: v.is_beta))
    release_versions = version_list(
        dict(product_details.mobile_history_major_releases.items() +
             product_details.mobile_history_stability_releases.items() +
             product_details.mobile_history_development_releases.items()),
        hide_below='4.0',
        filter=(lambda v: v.is_release))
Esempio n. 8
0
class FIREFOX:
    id = 1
    short = 'firefox'
    pretty = _(u'Firefox')
    guid = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'
    extra_versions = ['10.0a1', '9.0a2', '8.0', '7.0']
    default_version = '7.0'  # Default dashboard version.
    min_version = '4.0'  # Minimum version for which we'll accept feedback
    beta_versions = version_list(
        dict(product_details.firefox_history_major_releases.items() +
             product_details.firefox_history_stability_releases.items() +
             product_details.firefox_history_development_releases.items()),
        hide_below='4.0b12',
        filter=(lambda v: v.is_beta))
    release_versions = version_list(
        dict(product_details.firefox_history_major_releases.items() +
             product_details.firefox_history_stability_releases.items() +
             product_details.firefox_history_development_releases.items()),
        hide_below='4.0',
        filter=(lambda v: v.is_release))
Esempio n. 9
0
def show_snippet(request, snippet_id):
    snippet = get_object_or_404(Snippet, pk=snippet_id)
    if snippet.disabled and not request.user.is_authenticated():
        raise Http404()

    current_firefox_version = (
        version_list(product_details.firefox_history_major_releases)[0].split('.', 1)[0])
    return render(request, 'base/preview.jinja', {
        'snippets_json': json.dumps([snippet.to_dict()]),
        'client': PREVIEW_CLIENT,
        'preview': True,
        'current_firefox_version': current_firefox_version,
    })
def test_version_list():
    """Test if version lists are generated properly."""
    my_versions = {
        '4.0b2build8': '2010-12-06',
        '3.0': '2010-12-01',
        '4.0b1': '2010-11-24',
        '4.0b2build7': '2010-12-05',
    }
    expected = ('4.0b2', '4.0b1')

    test_list = version_list(my_versions, hide_below='4.0b1')

    # Check if the generated version list is the same as we expect.
    eq_(len(expected), len(test_list))
    for n, v in enumerate(test_list):
        eq_(v, expected[n])
Esempio n. 11
0
    def __init__(self, *args, **kwargs):
        super(SnippetAdminForm, self).__init__(*args, **kwargs)

        version_choices = [(x, x) for x in version_list(
            product_details.firefox_history_major_releases)]
        self.fields[
            'client_option_version_lower_bound'].choices += version_choices
        self.fields[
            'client_option_version_upper_bound'].choices += version_choices

        if self.instance.client_options:
            for key in self.fields:
                if key.startswith('client_option_'):
                    self.fields[
                        key].initial = self.instance.client_options.get(
                            key.split('client_option_', 1)[1], None)
    def test_version_list(self):
        """Test if version lists are generated properly."""
        my_versions = {
            '4.0b2build8': '2010-12-06',
            '3.0': '2010-12-01',
            '4.0b1': '2010-11-24',
            '4.0b2build7': '2010-12-05',
        }
        expected = ('4.0b2', '4.0b1')

        test_list = version_list(my_versions, hide_below='4.0b1')

        # Check if the generated version list is the same as we expect.
        eq_(len(expected), len(test_list))
        for n, v in enumerate(test_list):
            eq_(v, expected[n])
Esempio n. 13
0
def preview_snippet(request):
    """
    Build a snippet using info from the POST parameters, and preview that
    snippet on a mock about:home page.
    """
    try:
        template_id = int(request.POST.get('template_id', None))
    except (TypeError, ValueError):
        return HttpResponseBadRequest()

    template = get_object_or_none(SnippetTemplate, id=template_id)
    data = request.POST.get('data', None)

    # Validate that data is JSON.
    try:
        json.loads(data)
    except (TypeError, ValueError):
        data = None

    # If your parameters are wrong, I have no sympathy for you.
    if data is None or template is None:
        return HttpResponseBadRequest()

    # Build a snippet that isn't saved so we can render it.
    snippet = Snippet(template=template, data=data)

    skip_boilerplate = request.POST.get('skip_boilerplate', 'false')
    skip_boilerplate = strtobool(skip_boilerplate)

    template_name = 'base/preview_without_shell.jinja' if skip_boilerplate else 'base/preview.jinja'
    current_firefox_version = (
        version_list(product_details.firefox_history_major_releases)[0].split('.', 1)[0])

    return render(request, template_name, {
        'snippets_json': json.dumps([snippet.to_dict()]),
        'client': PREVIEW_CLIENT,
        'preview': True,
        'current_firefox_version': current_firefox_version,
    })
Esempio n. 14
0
    def generate(self):
        """Generate and save the code for this snippet bundle."""
        current_firefox_version = (
            version_list(product_details.firefox_history_major_releases)[0].split('.', 1)[0])

        metrics_url = settings.METRICS_URL
        if ((settings.ALTERNATE_METRICS_URL and
             self.client.channel in settings.ALTERNATE_METRICS_CHANNELS)):
            metrics_url = settings.ALTERNATE_METRICS_URL

        bundle_content = render_to_string('base/fetch_snippets.jinja', {
            'snippet_ids': [snippet.id for snippet in self.snippets],
            'snippets_json': json.dumps([s.to_dict() for s in self.snippets]),
            'client': self.client,
            'locale': self.client.locale,
            'settings': settings,
            'current_firefox_version': current_firefox_version,
            'metrics_url': metrics_url,
        })

        if isinstance(bundle_content, unicode):
            bundle_content = bundle_content.encode('utf-8')
        default_storage.save(self.filename, ContentFile(bundle_content))
        cache.set(self.cache_key, True, settings.SNIPPET_BUNDLE_TIMEOUT)
Esempio n. 15
0
def current_firefox_major_version():
    full_version = version_list(
        product_details.firefox_history_major_releases)[0]

    return full_version.split('.', 1)[0]