当前位置: 首页>>代码示例>>Python>>正文


Python middleware.CuserMiddleware类代码示例

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


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

示例1: test_current_user_field

 def test_current_user_field(self):
     user = User.objects.get(username="test")
     CuserMiddleware.set_user(user)
     TestModel.objects.create(name="TEST")
     CuserMiddleware.del_user()
     test_instance = TestModel.objects.get(name="TEST")
     self.assertEqual(test_instance.creator, user)
开发者ID:VoNov,项目名称:django-cuser,代码行数:7,代码来源:tests.py

示例2: setUpTestData

 def setUpTestData(cls):
     cls.user = User.objects.create_user(
         username="Toto", email="", password="secret"
     )
     cls.user_repr = repr(cls.user)
     CuserMiddleware.set_user(cls.user)
     cls.pet = Pet.objects.create(name="Catz", age=12)
     cls.human = Human.objects.create(name="George", age=42, height=175)
     cls.human_repr = repr(cls.human)
开发者ID:makinacorpus,项目名称:django-tracking-fields,代码行数:9,代码来源:tests.py

示例3: setUp

 def setUp(self):
     self.user = User.objects.create_user(
         username="Toto", email="", password="secret"
     )
     self.user_repr = repr(self.user)
     CuserMiddleware.set_user(self.user)
     self.pet = Pet.objects.create(name="Catz", age=12)
     self.pet2 = Pet.objects.create(name="Catzou", age=1)
     self.human = Human.objects.create(name="George", age=42, height=175)
     self.human.pets.add(self.pet)
     self.human_repr = repr(self.human)
开发者ID:makinacorpus,项目名称:django-tracking-fields,代码行数:11,代码来源:tests.py

示例4: bodega_actual

 def bodega_actual():
     user = CuserMiddleware.get_user()
     cuenta = Cuenta.objects.filter(pk=user.pk).first()
     if cuenta:
         return cuenta.bodega
     # end if
     return None
开发者ID:exildev,项目名称:piscix_demo,代码行数:7,代码来源:models.py

示例5: pre_save

 def pre_save(self, model_instance, add):
     if add or not self.add_only:
         user = CuserMiddleware.get_user()
         if user:
             setattr(model_instance, self.attname, user.pk)
             return user.pk
     return super(CurrentUserField, self).pre_save(model_instance, add)
开发者ID:VoNov,项目名称:django-cuser,代码行数:7,代码来源:fields.py

示例6: save_model

	def save_model(self, request, obj, form, change):
		user = CuserMiddleware.get_user()
		service = Service.objects.filter(userservice__user = user).first()
		if service:
			obj.service = service
		#end if
		super(ClientAdmin, self).save_model(request, obj, form, change)
开发者ID:scriptquo,项目名称:pventa,代码行数:7,代码来源:admin.py

示例7: __init__

    def __init__(self, *args, **kwargs):
        super(NoSerialForm, self).__init__(*args, **kwargs)
        user = CuserMiddleware.get_user()
        cuenta = inv.Cuenta.objects.filter(pk=user.pk).first()
        if cuenta and self.fields.has_key('noserial'):
            self.fields['noserial'].queryset = inv.ActivoNoSerial.objects.filter(bodega=cuenta.bodega)

        # end if

        def clean(self):
            data = self.cleaned_data
            noserial = geo.GeoNoSerial.objects.filter(geoactivo=data['geoactivo'], noserial=data['noserial']).first()
            if noserial:
                raise forms.ValidationError("Ya tiene asignado/a una %s" % (data['noserial'].nombre))
            else:
                return data
            # end if

        # end def

        def clean_cantidad(self):
            if self.cleaned_data['cantidad']:
                cantidad = self.cleaned_data['cantidad']
                noserial = self.cleaned_data['noserial']
                if noserial:
                    if noserial.cantidad - cantidad < 0:
                        raise forms.ValidationError("La cantidad maxima disponible es %d" % (cantidad))
                    # end if
                    return cantidad
                # end if
                return forms.ValidationError("Seleccione un activo no serial")
            # end if
            return forms.ValidationError("Este campo es requerido")
开发者ID:mariobp,项目名称:geoactivos,代码行数:33,代码来源:forms.py

示例8: get_fields

	def get_fields(self, request, obj):
		fields = super(BillAdmin, self).get_fields(request, obj)
		user = CuserMiddleware.get_user()
		service = Service.objects.filter(userservice__user = user).first()
		if service:
			fields.remove('service')
		return fields
开发者ID:scriptquo,项目名称:pventa,代码行数:7,代码来源:admin.py

示例9: update

 def update(self, instance, validated_data):
     if not instance:
         return self.create(validated_data)
     #end if
     user = CuserMiddleware.get_user()
     service = venta.Service.objects.filter(userservice__user = user).first()
     
     order = instance
     if 'bill' in validated_data:
         order.bill = validated_data['bill']
     #end if
     if 'client' in validated_data:
         order.client  = validated_data['client']
     #end if
     if 'canceled' in validated_data:
         order.canceled  = validated_data['canceled']
     #end if
     order.service = service
     order.save()
     if 'products' in validated_data:
         order.products.all().delete()
         for item in validated_data['products']:
             itemorder = venta.ItemOrder.objects.create(product=item['product'], count=item['count'])
             order.products.add(itemorder)
         #end for
     #end if
     return order
开发者ID:scriptquo,项目名称:pventa,代码行数:27,代码来源:rest.py

示例10: unread_dialogs

def unread_dialogs():
	user = CuserMiddleware.get_user()
	if user.is_authenticated():
		d_count = get_unread_messages_count(user.id)
		if d_count > 0:
			return "+{}".format(d_count)
	return ""
开发者ID:enotikc,项目名称:np_station,代码行数:7,代码来源:chat_tags.py

示例11: clean

 def clean(self):
     if self.instance.pk == None:
         user = CuserMiddleware.get_user()
         cuenta = inventario.Cuenta.objects.filter(pk=user.pk).first()
         if cuenta:
             return super(ActivoInsumoForm, self).clean()
         else:
             raise forms.ValidationError("Necesita tener una cuenta de bodega para registrar el activo no serial")
开发者ID:exildev,项目名称:piscix_demo,代码行数:8,代码来源:forms.py

示例12: __init__

 def __init__(self, *args, **kwargs):
     super(SalidaInsumoForm, self).__init__(*args, **kwargs)
     user = CuserMiddleware.get_user()
     cuenta = inventario.Cuenta.objects.filter(pk=user.pk).first()
     if cuenta:
         self.fields['activos'].queryset = ActivoInsumo.objects.filter(
             Q(bodega=cuenta.bodega, vendido=False) | Q(salidainsumo=self.instance))
         self.fields['destino'].queryset = Bodega.objects.all().exclude(id=cuenta.bodega.id)
开发者ID:exildev,项目名称:piscix_demo,代码行数:8,代码来源:forms.py

示例13: save

 def save(self, *args, **kwargs):
     user = CuserMiddleware.get_user()
     cuenta = Cuenta.objects.filter(pk=user.pk).first()
     if cuenta:
         self.creado_por = cuenta
         self.salida = cuenta.bodega
         super(SalidaInsumo, self).save(*args, **kwargs)
         self.activos.update(bodega=None)
开发者ID:exildev,项目名称:piscix_demo,代码行数:8,代码来源:models.py

示例14: clean

 def clean(self):
     if self.instance.pk == None:
         user = CuserMiddleware.get_user()
         cuenta = inv.Cuenta.objects.filter(pk=user.pk).first()
         if cuenta:
             self.instance.creado_por = cuenta
             return super(GeoActivoForm, self).clean()
         else:
             raise forms.ValidationError("Necesita tener una cuenta para crear el Apta de Salida")
开发者ID:mariobp,项目名称:geoactivos,代码行数:9,代码来源:forms.py

示例15: create

 def create(self, validated_data):
     user = CuserMiddleware.get_user()
     service = venta.Service.objects.filter(userservice__user = user).first()
     row = {
         'name': validated_data['name'],
         'service': service,
         'image': validated_data['image']
     }
     return venta.Category.objects.create(**row)
开发者ID:scriptquo,项目名称:pventa,代码行数:9,代码来源:rest.py


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