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"
예제 #3
0
from django import forms
from djinn_profiles.utils import get_userprofile_model


UserProfile = get_userprofile_model()


class UserProfileForm(forms.ModelForm):

    class Meta:
        model = UserProfile
예제 #4
0
import logging
import json
from django.core.exceptions import ObjectDoesNotExist
from django.views.generic.detail import DetailView
from django.http import Http404
from django.http import HttpResponse
from djinn_profiles.utils import get_userprofile_model


UserProfile = get_userprofile_model()


log = logging.getLogger("pu_in_favorites")


class FavoritesView(DetailView):

    """ Favoritesview """

    model = UserProfile
    template_name = "favorites.html"

    def get_object(self, queryset=None):

        """ Find user profile from logged in user """

        try:
            self.obj = self.request.user.get_profile()
        except:
            raise Http404