def search_url(context, defaults=None, extra=None, feed=False, **kwargs): """Build a search URL with default values unless specified otherwise.""" if feed: search = reverse('search.feed') else: search = reverse('search') if not defaults: defaults = {} data = [] # fallbacks other than None fallbacks = {} if not 'product' in defaults and not 'product' in kwargs: app = context['request'].default_app fallbacks['product'] = app.short fallbacks['version'] = simplify_version(LATEST_BETAS[app]) # 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))
def demographics(request, date_start, date_end): """AJAX action returning an OS/locale summary.""" opinions = Opinion.objects.between(date_start, date_end).filter( product=request.default_app.id, version=simplify_version(LATEST_BETAS[request.default_app])) data = {'demo': stats.demographics(qs=opinions)} return jingo.render(request, 'dashboard/demographics.html', data)
def sentiment(request, date_start, date_end): """AJAX action returning a summary of positive/negative sentiments.""" opinions = Opinion.objects.between(date_start, date_end).filter( product=request.default_app.id, version=simplify_version(LATEST_BETAS[request.default_app])) data = {'sent': stats.sentiment(qs=opinions)} return jingo.render(request, 'dashboard/sentiments.html', data)
def messages(request, count=settings.MESSAGES_COUNT): """AJAX action returning the most recent messages.""" opinions = Opinion.objects.filter( product=request.default_app.id, version=simplify_version(LATEST_BETAS[request.default_app])).order_by( '-created')[:count] data = {'opinions': opinions} return jingo.render(request, 'dashboard/messages.html', data)
def products_block(context, products, product): latest_betas = dict((a.short, simplify_version(LATEST_BETAS[a])) for a in LATEST_BETAS) version_choices = {} for app in VERSION_CHOICES: version_choices = json.dumps( dict((app.short, [map(unicode, v) for v in VERSION_CHOICES[app]]) for app in VERSION_CHOICES)) return new_context(**locals())
def test_simplify_version(self): """Make sure version simplification works.""" versions = { '4.0b1': '4.0b1', '3.6': '3.6', '3.6.4b1': '3.6.4b1', '3.6.4build1': '3.6.4', '3.6.4build17': '3.6.4', } for v in versions: self.assertEquals(simplify_version(v), versions[v])
def trends(request, date_start, date_end): """AJAX action returning a summary of frequent terms.""" term_params = { 'date_start': date_start, 'date_end': date_end, 'product': request.default_app.id, 'version': simplify_version(LATEST_BETAS[request.default_app]), } frequent_terms = Term.objects.frequent( **term_params)[:settings.TRENDS_COUNT] data = {'terms': stats.frequent_terms(qs=frequent_terms)} return jingo.render(request, 'dashboard/trends.html', data)
def _get_results(request, meta=[]): form = ReporterSearchForm(request.GET) if form.is_valid(): query = form.cleaned_data.get("q", "") product = form.cleaned_data["product"] or FIREFOX.short version = form.cleaned_data["version"] search_opts = _get_results_opts(request, form, product, meta) c = Client() opinions = c.query(query, **search_opts) metas = c.meta else: query = "" opinions = [] product = request.default_app version = simplify_version(LATEST_BETAS[product]) metas = {} return (opinions, form, product, version, metas)
def dashboard(request): """Front page view.""" # Defaults app = request.default_app version = simplify_version(LATEST_BETAS[app]) # Frequent terms term_params = { 'product': app.id, 'version': version, } frequent_terms = Term.objects.frequent( **term_params)[:settings.TRENDS_COUNT] # opinions queryset for demographics latest_opinions = Opinion.objects.browse(**term_params) latest_beta = Opinion.objects.filter(version=version, product=app.id) # Sites clusters sites = SiteSummary.objects.filter(version__exact=version).filter( positive__exact=None).filter(os__exact=None)[:settings.TRENDS_COUNT] # search form to generate various form elements. search_form = ReporterSearchForm() try: c = Client() search_opts = dict(product=app.short, version=version) c.query('', meta=('type', 'locale', 'os', 'day_sentiment'), **search_opts) metas = c.meta daily = c.meta.get('day_sentiment', {}) chart_data = dict(series=[ dict(name=_('Praise'), data=daily['praise']), dict(name=_('Issues'), data=daily['issue']), dict(name=_('Suggestion'), data=daily['suggestion']), ], ) total = c.total_found except SearchError: metas = {} total = latest_beta.count() chart_data = None data = {'opinions': latest_opinions.all()[:settings.MESSAGES_COUNT], 'opinion_count': total, 'opinion_types': OPINION_TYPES, 'OPINION_PRAISE': OPINION_PRAISE, 'OPINION_ISSUE': OPINION_ISSUE, 'OPINION_SUGGESTION': OPINION_SUGGESTION, 'product': app.short, 'products': PROD_CHOICES, 'sentiments': get_sentiment(metas.get('type', [])), 'terms': stats.frequent_terms(qs=frequent_terms), 'demo': dict(locale=metas.get('locale'), os=metas.get('os')), 'sites': sites, 'version': version, 'versions': VERSION_CHOICES[app], 'search_form': search_form, 'chart_data_json': json.dumps(chart_data), } if not request.mobile_site: template = 'dashboard/dashboard.html' else: template = 'dashboard/mobile/dashboard.html' return jingo.render(request, template, data)
from feedback import FIREFOX, MOBILE, OS_USAGE, OPINION_TYPES from feedback.version_compare import simplify_version, version_int from input.fields import DateInput, SearchInput from input.utils import uniquifier PROD_CHOICES = ( (FIREFOX.short, FIREFOX.pretty), (MOBILE.short, MOBILE.pretty), ) # TODO need this for Mobile as well VERSION_CHOICES = { FIREFOX: [('', _lazy('-- all --', 'version_choice'))] + uniquifier( [(simplify_version(v[0]), v[0]) for v in sorted(product_details.firefox_history_development_releases.items(), key=lambda x: x[1], reverse=True) if version_int(v[0]) >= version_int(FIREFOX.hide_below)], key=lambda x: x[0]), MOBILE: [('', _lazy('-- all --', 'version_choice'))] + uniquifier( [(simplify_version(v[0]), v[0]) for v in sorted(product_details.mobile_history_development_releases.items(), key=lambda x: x[1], reverse=True)]), } SENTIMENT_CHOICES = [('', _lazy('-- all --', 'sentiment_choice')), ('happy', _lazy('Praise')), ('sad', _lazy('Issues')), ('suggestions', _lazy('Suggestions')) ]
from tower import ugettext_lazy as _lazy from feedback import APPS, FIREFOX, MOBILE, OS_USAGE, LATEST_BETAS from feedback.version_compare import simplify_version, version_int from input.fields import DateInput, SearchInput from input.utils import uniquifier PROD_CHOICES = ( (FIREFOX.short, FIREFOX.pretty), (MOBILE.short, MOBILE.pretty), ) # TODO need this for Mobile as well VERSION_CHOICES = { FIREFOX: [('', _lazy('-- all --', 'version_choice'))] + uniquifier( [(simplify_version(v[0]), v[0]) for v in sorted(product_details.firefox_history_development_releases.items(), key=lambda x: x[1], reverse=True) if version_int(v[0]) >= version_int(FIREFOX.hide_below) ], key=lambda x: x[0]), MOBILE: [ ('', _lazy('-- all --', 'version_choice')), (simplify_version(LATEST_BETAS[MOBILE]), LATEST_BETAS[MOBILE]), ], } SENTIMENT_CHOICES = [ ('', _lazy('-- all --', 'sentiment_choice')), ('happy', _lazy('Praise')), ('sad', _lazy('Issues')), ]