Skip to content

Instantly share code, notes, and snippets.

@cooncesean
cooncesean / GB EditorialReview Scores By Developer
Created November 30, 2011 00:29
Find the total number of EditorialReviews by platform and the average score given per platform/developer.
developers = {}
for er in EditorialReview.objects.all():
print er
for dtg in er.game.developers.all():
if dtg.company.name in developers:
_dict = developers[dtg.company.name]
_dict['total_reviews'] += 1
_dict['total_review_score'] += er.score
_dict['avg_review_score'] = '%.1f' % (float(_dict['total_review_score']) / float(_dict['total_reviews']))
else:
@cooncesean
cooncesean / EditorialReviews By Developer
Created November 30, 2011 00:44
GiantBomb editorial reviews by developer.
{u'2K Australia': {'avg_review_score': 4,
'total_review_score': 4,
'total_reviews': 1},
u'2K China': {'avg_review_score': 4,
'total_review_score': 4,
'total_reviews': 1},
u'2K Czech': {'avg_review_score': 3,
'total_review_score': 3,
'total_reviews': 1},
u'2K Marin': {'avg_review_score': 4,
@cooncesean
cooncesean / Profile Forum History Page.
Created January 9, 2012 20:01
Performance comparison between sql and redis queries to build a topic detail page.
WITH REDIS
Executed SQL
EXPLAIN SELECT "shout_post"."id", "shout_post"."body", "shout_post"."date_added", "shout_post"."date_last_updated", "shout_post"."user_profile_id", "shout_post"."status", "shout_post"."points", "shout_post"."content_type_id", "shout_post"."object_id", "shout_post"."section" FROM "shout_post" WHERE "shout_post"."id" IN (2882288, 2882276, 2882274, 637787, 637651, 637513, 637478, 637447, 637439, 637351, 636576, 636569, 635341, 635252, 635213, 635206, 635194, 635155, 635095, 635084) ORDER BY "shout_post"."id" DESC
Time
1.73 ms
QUERY PLAN
Sort (cost=165.88..165.93 rows=20 width=363)
Sort Key: id
-> Bitmap Heap Scan on shout_post (cost=85.48..165.45 rows=20 width=363)
Recheck Cond: (id = ANY ('{2882288,2882276,2882274,637787,637651,637513,637478,637447,637439,637351,636576,636569,635341,635252,635213,635206,635194,635155,635095,635084}'::integer[]))
@cooncesean
cooncesean / create_comment.py
Created February 13, 2012 19:10
Creating an Ella Comment on a Topic
from django.contrib import comments
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.contrib.contenttypes.models import ContentType
from django.contrib.webdesign.lorem_ipsum import sentence
from scout.topics.models import Topic
def create_comments(obj, number_of_comments=5):
for i in range(0, number_of_comments):
@cooncesean
cooncesean / topic.py
Created February 14, 2012 18:04
Get Comments for Publishable
class Topic(Publishable):
@property
def comments(self):
return Comment.objects.filter(content_type=ContentType.objects.get_for_model(self), object_pk=self.id).order_by('id')
@cooncesean
cooncesean / admin.py
Created March 2, 2012 21:13
Multiple Inlines for a ModelAdmin
from momme.forms import ListingInline, LifeStageInline, FranchiseInline
class MommeArticleModelAdmin(admin.ModelAdmin):
" Custom model admin for Articles to separate out LifeStages, Franchises and SubCategories. "
inlines = [
ListingInline,
LifeStageInline,
FranchiseInline
]
admin.register(Article, MommeArticleModelAdmin)
Live Galleries
a. chronological - should have the most recent gallery created on top
b. Category link should remain internal (not link to live site category page, but be
seen as a sorting tool for content under that category)
2. Add gallery
a. Category - should split out life stage / category / subcategory
b. need franchise drop down
- Family Ties
- Parenting Styles
- Am I Ruining My Kid
@cooncesean
cooncesean / script.sh
Created March 7, 2012 18:20
Remove transaction management from django admin options.py
> cd ~/.virtualenvs/tested/lib/python2.7/site-packages
> subl django
Open: django.contrib.admin.options.py
Search for the methods:
add_view()
change_view()
Remove the decorators above those methods:
@cooncesean
cooncesean / video_index.html
Created March 11, 2012 00:04
Video index page using Listings in ella.
{% box 'main_video_player.tpl' for listings.0 %}
{% for listing in listings|slice:1 %}
{% box 'archive.tpl' for listing %}
{% endfor %}
@cooncesean
cooncesean / box.html
Created March 11, 2012 17:28
Test the {% box %} template tag in ella.
{% box featured for listings.0 %}
second_listing: {{ listings.1 }}
{% endbox %}