Skip to content

Instantly share code, notes, and snippets.

@cooncesean
cooncesean / create_best_of_category.py
Created March 11, 2012 18:56
Create a 'Best Of' article Category for Tested.
from ella.core.models import *
article_cat = Category.objects.get(slug='articles')
Category.objects.create(slug='best-of', title='Best Of', tree_path='articles/best-of', tree_parent=article_cat, site_id=1)
@cooncesean
cooncesean / create_staff_user.py
Created March 12, 2012 22:00
Script to create a new staff user.
def create_staff_user(username, password, first_name, last_name):
from django.contrib.auth.models import User
u = User.objects.create(
username=username,
first_name=first_name,
last_name=last_name,
is_staff=True,
is_superuser=True
)
@cooncesean
cooncesean / best_of_article_updater.py
Created March 15, 2012 06:37
Update Tested 'Best-Of' News Articles
cat = Category.objects.get(tree_path='news/best-of')
for a in Article.objects.filter(pk__in=[25, 12, 54, 147, 19, 152, 175, 406, 1904, 45, 1299, 2123, 2675]):
Listing.objects.create(
publishable=a,
category=cat,
publish_from=a.publish_from,
)
@cooncesean
cooncesean / conversion.py
Created March 15, 2012 16:27
Vines to Ella 'evergreen' to 'best of' conversion
# From prod tested
best_of_category = ella.core.models.Category.objects.get(tree_path='news/best-of')
for a in vines.Articles.objects.all():
... run your migration code ...
if a.evergreen_order > 0:
Listing.objects.create(
publishable=a,
category=best_of_category,
publish_from=a.publish_from,
)
@cooncesean
cooncesean / top_posters_import_script.py
Created March 15, 2012 21:57
Tested's Top Posters (Forums) Import Script.
from scout.topics.models import Topic
from scout.topics.top_posters import TopPosterLogger, log_new_comment
for t in Topic.objects.all():
for c in t.comments.all():
if c.category is not None:
TopPosterLogger.incr_new_comment(
t.category_id,
c.user_id
)
@cooncesean
cooncesean / signal_handler.py
Created March 15, 2012 22:38
comment_was_posted signal handler
def log_new_comment(sender, comment, request, **kwargs):
" Update the appropriate TopPoster data after a new Comment is created. "
print 'comment', comment
if hasattr(comment.content_object, 'category'):
print 'logging.'
TopPosterLogger.incr_new_comment(comment.content_object.category.id, comment.user.id)
comment_was_posted.connect(log_new_comment)
- query_params = '?p='
+ query_params = '?'
if 'request' in context:
get = context['request'].GET
- if 'using' in get:
- query_params = '?%s&p=' % urlencode({'using': get['using']})
+ query_params += '&'.join(['%s=%s' % (k,v) for k, v in get.items() if k != 'p'])
+ query_params += '&p='
@cooncesean
cooncesean / empty_article_ids.py
Created March 19, 2012 07:02
Script to Re-Populate Deleted Authors on Tested
# This was executed on production to find all articles whos' Authors
# had been deleted
[a.id for a in Article.objects.filter(authors=None)]
[35,
46,
48,
50,
53,
56,
@cooncesean
cooncesean / create_categories.py
Created March 21, 2012 18:34
Create Ella Categories
from django.template.defaultfilters import slugify
from ella.core.models import Category
def create_category(title, parent):
Category.objects.create(
title=title,
slug=slugify(title),
tree_parent=parent,
site_id=1
)
@cooncesean
cooncesean / migration_script.py
Created March 28, 2012 21:53
User/Group Permission Management in Distillery.
from django.contrib.auth.models import User, Group, Permission
from django.contrib.contenttypes.models import ContentType
from ella.articles.models import Article
from ella.core.models import Listing, Publishable
from ella.photos.models import Photo, FormatedPhoto
from ella_galleries.models import Gallery, GalleryItem
from scout.podcasts.models import Podcast