Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
bug 648405, removing channels from views
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Apr 18, 2011
1 parent ff7fe4e commit 57746d2
Show file tree
Hide file tree
Showing 42 changed files with 166 additions and 1,194 deletions.
28 changes: 3 additions & 25 deletions apps/api/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import cronjobs

from input import PRODUCT_IDS
from feedback.models import Opinion, Rating
from input import OPINION_RATING, OPINION_TYPES, RATING_IDS
from feedback.models import Opinion
from input import OPINION_TYPES


BUCKET_SIZE = 10000 # Bucket size to split query set into.
Expand All @@ -34,7 +34,6 @@ def _fix_row(row):

def _split_queryset(qs):
"""Generator splitting a queryset into buckets."""
cnt = qs.count()
start = 0
end = BUCKET_SIZE
while True:
Expand All @@ -53,7 +52,7 @@ def _split_queryset(qs):
@cronjobs.register
def export_tsv():
"""
Exports a complete dump of the Opinions and Ratings tables to disk, in
Exports a complete dump of the Opinions table to disk, in
TSV format.
"""
opinions_path = os.path.join(settings.TSV_EXPORT_DIR, 'opinions.tsv.bz2')
Expand Down Expand Up @@ -83,24 +82,3 @@ def export_tsv():
outfile.close()
shutil.move(opinions_tmp, opinions_path)
print 'All opinions dumped to disk.'

ratings_path = os.path.join(settings.TSV_EXPORT_DIR, 'ratings.tsv.bz2')
ratings_tmp = '%s_exporting' % ratings_path
print 'Dumping all ratings into TSV file %s.' % ratings_path

# All ratings
ratings = Rating.objects.order_by('id')
try:
outfile = bz2.BZ2File(ratings_tmp, 'w')
tsv = csv.writer(outfile, dialect=TSVDialect)
for bucket in _split_queryset(ratings):
for rating in bucket:
tsv.writerow(_fix_row([
rating.opinion_id,
getattr(RATING_IDS.get(rating.type), 'short', None),
rating.value,
]))
finally:
outfile.close()
shutil.move(ratings_tmp, ratings_path)
print 'All ratings dumped to disk.'
10 changes: 5 additions & 5 deletions apps/dashboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import jinja2
from product_details.version_compare import Version

from input import LATEST_VERSION, get_channel
from input import LATEST_BETAS
from search.forms import VERSION_CHOICES


Expand Down Expand Up @@ -114,14 +114,14 @@ def themes_block(context, themes, defaults=None):
@jinja2.contextfunction
def products_block(context, products, product):
latest_versions = dict((prod.short, Version(v).simplified) for prod, v in
LATEST_VERSION().items())
LATEST_BETAS.items())
version_choices = {}
for prod in VERSION_CHOICES[get_channel()]:
for prod in VERSION_CHOICES:
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()]))
in VERSION_CHOICES[prod]]) for prod in
VERSION_CHOICES))
return new_context(**locals())


Expand Down
9 changes: 2 additions & 7 deletions apps/dashboard/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pyquery import PyQuery as pq

import input
from dashboard import helpers
from input.tests import InputTestCase
from input.urlresolvers import reverse
from search.tests import SphinxTestCase
Expand All @@ -36,12 +35,8 @@ def test_dashboard(self):
r = self.client.get(reverse('dashboard'), follow=True)
eq_(r.status_code, 200)

def test_beta_dashboard(self):
r = self.client.get(reverse('dashboard', channel='beta'))
eq_(r.status_code, 200)

def test_beta_pagination_link(self):
r = self.client.get(reverse('dashboard', channel='beta'))
r = self.client.get(reverse('dashboard'))
doc = pq(r.content)

pag_link = doc('.pager a.next')
Expand All @@ -53,7 +48,7 @@ def test_beta_pagination_link(self):

class TestMobileDashboard(test_utils.TestCase):
def test_dashboard(self):
r = self.client.get(reverse('dashboard', channel='beta'), follow=True,
r = self.client.get(reverse('dashboard'), follow=True,
SITE_ID=settings.MOBILE_SITE_ID)
eq_(r.status_code, 200)

Expand Down
11 changes: 4 additions & 7 deletions apps/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
from feedback import stats
from feedback.models import Opinion, Term
from input import LATEST_BETAS
from input.decorators import cache_page, forward_mobile, negotiate
from input.decorators import cache_page, forward_mobile
from search.client import Client, SearchError
from search.forms import PROD_CHOICES, VERSION_CHOICES, ReporterSearchForm
from search.views import get_sentiment, release, get_defaults, get_plotbands
from search.views import get_sentiment, get_defaults, get_plotbands
from website_issues.models import SiteSummary


@forward_mobile
@cache_page
def beta(request):
def dashboard(request):
"""Beta dashboard."""
# Defaults
prod = request.default_prod
Expand Down Expand Up @@ -73,7 +73,7 @@ def beta(request):
'platforms': metas.get('platform'),
'sites': sites,
'version': version,
'versions': VERSION_CHOICES['beta'][prod],
'versions': VERSION_CHOICES[prod],
'chart_data_json': json.dumps(chart_data),
'defaults': get_defaults(search_form),
'search_form': search_form,
Expand All @@ -84,6 +84,3 @@ def beta(request):
else:
template = 'dashboard/mobile/beta.html'
return jingo.render(request, template, data)


dashboard = negotiate(beta=beta, release=release)
13 changes: 3 additions & 10 deletions apps/feedback/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib import admin

from .models import Opinion, Rating, Term
from .utils import smart_truncate
from .models import Opinion, Term


class OpinionAdmin(admin.ModelAdmin):
Expand All @@ -20,8 +19,8 @@ class OpinionAdmin(admin.ModelAdmin):
'fields': ('type', 'description', 'created')
}),
('Build Info', {
'fields': ('user_agent', 'product_name', 'version', 'platform_name',
'locale')
'fields': ('user_agent', 'product_name', 'version',
'platform_name', 'locale')
}),
('Device Info', {
'fields': ('manufacturer', 'device')
Expand All @@ -36,12 +35,6 @@ class OpinionAdmin(admin.ModelAdmin):
admin.site.register(Opinion, OpinionAdmin)


class RatingAdmin(admin.ModelAdmin):
pass

admin.site.register(Rating, RatingAdmin)


class TermAdmin(admin.ModelAdmin):
list_display = ('term', 'hidden')
list_filter = ('hidden',)
Expand Down
11 changes: 2 additions & 9 deletions apps/feedback/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import cronjobs

from feedback.models import Opinion, Rating
from feedback.models import Opinion
import input


Expand Down Expand Up @@ -73,8 +73,7 @@ def populate(num_opinions=None, product='mobile', type=None, locale=None):
locale=locale or random.choice(settings.INPUT_LANGUAGES),
user_agent=random.choice(UA_STRINGS[product]))

if type != input.OPINION_RATING.id:
o.description = sample()
o.description = sample()

if 'mobile':
manufacturer = random.choice(DEVICES.keys())
Expand All @@ -83,12 +82,6 @@ def populate(num_opinions=None, product='mobile', type=None, locale=None):

o.save(terms=False)

if type == input.OPINION_RATING.id:
for question in input.RATING_USAGE:
Rating(
opinion=o,
type=question.id,
value=random.randint(1, 5)).save()
o.created = datetime.datetime.now() - datetime.timedelta(
seconds=random.randint(0, 30 * 24 * 3600))
o.save()
10 changes: 1 addition & 9 deletions apps/feedback/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from feedback import query
from feedback.utils import ua_parse, extract_terms, smart_truncate
from input import PRODUCT_IDS, OPINION_TYPES, OPINION_PRAISE, PLATFORMS, RATING_USAGE
from input import PRODUCT_IDS, OPINION_TYPES, OPINION_PRAISE, PLATFORMS
from input.models import ModelBase
from input.urlresolvers import reverse

Expand Down Expand Up @@ -162,11 +162,3 @@ def __unicode__(self):

class Meta:
ordering = ('term',)


class Rating(ModelBase):
"""Ratings associated with an opinion."""
opinion = models.ForeignKey(Opinion, related_name='ratings')
type = models.PositiveSmallIntegerField(default=RATING_USAGE[0],
db_index=True)
value = models.PositiveSmallIntegerField()
Loading

0 comments on commit 57746d2

Please sign in to comment.