當前位置: 首頁>>代碼示例>>Python>>正文


Python models.User方法代碼示例

本文整理匯總了Python中core.models.User方法的典型用法代碼示例。如果您正苦於以下問題:Python models.User方法的具體用法?Python models.User怎麽用?Python models.User使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在core.models的用法示例。


在下文中一共展示了models.User方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: list

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def list(self, djangoClass, user):
        try:
            queryset = djangoClass.objects.all()
            filtered_queryset = (
                elt
                for elt in queryset
                if self.xos_security_check(elt, user, read_access=True)
            )

            # FIXME: Implement auditing here
            # logging.info("User requested x objects, y objects were filtered out by policy z")

            response = self.querysetToProto(djangoClass, filtered_queryset)
            return response
        except BaseException:
            log.exception("Exception in apihelper.list")
            raise 
開發者ID:open-cloud,項目名稱:xos,代碼行數:19,代碼來源:apihelper.py

示例2: xos_security_gate

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def xos_security_gate(self, obj, user, **access_types):
        sec_ctx = XOSDefaultSecurityContext()
        if not user:
            user = xos_anonymous_user

        sec_ctx.user = user

        for k, v in access_types.items():
            setattr(sec_ctx, k, v)

        verdict, policy_name = obj.can_access(ctx=sec_ctx)

        # FIXME: This is the central point of enforcement for security policies
        #        Implement Auditing here.
        #        logging.info( ... )

        if not verdict:
            #    logging.critical( ... )
            if obj.id:
                object_descriptor = "object %d" % obj.id
            else:
                object_descriptor = "new object"

            raise XOSPermissionDenied(
                "User %(user_email)s cannot access %(django_class_name)s %(descriptor)s due to policy %(policy_name)s"
                % {
                    "user_email": user.email,
                    "django_class_name": obj.__class__.__name__,
                    "policy_name": policy_name,
                    "descriptor": object_descriptor,
                }
            ) 
開發者ID:open-cloud,項目名稱:xos,代碼行數:34,代碼來源:apihelper.py

示例3: pm_name_field

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def pm_name_field(self, obj):
        user = get_object_or_404(models.User, id=obj.proposed_by.id)
        return user.name 
開發者ID:LukaszMalucha,項目名稱:Project-Dashboard-with-Django,代碼行數:5,代碼來源:serializers.py

示例4: pm_email_field

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def pm_email_field(self, obj):
        user = get_object_or_404(models.User, id=obj.proposed_by.id)
        return user.email 
開發者ID:LukaszMalucha,項目名稱:Project-Dashboard-with-Django,代碼行數:5,代碼來源:serializers.py

示例5: clean_email

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def clean_email(self):
        email = self.cleaned_data.get('email')
        if User.objects.filter(email=email):
            raise forms.ValidationError(u'Email addresses must be unique.')
        return email 
開發者ID:LukaszMalucha,項目名稱:Project-Dashboard-with-Django,代碼行數:7,代碼來源:forms.py

示例6: get_email

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def get_email(self):
        user = get_object_or_404(User, id=self.assigned_to.id)
        return user.email 
開發者ID:LukaszMalucha,項目名稱:Project-Dashboard-with-Django,代碼行數:5,代碼來源:models_project.py

示例7: get_name

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def get_name(self):
        user = get_object_or_404(User, id=self.member.id)
        return user.name 
開發者ID:LukaszMalucha,項目名稱:Project-Dashboard-with-Django,代碼行數:5,代碼來源:models_project.py

示例8: filter

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def filter(self, djangoClass, user, request):
        try:
            if request.kind == request.DEFAULT:
                query = self.build_filter(request, None)
                queryset = djangoClass.objects.filter(query)
            elif request.kind == request.SYNCHRONIZER_DIRTY_OBJECTS:
                query = (
                    (
                        Q(enacted=None)
                        | Q(enacted__lt=F("updated"))
                        | Q(enacted__lt=F("changed_by_policy"))
                    )
                    & Q(lazy_blocked=False)
                    & Q(no_sync=False)
                )
                query = self.build_filter(request, query)
                queryset = djangoClass.objects.filter(query)
            elif request.kind == request.SYNCHRONIZER_DELETED_OBJECTS:
                query = self.build_filter(request, None)
                if query:
                    queryset = djangoClass.deleted_objects.filter(query)
                else:
                    queryset = djangoClass.deleted_objects.all()
            elif request.kind == request.SYNCHRONIZER_DIRTY_POLICIES:
                query = (
                    Q(policed=None)
                    | Q(policed__lt=F("updated"))
                    | Q(policed__lt=F("changed_by_step"))
                ) & Q(no_policy=False)
                query = self.build_filter(request, query)
                queryset = djangoClass.objects.filter(query)
            elif request.kind == request.SYNCHRONIZER_DELETED_POLICIES:
                query = Q(policed__lt=F("updated")) | Q(policed=None)
                query = self.build_filter(request, query)
                queryset = djangoClass.deleted_objects.filter(query)
            elif request.kind == request.ALL:
                queryset = djangoClass.objects.all()

            filtered_queryset = (
                elt
                for elt in queryset
                if self.xos_security_check(elt, user, read_access=True)
            )

            # FIXME: Implement auditing here
            # logging.info("User requested x objects, y objects were filtered out by policy z")

            response = self.querysetToProto(djangoClass, filtered_queryset)
            return response
        except BaseException:
            log.exception("Exception in apihelper.filter")
            raise 
開發者ID:open-cloud,項目名稱:xos,代碼行數:54,代碼來源:apihelper.py

示例9: search

# 需要導入模塊: from core import models [as 別名]
# 或者: from core.models import User [as 別名]
def search(request, *args, **kwargs):
  payload = json.loads(request.body.decode())

  if 'steam' in payload:
    steamid = SteamID.from_url('https://steamcommunity.com/id/' + payload['steam'])
    if not steamid:
      data = []
    else:
      data = User.objects.filter(username=str(steamid.as_64))
      if not data:
        user = User()
        user.is_steam = True
        user.is_active = False
        user.username = str(steamid.as_64)
        user.save()

        populate(user)
        data = [user]

  elif 'steam64' in payload:
    data = User.objects.filter(username=str(payload['steam64']))
    if not data:
      user = User()
      user.is_steam = True
      user.is_active = False
      user.username = str(payload['steam64'])

      populate(user)
      data = [user]

  elif 'local' in payload:
    data = User.objects.filter(is_steam=True, namespace__icontains=payload['local'])
    data = list(data)

  elif 'steam' in payload:
    user = User()
    user.is_steam = False
    user.is_active = False
    user.username = payload['steam']
    user.save()

    data = [user]

  return render(request, 'components/globals/dropdown/wrapper.pug',
                {'data': data[:settings.PAGE_SIZE]}) 
開發者ID:indietyp,項目名稱:hawthorne,代碼行數:47,代碼來源:utils.py


注:本文中的core.models.User方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。