def handle(self, *args, **options):

        UserProfile = get_userprofile_model()

        indicator = ""
        if not options["do-create"]:
            indicator = "DRY RUN: "
            print "\nDoing a dry-run\n"

        defaultfavorites_user, created = User.objects.get_or_create(username=settings.DEFAULT_FAVORITES_USERNAME)
        if defaultfavorites_user.get_profile().favoritesfolder_set.count() == 0:
            print "#######################################################################################"
            print "# WARNING"
            print "# user %s does not have default favoritesfolders and favorites yet. " % defaultfavorites_user.username
            print "# Add those from the django-admin screens first"
            print "# ...aborted"
            print "#######################################################################################"
            return

        for profile in UserProfile.objects.all():
            if profile.favoritesfolder_set.count() == 0:
                print "%sinitialising default favorites for %s" % (indicator, profile.slug)
                if options["do-create"]:
                    FavoritesFolder.create_defaults_for(profile)

            if options["do-create"]:
                userdefaultfolder = profile.favoritesfolder_set.all()[0]

        if not options["do-create"]:
            print "\nend of dry-run\n"
    def handle(self, *args, **options):

        UserProfile = get_userprofile_model()

        indicator = ''
        if not options['do-create']:
            indicator = 'DRY RUN: '
            print "\nDoing a dry-run\n"

        defaultfavorites_user, created = User.objects.get_or_create(
            username=settings.DEFAULT_FAVORITES_USERNAME)
        if defaultfavorites_user.get_profile().favoritesfolder_set.count(
        ) == 0:
            print "#######################################################################################"
            print "# WARNING"
            print "# user %s does not have default favoritesfolders and favorites yet. " % defaultfavorites_user.username
            print "# Add those from the django-admin screens first"
            print "# ...aborted"
            print "#######################################################################################"
            return

        for profile in UserProfile.objects.all():
            if profile.favoritesfolder_set.count() == 0:
                print "%sinitialising default favorites for %s" % (
                    indicator, profile.slug)
                if options['do-create']:
                    FavoritesFolder.create_defaults_for(profile)

            if options['do-create']:
                userdefaultfolder = profile.favoritesfolder_set.all()[0]

        if not options['do-create']:
            print "\nend of dry-run\n"
def userprofile_post_save(sender, instance, **kwargs):
    if kwargs.get("created", False):
        FavoritesFolder.create_defaults_for(instance)
def userprofile_post_save(sender, instance, **kwargs):
    if kwargs.get('created', False):
        FavoritesFolder.create_defaults_for(instance)