def fetch_profile(request):
    """ attaches the user.profile object into the request object"""

    context = {}
    if request.user.is_authenticated():
        profile = request.my_profile
        if profile:
            context[get_my_profile_module_name()] = profile
    return context
Exemplo n.º 2
0
def fetch_profile(request):
    """ attaches the user.profile object into the request object"""

    context = {}
    if request.user.is_authenticated():
        profile_module_name = get_my_profile_module_name()
        profile = getattr(request, profile_module_name, None)
        if profile != None:
            context[profile_module_name] = profile
    return context
def fetch_profile(request):
    """ attaches the user.profile object into the request object"""

    context = {}
    if request.user.is_authenticated():
        profile_module_name = get_my_profile_module_name()
        profile = getattr(request, profile_module_name, None)
        if profile != None:
            context[profile_module_name] = profile
    return context
Exemplo n.º 4
0
class ProfileForm(forms.ModelForm):
    class Meta:
        model = PROFILE_MODEL
        exclude = getattr(PROFILE_MODEL, "exclude", ('user', ))
        fields = getattr(PROFILE_MODEL, "fields", ())


########NEW FILE########
__FILENAME__ = middleware
from django.utils.functional import SimpleLazyObject

from profiletools.utils import get_profile, get_my_profile_module_name

# preload this variable
my_profile_module_name = get_my_profile_module_name()


class LazyProfileMiddleware(object):
    """Middleware to attach a lazy .profile value to all requests.
        This reduces the number of queries per request substantially
    """
    def process_request(self, request):
        self.user = request.user
        setattr(request.__class__, my_profile_module_name,
                SimpleLazyObject(lambda: get_profile(request.user)))


########NEW FILE########
__FILENAME__ = models
# Django boilerplate here
Exemplo n.º 5
0
from django.utils.functional import SimpleLazyObject

from profiletools.utils import get_profile, get_my_profile_module_name

# preload this variable
my_profile_module_name = get_my_profile_module_name()


class LazyProfileToUserMiddleware(object):
    """Middleware to attach a lazy .profile value to all requests.
        This reduces the number of queries per request substantially
    """

    def process_request(self, request):
        lazygetprofile = SimpleLazyObject(lambda: get_profile(request.user))
        setattr(request, my_profile_module_name, lazygetprofile)
        setattr(request.user, my_profile_module_name, lazygetprofile)
Exemplo n.º 6
0
 def process_request(self, request):
     self.user = request.user
     setattr(request.__class__, get_my_profile_module_name(), self.lazy_profile)