• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.get_profile_model函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中userena.utils.get_profile_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_profile_model函数的具体用法?Python get_profile_model怎么用?Python get_profile_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_profile_model函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_no_profile

 def test_no_profile(self):
     """ Check for warning when there is no profile """
     # TODO: Dirty! Currently we check for the warning by getting a 100%
     # test coverage, meaning that it dit output some warning.
     user = UserenaSignup.objects.create_user(**self.user_info)
     
     # remove the profile of this user
     get_profile_model().objects.get(user=user).delete()
     
     # run the command to check for the warning.
     call_command('check_permissions', test=True)
开发者ID:Atreia,项目名称:grad_project,代码行数:11,代码来源:commands.py


示例2: check_permissions

    def check_permissions(self):
        """
        Checks that all permissions are set correctly for the users.

        :return: A set of users whose permissions was wrong.

        """
        # Variable to supply some feedback
        changed_permissions = []
        changed_users = []
        warnings = []

        # Check that all the permissions are available.
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == 'profile':
                model_obj = get_profile_model()
            else: model_obj = get_user_model()
            model_content_type = ContentType.objects.get_for_model(model_obj)
            for perm in perms:
                try:
                    Permission.objects.get(codename=perm[0],
                                           content_type=model_content_type)
                except Permission.DoesNotExist:
                    changed_permissions.append(perm[1])
                    Permission.objects.create(name=perm[1],
                                              codename=perm[0],
                                              content_type=model_content_type)

        # it is safe to rely on settings.ANONYMOUS_USER_ID since it is a
        # requirement of django-guardian
        for user in get_user_model().objects.exclude(id=settings.ANONYMOUS_USER_ID):
            try:
                user_profile = user.get_profile()
            except get_profile_model().DoesNotExist:
                warnings.append(_("No profile found for %(username)s") \
                                    % {'username': user.username})
            else:
                all_permissions = get_perms(user, user_profile) + get_perms(user, user)

                for model, perms in ASSIGNED_PERMISSIONS.items():
                    if model == 'profile':
                        perm_object = user.get_profile()
                    else: perm_object = user

                    for perm in perms:
                        if perm[0] not in all_permissions:
                            assign(perm[0], user, perm_object)
                            changed_users.append(user)

        return (changed_permissions, changed_users, warnings)
开发者ID:hshaheucleia,项目名称:web-demo,代码行数:50,代码来源:managers.py


示例3: create_profile_and_userdetail

   def create_profile_and_userdetail(self, user):
      userDetail = UserDetail()
      userDetail.user = user
      userDetail.save()
      userena_profile = UserenaSignup.objects.create_userena_profile(user)

      # All users have an empty profile
      profile_model = get_profile_model()
      try:
         new_profile = user.get_profile()
      except profile_model.DoesNotExist:
         new_profile = profile_model(user=user)
         new_profile.save(using=self._db)

      # Give permissions to view and change profile
      for perm in ASSIGNED_PERMISSIONS['profile']:
         assign(perm[0], user, new_profile)

      # Give permissions to view and change itself
      for perm in ASSIGNED_PERMISSIONS['user']:
         assign(perm[0], user, user)

      if settings.USERENA_ACTIVATION_REQUIRED:
         userena_profile.send_activation_email()

      return user
开发者ID:adamfeuer,项目名称:ArtOfGratitude_app,代码行数:26,代码来源:managers.py


示例4: create_inactive_user

    def create_inactive_user(self, username, email, password):
        """
        A simple wrapper that creates a new ``User``.

        """
        now = datetime.datetime.now()

        new_user = User.objects.create_user(username, email, password)
        new_user.is_active = False
        new_user.save()

        userena_profile = self.create_userena_profile(new_user)

        # All users have an empty profile
        profile_model = get_profile_model()
        new_profile = profile_model(user=new_user)
        new_profile.save(using=self._db)

        # Give permissions to view and change profile
        for perm in PERMISSIONS['profile']:
            assign(perm, new_user, new_profile)

        # Give permissinos to view and change itself
        for perm in PERMISSIONS['user']:
            assign(perm, new_user, new_user)

        userena_profile.send_activation_email()

        return new_user
开发者ID:lukaszb,项目名称:django-userena,代码行数:29,代码来源:managers.py


示例5: get_context_data

    def get_context_data(self, username, extra_context=None, *args, **kwargs):
        context = super(ProfileDetailView, self).get_context_data(*args, **kwargs)
        
        user = get_object_or_404(get_user_model(),
                                 username__iexact=username)

        # Get profile
        profile_model = get_profile_model()
        try:
            profile = user.get_profile()
        except profile_model.DoesNotExist:
            profile = profile_model.objects.create(user=user)

        # Lookup badges
        services = profile.services.all()
        services_detailed = profile.service_detailed.all()
        badges = ServiceBadge.objects.filter(services__in=services).distinct().order_by('category')
        
        for b in badges:
            b.user_services = []
            for service_detailed in services_detailed:
                if service_detailed.service in b.services.all():
                    b.user_services.append(service_detailed)

        # Check perms
        if not profile.can_view_profile(self.request.user):
            return HttpResponseForbidden(_("You don't have permission to view this profile."))

        # context
        context['profile'] = profile
        context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
        context['badges'] = badges

        return context
开发者ID:CommonsDev,项目名称:coack.me,代码行数:34,代码来源:views.py


示例6: check_permissions

    def check_permissions(self):
        """
        Checks that all permissions are set correctly for the users.

        :return: A set of users whose permissions was wrong.

        """
        # Variable to supply some feedback
        changed_permissions = []
        changed_users = []
        warnings = []

        # Check that all the permissions are available.
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == "profile":
                model_obj = get_profile_model()
            else:
                model_obj = User
            model_content_type = ContentType.objects.get_for_model(model_obj)
            for perm in perms:
                try:
                    Permission.objects.get(codename=perm[0], content_type=model_content_type)
                except Permission.DoesNotExist:
                    changed_permissions.append(perm[1])
                    Permission.objects.create(name=perm[1], codename=perm[0], content_type=model_content_type)

        for user in User.objects.all():
            if not user.username == "AnonymousUser":
                try:
                    user_profile = user.get_profile()
                except get_profile_model().DoesNotExist:
                    warnings.append(_("No profile found for %(username)s") % {"username": user.username})
                else:
                    all_permissions = get_perms(user, user_profile) + get_perms(user, user)

                    for model, perms in ASSIGNED_PERMISSIONS.items():
                        if model == "profile":
                            perm_object = user.get_profile()
                        else:
                            perm_object = user

                        for perm in perms:
                            if perm[0] not in all_permissions:
                                assign(perm[0], user, perm_object)
                                changed_users.append(user)

        return (changed_permissions, changed_users, warnings)
开发者ID:fberger,项目名称:django-userena,代码行数:47,代码来源:managers.py


示例7: create_user

    def create_user(self, username, email, password, active=False,
                    send_email=True, firstname=''):
        """
        A simple wrapper that creates a new :class:`User`.

        :param username:
            String containing the username of the new user.

        :param email:
            String containing the email address of the new user.

        :param password:
            String containing the password for the new user.

        :param active:
            Boolean that defines if the user requires activation by clicking 
            on a link in an e-mail. Defauts to ``True``.

        :param send_email:
            Boolean that defines if the user should be send an email. You could
            set this to ``False`` when you want to create a user in your own
            code, but don't want the user to activate through email.

        :return: :class:`User` instance representing the new user.

        """
        now = timezone.now()

        new_user = User.objects.create_user(username, email, password)
        new_user.first_name = firstname
        new_user.is_active = active
        new_user.save()

        userena_profile = self.create_userena_profile(new_user)

        # All users have an empty profile
        profile_model = get_profile_model()
        try:
            new_profile = new_user.get_profile()
        except profile_model.DoesNotExist:
            new_profile = profile_model(user=new_user)
            new_profile.save(using=self._db)

        # Give permissions to view and change profile
        for perm in ASSIGNED_PERMISSIONS['profile']:
            assign(perm[0], new_user, new_profile)

        # Give permissions to view and change itself
        for perm in ASSIGNED_PERMISSIONS['user']:
            assign(perm[0], new_user, new_user)

        if send_email:
            userena_profile.send_activation_email()

        # Send the signup complete signal
        userena_signals.signup_complete.send(sender=None,
                                             user=new_user)

        return new_user
开发者ID:FranciscoJRA,项目名称:agora-ciudadana,代码行数:59,代码来源:managers.py


示例8: get_queryset

    def get_queryset(self):

        logging.error(get_user_profile(self.request.user).__dict__)
        profile_model = get_profile_model()
        logging.error(profile_model.__dict__)
        logging.error(profile_model.objects.all())
        logging.error(profile_model.__doc__)
##        logging.error(self.__dict__)
##        logging.error(self.request.__dict__)
        queryset = profile_model.objects.get_visible_profiles(self.request.user).select_related()
        return queryset
开发者ID:behappyyoung,项目名称:pythonprojectm,代码行数:11,代码来源:views.py


示例9: create_user

    def create_user(self, form_data, active=False,
                    send_email=True):
        """
        A simple wrapper that creates a new :class:`User`.

        :param username:
            String containing the username of the new user.

        :param email:
            String containing the email address of the new user.

        :param password:
            String containing the password for the new user.

        :param active:
            Boolean that defines if the user requires activation by clicking 
            on a link in an e-mail. Defauts to ``True``.

        :param send_email:
            Boolean that defines if the user should be send an email. You could
            set this to ``False`` when you want to create a user in your own
            code, but don't want the user to activate through email.

        :return: :class:`User` instance representing the new user.

        """
        username, email, password = (form_data['username'],
                                     form_data['email'],
                                     form_data['password1'])
        
        now = datetime.datetime.now()

        new_user = User.objects.create_user(username, email, password)
        new_user.is_active = active
        new_user.save()

        userena_profile = self.create_userena_profile(new_user)

        # All users have an empty profile
        profile_model = get_profile_model()
        try:
            new_profile = new_user.get_profile()
        except profile_model.DoesNotExist:
            profile_model.objects.create_profile(new_user=new_user, form_data=form_data)

        # Give permissions to view and change itself
        for perm in ASSIGNED_PERMISSIONS['user']:
            assign(perm[0], new_user, new_user)

        if send_email:
            userena_profile.send_activation_email()
 
        return new_user
开发者ID:florentin,项目名称:django-userena,代码行数:53,代码来源:managers.py


示例10: create_inactive_user

    def create_inactive_user(self, username, email, password=None, send_email=True):
        """
        A simple wrapper that creates a new :class:`User`.

        :param username:
            String containing the username of the new user.

        :param email:
            String containing the email address of the new user.

        :param password:
            String containing the password for the new user.

        :param send_email:
            Boolean that defines if the user should be send an email. You could
            set this to ``False`` when you want to create a user in your own
            code, but don't want the user to activate through email.

        :return: :class:`User` instance representing the new user.

        """
        now = datetime.datetime.now()

        if password:
            new_user = User.objects.create_user(username, email, password)
        else:
            new_user = User.objects.create_user(username, email)
        new_user.is_active = False
        new_user.save()

        userena_profile = self.create_userena_profile(new_user)

        # All users have an empty profile
        profile_model = get_profile_model()
        new_profile = profile_model(user=new_user)
        new_profile.save(using=self._db)

        # Give permissions to view and change profile
        for perm in PERMISSIONS['profile']:
            assign(perm, new_user, new_profile)

        # Give permissinos to view and change itself
        for perm in PERMISSIONS['user']:
            assign(perm, new_user, new_user)

        if send_email:
            userena_profile.send_activation_email()

        # Send the signup complete signal
        userena_signals.signup_complete.send(sender=None,
                                             user=new_user)

        return new_user
开发者ID:sayanchowdhury,项目名称:django-userena,代码行数:53,代码来源:managers.py


示例11: has_profile

def has_profile(user):
    """Test utility function to check if user has profile"""
    profile_model = get_profile_model()
    try:
        profile = user.get_profile()
    except AttributeError:
        related_name = profile_model._meta.get_field('user')\
                                    .related_query_name()
        profile = getattr(user, related_name, None)
    except profile_model.DoesNotExist:
        profile = None

    return bool(profile)
开发者ID:AmmsA,项目名称:django-userena,代码行数:13,代码来源:tests_middleware.py


示例12: profile_detail

def profile_detail(request, username,extra_context=None, **kwargs):

    template_name = 'userena/profile_detail.html'
    user = get_object_or_404(get_user_model(),
                             username__iexact=username)
    profile_model = get_profile_model()
    try:
        profile = user.get_profile()
    except profile_model.DoesNotExist:
        profile = profile_model.objects.create(user=user)

    if not profile.can_view_profile(request.user):
        raise PermissionDenied
    return render(request, template_name, {'profile': profile,'bulletins' : Post.objects.filter(tag1='announcement').order_by("-time")})
开发者ID:ck520702002,项目名称:TFT_project,代码行数:14,代码来源:views.py


示例13: profile_detail

def profile_detail(request, username,
    template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE,
    extra_context=None, **kwargs):
    """
    Detailed view of an user.

    :param username:
        String of the username of which the profile should be viewed.

    :param template_name:
        String representing the template name that should be used to display
        the profile.

    :param extra_context:
        Dictionary of variables which should be supplied to the template. The
        ``profile`` key is always the current profile.

    **Context**

    ``profile``
        Instance of the currently viewed ``Profile``.

    """
    user = get_object_or_404(get_user_model(),
                             username__iexact=username)

    if Pago.objects.filter(user=user).exists():
        last_pago = Pago.objects.filter(user=user).order_by('-fecha_expiracion').get()
    else:
        last_pago = None

    today = date.today()

    profile_model = get_profile_model()
    try:
        profile = user.get_profile()
    except profile_model.DoesNotExist:
        profile = profile_model.objects.create(user=user)


    if not profile.can_view_profile(request.user):
        return HttpResponseForbidden(_("You don't have permission to view this profile."))
    if not extra_context: extra_context = dict()
    extra_context['profile'] = user.get_profile()
    extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
    if last_pago is None or last_pago.fecha_expiracion < today:
        extra_context['suscripcion_status'] = "Inactiva"
    return ExtraContextTemplateView.as_view(template_name=template_name,
                                            extra_context=extra_context)(request)
开发者ID:omaraf,项目名称:helloowsweb,代码行数:49,代码来源:views.py


示例14: profile_detail

def profile_detail(request, username, template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE, extra_context=None, **kwargs):
    """
    Detailed view of an user.

    :param username:
        String of the username of which the profile should be viewed.

    :param template_name:
        String representing the template name that should be used to display
        the profile.

    :param extra_context:
        Dictionary of variables which should be supplied to the template. The
        ``profile`` key is always the current profile.

    **Context**

    ``profile``
        Instance of the currently viewed ``Profile``.

    """
    user = get_object_or_404(get_user_model(),
                             username__iexact=username)

    profile_model = get_profile_model()
    try:
        profile = user.get_profile()
    except profile_model.DoesNotExist:
        profile = profile_model.objects.create(user=user)

    if not profile.can_view_profile(request.user):
        return HttpResponseForbidden(_("You don't have permission to view this profile."))
    if not extra_context:
        extra_context = dict()
    
    extra_context['profile'] = user.get_profile()
    extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
    extra_context['location'] = request.user_location["user_location_lat_lon"]
    extra_context['is_admin'] = user.is_superuser
    extra_context['per_page'] = int(request.GET.get('per_page', 6))

    tabs_page = "profile-detail"
    active_tab = request.session.get(tabs_page, "account-events")
    extra_context['active_tab'] = active_tab

    return ExtraContextTemplateView.as_view(
        template_name=template_name,
        extra_context=extra_context
    )(request)    
开发者ID:dany431,项目名称:cityfusion,代码行数:49,代码来源:views.py


示例15: profile_detail

def profile_detail(request, username,
    template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE,
    extra_context=None, **kwargs):
    """
    Detailed view of an user.

    :param username:
        String of the username of which the profile should be viewed.

    :param template_name:
        String representing the template name that should be used to display
        the profile.

    :param extra_context:
        Dictionary of variables which should be supplied to the template. The
        ``profile`` key is always the current profile.

    **Context**

    ``profile``
        Instance of the currently viewed ``Profile``.

    """
    user = get_object_or_404(get_user_model(),
                             username__iexact=username)
    ganaderia = 'Sin asignar'
    if Ganaderia.objects.all():
        if Ganaderia.objects.filter(perfil=user.id):
            ganaderia = Ganaderia.objects.get(perfil=user.id)

    profile_model = get_profile_model()
    try:
        profile = user.get_profile()
    except profile_model.DoesNotExist:
        profile = profile_model.objects.create(user=user)

    if not profile.can_view_profile(request.user):
        raise PermissionDenied
    if not extra_context: extra_context = dict()
    extra_context['profile'] = user.get_profile()
    extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
    extra_context['ganaderia'] = ganaderia
    return ExtraContextTemplateView.as_view(template_name=template_name,
                                            extra_context=extra_context)(request)
开发者ID:mricharleon,项目名称:HatosGanaderos,代码行数:44,代码来源:views.py


示例16: create_user

    def create_user(self, username, email, password, active=False,
                    send_email=True):
        """
        A simple wrapper that creates a new :class:`User`.

        :param username:
            String containing the username of the new user.

        :param email:
            String containing the email address of the new user.

        :param password:
            String containing the password for the new user.

        :param active:
            Boolean that defines if the user requires activation by clicking 
            on a link in an e-mail. Defauts to ``True``.

        :param send_email:
            Boolean that defines if the user should be send an email. You could
            set this to ``False`` when you want to create a user in your own
            code, but don't want the user to activate through email.

        :return: :class:`User` instance representing the new user.

        """
        new_user = User.objects.create_user(username, email, password)
        new_user.is_active = active
        new_user.save()

        userena_profile = self.create_userena_profile(new_user)

        # All users have an empty profile
        profile_model = get_profile_model()
        try:
            new_profile = new_user.get_profile()
        except profile_model.DoesNotExist:
            new_profile = profile_model(user=new_user)
            new_profile.save(using=self._db)

        if send_email:
            userena_profile.send_activation_email()

        return new_user
开发者ID:barszczmm,项目名称:django-easy-userena,代码行数:44,代码来源:managers.py


示例17: check_permissions

    def check_permissions(self):
        """
        Checks that all permissions are set correctly for the users.

        :return: A set of users whose permissions was wrong.

        """
        # Variable to supply some feedback
        warnings = []

        for user in User.objects.all():
            if not user.username == 'AnonymousUser':
                try:
                    user.get_profile()
                except get_profile_model().DoesNotExist:
                    warnings.append(_("No profile found for %(username)s") \
                                        % {'username': user.username})

        return warnings
开发者ID:barszczmm,项目名称:django-easy-userena,代码行数:19,代码来源:managers.py


示例18: profile_detail

def profile_detail(request, username):
    """
        Add extra context and returns userena_profile_detail view
    """
    extra_context = {}
    user = get_object_or_404(get_user_model(),
                             username__iexact=username)

    # Get profile
    profile_model = get_profile_model()
    profile = user.get_profile()
    # Check perms
    if not profile.can_view_profile(request.user):
        return HttpResponseForbidden(_("You don't have permission to view this profile."))

    # context
    extra_context['profile'] = profile
    extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL

    return userena_profile_detail(request=request, username=username, extra_context=extra_context)
开发者ID:CommonsDev,项目名称:unisson.co,代码行数:20,代码来源:views.py


示例19: profile_detail

def profile_detail(request, username,
    template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE,
    extra_context=None, **kwargs):

    user = get_object_or_404(get_user_model(),
                             username__iexact=username)

    profile_model = get_profile_model()
    
    try:
        profile = user.get_profile()
    except profile_model.DoesNotExist:
        profile = profile_model.objects.create(user=user)
            
    if not extra_context: extra_context = dict()
    extra_context['profile'] = user.get_profile()
    extra_context['company'] = Company.objects.get(id=profile.company_id)
    extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
    return ExtraContextTemplateView.as_view(template_name=template_name,
                                            extra_context=extra_context)(request)
开发者ID:dosberg,项目名称:Feedback,代码行数:20,代码来源:views.py


示例20: authenticate

    def authenticate(self, token=None):

        facebook_session = models.FacebookSession.objects.get(
            access_token=token,
        )

        profile = facebook_session.query('me')

        try:
            user = auth_models.User.objects.get(username=profile['id'])
        except auth_models.User.DoesNotExist, e:
            user = auth_models.User(username=profile['id'])



            user.set_unusable_password()
            user.email = profile['email']
            user.first_name = profile['first_name']
            user.last_name = profile['last_name']
            password = self.password_generate()
            user.set_password(password)

            user.email_user("Registrado en libreta", 'your username:'+user.username+'\n'+'your password:'+password)

            user.save()
            profile_model = get_profile_model()
            new_profile = profile_model(user=user)
            #new_profile.location = profile['hometown']['name']
            new_profile.facebook_url = profile['link']
            new_profile.save(using=self._db)

            for perm in PERMISSIONS['profile']:
                assign(perm, user, new_profile)

            for perm in PERMISSIONS['user']:
                assign(perm, user, user)

            try:
                models.FacebookSession.objects.get(uid=profile['id']).delete()
            except models.FacebookSession.DoesNotExist, e:
                pass
开发者ID:blamat88,项目名称:mangoproject,代码行数:41,代码来源:backends.py



注:本文中的userena.utils.get_profile_model函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_protocol函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_gravatar函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap