Added processuser management command

This commit is contained in:
Fergal Moran
2013-04-23 14:18:45 +01:00
parent 520681837c
commit 2457f5e3e1
11 changed files with 51 additions and 27 deletions

View File

@@ -49,7 +49,7 @@ def unique_slugify(instance, value, slug_field_name='slug', queryset=None, slug_
slug = '%s%s' % (slug, end)
next += 1
setattr(instance, slug_field.attname, slug)
return slug
def _slug_strip(value, separator='-'):

View File

@@ -133,8 +133,8 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'spa.middleware.uploadify.SWFUploadMiddleware',
#'spa.middleware.sqlprinter.SqlPrintingMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
'spa.middleware.sqlprinter.SqlPrintingMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
WSGI_APPLICATION = 'dss.wsgi.application'
@@ -166,6 +166,7 @@ INSTALLED_APPS = (
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.google',
'debug_toolbar'
#'backbone_tastypie',
)
@@ -226,9 +227,9 @@ PIPELINE_CSS = {
},
},
}
INTERNAL_IPS = ('127.0.0.1', '86.44.166.21')
INTERNAL_IPS = ('127.0.0.1', '86.44.166.21', '192.168.1.111')
GOOGLE_ANALYTICS_CODE = localsettings.GOOGLE_ANALYTICS_CODE
#TASTYPIE_DATETIME_FORMATTING = 'iso-8601'
TASTYPIE_DATETIME_FORMATTING = 'rfc-2822'
SENDFILE_BACKEND = localsettings.SENDFILE_BACKEND
@@ -256,4 +257,4 @@ import mimetypes
mimetypes.add_type("text/xml", ".plist", False)
#HTML_MINIFY = not localsettings.DEBUG
HTML_MINIFY = not localsettings.DEBUG

View File

@@ -33,7 +33,7 @@ class UserResource(BackboneCompatibleResource):
def dehydrate(self, bundle):
#set the "me" user only properties
if bundle.obj.id == bundle.request.user.id:
if bundle.obj.user.id == bundle.request.user.id:
bundle.data['email'] = bundle.obj.email
if bundle.obj.activity_sharing is not None:
bundle.data['activity_share_likes'] = \

View File

@@ -2,6 +2,7 @@ from django.core.management.base import NoArgsCommand, CommandError
from django.template.defaultfilters import slugify
from core.utils.audio import Mp3FileNotFoundException
from core.utils.audio.mp3 import mp3_length
from core.utils.url import unique_slugify
from spa.models import Mix
@@ -20,7 +21,7 @@ class Command(NoArgsCommand):
mix.duration = length
if mix.slug == 'Invalid':
print "Slugifying mix: %s" % mix.title
mix.slug = slugify(mix.title)
mix.slug = unique_slugify(mix, mix.title)
print "\tNew title: %s" % mix.slug
mix.save()
except Mp3FileNotFoundException, me:

View File

@@ -0,0 +1,21 @@
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import NoArgsCommand, CommandError
from spa.models import UserProfile
class Command(NoArgsCommand):
help = "Updates audio files with their durations"
def handle(self, *args, **options):
try:
candidates = User.objects.all()
for user in candidates:
try:
profile = user.get_profile()
except ObjectDoesNotExist, ce:
print "Creating profile for %s" % user.get_username()
UserProfile.objects.create(user=user)
user.save()
except Exception, ex:
raise CommandError(ex.message)

View File

@@ -36,6 +36,9 @@ class SqlPrintingMiddleware(object):
"""
def process_response(self, request, response):
if not settings.DEBUG:
return
indentation = 2
if len(connection.queries) > 0 and settings.DEBUG:
width = terminal_width()
@@ -43,7 +46,7 @@ class SqlPrintingMiddleware(object):
for query in connection.queries:
nice_sql = query['sql'].replace('"', '').replace(',', ', ')
sql = "\033[1;31m[%s]\033[0m %s" % (query['time'], nice_sql)
total_time = total_time + float(query['time'])
total_time += float(query['time'])
while len(sql) > width - indentation:
print "%s%s" % (" " * indentation, sql[:width - indentation])
sql = sql[width - indentation:]

View File

@@ -11,7 +11,7 @@ class Genre(_BaseModel):
def save(self, force_insert=False, force_update=False, using=None):
if not self.slug:
unique_slugify(self, self.description, slug_separator='_')
self.description = unique_slugify(self, self.description, slug_separator='_')
super(Genre, self).save(force_insert, force_update, using)

View File

@@ -10,6 +10,7 @@ from django.db import models
from django.db.models import Count
from core.utils import url
from core.utils.url import unique_slugify
from spa.models.Genre import Genre
from spa.models.MixPlay import MixPlay
from spa.models.MixDownload import MixDownload
@@ -55,7 +56,7 @@ class Mix(_BaseModel):
def save(self, force_insert=False, force_update=False, using=None):
if not self.id:
self.slug = slugify(self.title)
self.slug = unique_slugify(self, self.title)
#TODO
#turn away now - horrid hack to strip media root url

View File

@@ -1,7 +1,6 @@
import urlparse
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.exceptions import SuspiciousOperation
from django.db import models
from django.db.models.signals import post_save
@@ -57,14 +56,6 @@ class UserProfile(_BaseModel):
return super(UserProfile, self).save(force_insert, force_update, using)
"""
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
"""
def get_username(self):
return self.user.username
@@ -149,3 +140,12 @@ class UserProfile(_BaseModel):
@classmethod
def get_default_avatar_image(cls):
return urlparse.urljoin(settings.STATIC_URL, "img/default-avatar-32.png")
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)

View File

@@ -24,10 +24,8 @@ def app(request):
def default(request):
if 'HTTP_USER_AGENT' in request.META:
if request.META['HTTP_USER_AGENT'].startswith('facebookexternalhit'):
logger.debug("Redirecting facebook hit")
return social_redirect(request)
if 'HTTP_USER_AGENT' in request.META and request.META['HTTP_USER_AGENT'].startswith('facebookexternalhit'):
return social_redirect(request)
backbone_url = "http://%s/#%s" % (request.get_host(), rreplace(lreplace(request.path, '/', ''), '/', ''))
return redirect(backbone_url)

View File

@@ -51,11 +51,10 @@ window.UserView = DSSEditableView.extend({
this._saveChanges({
success:function () {
com.podnoms.utils.showAlert("Success", "Successfully updated yourself");
Backbone.history.navigate('/me', {trigger:true});
Backbone.history.navigate('/', {trigger:true});
},
error:function () {
com.podnoms.utils.showAlert("Success", "Successfully updated yourself");
alert("Error");
com.podnoms.utils.showError("Error", "There was an error updating your info. Please try again later.");
}
});
return false;