Skip to content

Commit

Permalink
Merge pull request #11 from grahamu/fix8
Browse files Browse the repository at this point in the history
Moving post_save handler to receivers.py
  • Loading branch information
paltman committed Feb 12, 2016
2 parents 6da3362 + ff4a21a commit e6820d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions pinax/documents/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib

from django.apps import AppConfig as BaseAppConfig
from django.utils.translation import ugettext_lazy as _

Expand All @@ -6,3 +8,6 @@ class AppConfig(BaseAppConfig):

name = "pinax.documents"
verbose_name = _("Pinax Documents")

def ready(self):
importlib.import_module("pinax.documents.receivers")
9 changes: 0 additions & 9 deletions pinax/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils import timezone

from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -314,10 +312,3 @@ def color(self):
if p >= 90 and p <= 100:
return "danger"
raise ValueError("percentage out of range")


@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def ensure_userstorage(sender, **kwargs):
if kwargs["created"]:
user = kwargs["instance"]
UserStorage.objects.create(user=user, bytes_total=(1024 * 1024 * 50))
12 changes: 12 additions & 0 deletions pinax/documents/receivers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db.models.signals import post_save
from django.dispatch import receiver

from .conf import settings
from .models import UserStorage


@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def ensure_userstorage(sender, **kwargs):
if kwargs["created"]:
user = kwargs["instance"]
UserStorage.objects.create(user=user, bytes_total=(1024 * 1024 * 50))

0 comments on commit e6820d7

Please sign in to comment.