本文整理汇总了Python中cuser.middleware.CuserMiddleware.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python CuserMiddleware.get_user方法的具体用法?Python CuserMiddleware.get_user怎么用?Python CuserMiddleware.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cuser.middleware.CuserMiddleware
的用法示例。
在下文中一共展示了CuserMiddleware.get_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unread_dialogs
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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 ""
示例2: bodega_actual
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
def bodega_actual():
user = CuserMiddleware.get_user()
cuenta = Cuenta.objects.filter(pk=user.pk).first()
if cuenta:
return cuenta.bodega
# end if
return None
示例3: pre_save
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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)
示例4: __init__
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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")
示例5: get_fields
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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
示例6: update
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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
示例7: save_model
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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)
示例8: clean
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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")
示例9: __init__
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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)
示例10: save
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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)
示例11: clean
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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")
示例12: create
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
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)
示例13: get_agency
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
def get_agency(user=None):
from agencies.models import Agency
if not user:
user = CuserMiddleware.get_user()
try:
agency = user.agent_profile.agency
except:
agency = Agency.objects.get(id=settings.DEFAULT_AGENCY_ID)
return agency
示例14: get_queryset
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
def get_queryset(self):
qs = super(NoteViewSet, self).get_queryset()
user = CuserMiddleware.get_user()
if user:
if user.is_superuser:
return qs
else:
return qs.filter(agency=get_agency())
else:
return qs.filter(agency=get_agency())
示例15: get_query_set
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import get_user [as 别名]
def get_query_set(self):
qs = super(AgencyIsolatedHstoreManager, self).get_query_set()
user = CuserMiddleware.get_user()
if user:
if user.is_superuser:
return qs
else:
return qs.filter(agency=get_agency())
else:
return qs.filter(agency=get_agency())