Example #1
0
def save_opinion_from_form(request, type, ua, form):
    """Given a (valid) form and feedback type, save it to the DB."""
    locale = detect_language(request)

    # Remove URL if checkbox disabled or no URL submitted. Broken Website
    # report does not have the option to disable URL submission.
    if type != input.OPINION_BROKEN.id and not (
        form.cleaned_data.get("add_url", False) and form.cleaned_data.get("url")
    ):
        form.cleaned_data["url"] = ""

    if type not in input.OPINION_TYPES:
        raise ValueError("Unknown type %s" % type)

    opinion = Opinion(
        _type=type,
        url=form.cleaned_data.get("url", ""),
        description=form.cleaned_data["description"],
        user_agent=ua,
        locale=locale,
        manufacturer=form.cleaned_data["manufacturer"],
        device=form.cleaned_data["device"],
    )
    opinion.save()

    return opinion
Example #2
0
def save_opinion_from_form(request, type, ua, form):
    """Given a (valid) form and feedback type, save it to the DB."""
    locale = detect_language(request)

    # Remove URL if checkbox disabled or no URL submitted. Broken Website
    # report does not have the option to disable URL submission.
    if (type != input.OPINION_BROKEN.id and
        not (form.cleaned_data.get('add_url', False) and
             form.cleaned_data.get('url'))):
        form.cleaned_data['url'] = ''

    if type not in input.OPINION_TYPES:
        raise ValueError('Unknown type %s' % type)

    if type != input.OPINION_RATING.id:
        return Opinion(
            type=type,
            url=form.cleaned_data.get('url', ''),
            description=form.cleaned_data['description'],
            user_agent=ua, locale=locale,
            manufacturer=form.cleaned_data['manufacturer'],
            device=form.cleaned_data['device']).save()

    else:
        opinion = Opinion(
            type=type,
            user_agent=ua, locale=locale)
        opinion.save()
        for question in input.RATING_USAGE:
            value = form.cleaned_data.get(question.short)
            if not value:
                continue
            Rating(opinion=opinion, type=question.id, value=value).save()
        return opinion
Example #3
0
def test_product_name():
    """Show product name or ID if unknown."""
    o = Opinion()
    o.product = FIREFOX.id
    eq_(o.product_name, FIREFOX.pretty)

    o.product = 17  # Unknown ID
    eq_(o.product_name, 17)
Example #4
0
def test_platform_name():
    """Show platform name or ID if unknown."""
    o = Opinion()
    o.platform = 'win7'
    eq_(o.platform_name, WINDOWS_7.pretty)

    o.platform = 'win25'  # Unknown ID
    eq_(o.platform_name, 'win25')
Example #5
0
def test_product_name():
    """Show product name or ID if unknown."""
    o = Opinion()
    o.product = FIREFOX.id
    eq_(o.product_name, FIREFOX.pretty)

    o.product = 17  # Unknown ID
    eq_(o.product_name, 17)
Example #6
0
def test_platform_name():
    """Show platform name or ID if unknown."""
    o = Opinion()
    o.platform = 'win7'
    eq_(o.platform_name, WINDOWS_7.pretty)

    o.platform = 'win25'  # Unknown ID
    eq_(o.platform_name, 'win25')
Example #7
0
 def make_comment(cluster, n, i, type):
     "Invent comment i of n for the given cluster."
     o = Opinion(description="Message %i/%i." % (i, n),
                 product=1, version=LATEST_BETAS[FIREFOX],
                 type=type.id, platform='mac', locale='en-US')
     o.save()
     c = Comment(cluster=cluster, description=o.description,
                 opinion_id=o.id, score=1.0)
     c.save()
     return c
Example #8
0
File: cron.py Project: x1B/reporter
def populate(num_opinions=None, product='mobile', type=None, locale=None):
    if not num_opinions:
        num_opinions = getattr(settings, 'NUM_FAKE_OPINIONS',
                               DEFAULT_NUM_OPINIONS)
    else:
        num_opinions = int(num_opinions)

    if hasattr(type, 'id'):  # Take "3" as well as OPINION_IDEA
        type = type.id

    for i in xrange(num_opinions):
        if not type:
            type = random.choice(TYPES).id
        o = Opinion(type=type,
                    url=random.choice(URLS),
                    locale=locale or random.choice(settings.INPUT_LANGUAGES),
                    user_agent=random.choice(UA_STRINGS[product]))

        o.description = sample()

        if 'mobile':
            manufacturer = random.choice(DEVICES.keys())
            o.manufacturer = manufacturer
            o.device = random.choice(DEVICES[manufacturer])

        o.save(terms=False)

        o.created = datetime.datetime.now() - datetime.timedelta(
                seconds=random.randint(0, 30 * 24 * 3600))
        o.save()
Example #9
0
 def make_comment(cluster, n, i, type):
     "Invent comment i of n for the given cluster."
     o = Opinion(description="Message %i/%i." % (i, n),
                 product=1,
                 version=LATEST_BETAS[FIREFOX],
                 type=type.id,
                 platform='mac',
                 locale='en-US')
     o.save()
     c = Comment(cluster=cluster,
                 description=o.description,
                 opinion_id=o.id,
                 score=1.0)
     c.save()
     return c
Example #10
0
def save_opinion_from_form(request, type, ua, form):
    """Given a (valid) form and feedback type, save it to the DB."""
    locale = detect_language(request)

    if type not in input.OPINION_TYPES:
        raise ValueError('Unknown type %s' % type)

    opinion = Opinion(
        _type=type,
        url=form.cleaned_data.get('url') or '',
        description=form.cleaned_data['description'],
        user_agent=ua, locale=locale,
        manufacturer=form.cleaned_data['manufacturer'],
        device=form.cleaned_data['device'])
    opinion.save()

    return opinion
Example #11
0
def save_opinion_from_form(request, type, ua, form):
    """Given a (valid) form and feedback type, save it to the DB."""
    locale = detect_language(request)

    if type not in input.OPINION_TYPES:
        raise ValueError('Unknown type %s' % type)

    opinion = Opinion(_type=type,
                      url=form.cleaned_data.get('url') or '',
                      description=form.cleaned_data['description'],
                      user_agent=ua,
                      locale=locale,
                      manufacturer=form.cleaned_data['manufacturer'],
                      device=form.cleaned_data['device'])
    opinion.save()

    return opinion
Example #12
0
def populate(num_opinions=None, product='mobile', type=None, locale=None):
    models.signals.post_save.disconnect(extract_terms,
                                        sender=Opinion,
                                        dispatch_uid='extract_terms')

    if not num_opinions:
        num_opinions = getattr(settings, 'NUM_FAKE_OPINIONS',
                               DEFAULT_NUM_OPINIONS)
    else:
        num_opinions = int(num_opinions)

    if hasattr(type, 'id'):  # Take "3" as well as OPINION_IDEA
        type = type.id

    for i in xrange(num_opinions):
        if not type:
            type = random.choice(TYPES).id
        o = Opinion(type=type,
                    url=random.choice(URLS),
                    locale=locale or random.choice(settings.INPUT_LANGUAGES),
                    user_agent=random.choice(UA_STRINGS[product]))

        o.description = sample()

        if 'mobile':
            manufacturer = random.choice(DEVICES.keys())
            o.manufacturer = manufacturer
            o.device = random.choice(DEVICES[manufacturer])

        o.save()

        o.created = datetime.datetime.now() - datetime.timedelta(
            seconds=random.randint(0, 30 * 24 * 3600))
        o.save()

    models.signals.post_save.connect(extract_terms,
                                     sender=Opinion,
                                     dispatch_uid='extract_terms')
Example #13
0
def save_opinion_from_form(request, type, ua, form):
    """Given a (valid) form and feedback type, save it to the DB."""
    locale = detect_language(request)

    # Remove URL if checkbox disabled or no URL submitted. Broken Website
    # report does not have the option to disable URL submission.
    if (type != input.OPINION_BROKEN.id
            and not (form.cleaned_data.get('add_url', False)
                     and form.cleaned_data.get('url'))):
        form.cleaned_data['url'] = ''

    if type not in input.OPINION_TYPES:
        raise ValueError('Unknown type %s' % type)

    opinion = Opinion(_type=type,
                      url=form.cleaned_data.get('url', ''),
                      description=form.cleaned_data['description'],
                      user_agent=ua,
                      locale=locale,
                      manufacturer=form.cleaned_data['manufacturer'],
                      device=form.cleaned_data['device'])
    opinion.save()

    return opinion
Example #14
0
    def setUp(self):
        self.client.get('/')
        settings.CLUSTER_SIM_THRESHOLD = 2

        args = dict(product=1, version=FIREFOX.default_version, platform='mac',
                    locale='en-US')
        for x in xrange(10):
            o = Opinion(description='Skip town. slow down '
                        'Push it to the ' + x * 'east coast ',
                        **args)
            o.save()

        for x in xrange(10):
            o = Opinion(description='Despite all my rage, '
                        'I am still just a rat in a ' + x * 'cage ',
                        **args)
            o.save()

        for x in xrange(4):
            o = Opinion(description='It is hammer time ' + x * 'baby ',
                        **args)
            o.save()

        for x in xrange(2):
            o = Opinion(description='Three blind mice.', **args)
            o.save()

        o = Opinion(description='Hello World', **args)
        o.save()

        from themes.cron import cluster
        cluster()
Example #15
0
    def setUp(self):
        self.client.get('/')
        settings.CLUSTER_SIM_THRESHOLD = 0.1

        args = dict(product=1, version=LATEST_BETAS[FIREFOX], os='mac',
                    locale='en-US')
        for x in xrange(10):
            o = Opinion(description='Skip town. slow down '
                        'Push it to the east coast ' + str(x),
                        **args)
            o.save()

        for x in xrange(10):
            o = Opinion(description='Despite all my rage, '
                        'I am still just a rat in a cage.' + str(x),
                        **args
                       )
            o.save()

        for x in xrange(4):
            o = Opinion(description='It is hammer time baby.  ' + str(x),
                        **args
                       )
            o.save()

        for x in xrange(2):
            o = Opinion(description='Three blind mice.', **args)
            o.save()

        o = Opinion(description='Hello World', **args)
        o.save()

        from themes.cron import cluster
        cluster()
Example #16
0
    def setUp(self):
        self.client.get('/')
        settings.CLUSTER_SIM_THRESHOLD = 2

        args = dict(product=1,
                    version=FIREFOX.default_version,
                    platform='mac',
                    locale='en-US')
        for x in xrange(10):
            o = Opinion(description='Skip town. slow down '
                        'Push it to the ' + x * 'east coast ',
                        **args)
            o.save()

        for x in xrange(10):
            o = Opinion(description='Despite all my rage, '
                        'I am still just a rat in a ' + x * 'cage ',
                        **args)
            o.save()

        for x in xrange(4):
            o = Opinion(description='It is hammer time ' + x * 'baby ', **args)
            o.save()

        for x in xrange(2):
            o = Opinion(description='Three blind mice.', **args)
            o.save()

        o = Opinion(description='Hello World', **args)
        o.save()

        from themes.cron import cluster
        cluster()
Example #17
0
 def mock_items(self, obj):
     return [Opinion(id=n, _type=type.id, product=FIREFOX.id) for
             n, type in enumerate(OPINION_TYPES_USAGE)]
Example #18
0
    def setUp(self):
        self.client.get("/")
        settings.CLUSTER_SIM_THRESHOLD = 2

        args = dict(product=1, version=LATEST_BETAS[FIREFOX], platform="mac", locale="en-US")
        for x in xrange(10):
            o = Opinion(description="Skip town. slow down " "Push it to the " + x * "east coast ", **args)
            o.save()

        for x in xrange(10):
            o = Opinion(description="Despite all my rage, " "I am still just a rat in a " + x * "cage ", **args)
            o.save()

        for x in xrange(4):
            o = Opinion(description="It is hammer time " + x * "baby ", **args)
            o.save()

        for x in xrange(2):
            o = Opinion(description="Three blind mice.", **args)
            o.save()

        o = Opinion(description="Hello World", **args)
        o.save()

        from themes.cron import cluster

        cluster()