Exemplo n.º 1
0
 def to_dict(self):
     result = {
         'id': self.id,
         'type': self.type,
         'type_text': self.get_type_display(),
         'content': self.content,
         'create_user': self.create_user.id,
         'create_user_text': self.create_user.username,
         'create_time': strftime(self.create_time),
         'reply_content': self.reply_content,
         'reply_time': strftime(self.reply_time),
         'reply_read': self.reply_read
     }
     return result
Exemplo n.º 2
0
 def to_export_data(self):
     result = (
         self.platform,
         self.device_UID,
         self.device_machine,
         self.os_version,
         self.app_version,
         self.resolution,
         self.network_type,
         self.IP,
         strftime(self.start_time),
         strftime(self.end_time),
         self.user.username,
     )
     return result
Exemplo n.º 3
0
def order_recharge_save(request, user):
    """
    :param request:
        {
            "total_fee":10,
        }
    :param user:
    :return:
    """
    params = json.loads(request.body)
    try:
        total_fee = float(params['total_fee'])
    except Exception:
        return JSONError(u'参数无效!')

    if total_fee <= 0:
        return JSONError(u'无效的充值金额!')

    try:
        with transaction.atomic():
            order = Order.objects.create(
                type = Order.RECHARGE,
                total_fee = total_fee,
                create_user = user,
                status = Order.STATUS_DEFAULT
            )
            return JSONResponse({'data': {'order_no':order.no,'create_time':strftime(order.create_time)}})
    except ValueError, e:
        return JSONError(unicode(e))
Exemplo n.º 4
0
 def to_dict(self):
     result = {
         'id': self.id,
         'username': self.username,
         'name': self.name,
         'type': self.type,
         'type_text': self.get_type_display(),
         'is_superuser': self.is_superuser,
         'is_active': self.is_active,
         'last_login': strftime(self.last_login),
         'last_login_ip': self.last_login_ip,
         'time_locked': self.time_locked and strftime(self.time_locked)
         or '',
         'date_joined': strftime(self.date_joined),
     }
     return result
Exemplo n.º 5
0
 def to_dict(self):
     result = {
         'id': self.id,
         'platform': self.platform,
         'device_UID': self.device_UID,
         'device_machine': self.device_machine,
         'os_version': self.os_version,
         'app_version': self.app_version,
         'resolution': self.resolution,
         'network_type': self.network_type,
         'IP': self.IP,
         'start_time': strftime(self.start_time),
         'end_time': strftime(self.end_time),
         'user': self.user.id,
         'user_text': self.user.username,
     }
     return result
Exemplo n.º 6
0
 def to_dict(self):
     result = {
         'id': self.id,
         'status': self.status,
         'status_text': self.get_status_display(),
         'create_time': utils.strftime(self.create_time),
         'create_user_text': self.create_user.username
     }
     return result
Exemplo n.º 7
0
 def to_dict(self):
     result = {}
     result['mobile'] = self.mobile
     result['vcode'] = self.vcode
     result['add_time'] = strftime(self.add_time)
     result['type'] = self.type
     result['type_text'] = self.get_type_display()
     result['status'] = self.status
     result['status_text'] = self.get_status_display()
     return result
Exemplo n.º 8
0
 def to_dict(self):
     result = {
         'id': self.id,
         'notes': self.notes,
         'balance': self.balance,
         'code': self.code.code,
         'subject': self.code.name,
         'create_time': strftime(self.create_time),
         'submitter': self.submitter.name
     }
     return result
Exemplo n.º 9
0
 def to_dict(self):
     result = {
         'id':self.id,
         'title':self.title,
         'create_time':strftime(self.create_time),
         # 'image':self.image.url if self.image else '',
         'detail':self.detail,
         'create_user':self.create_user.id,
         'create_user_name':self.create_user.name
     }
     return result
Exemplo n.º 10
0
 def to_dict(self):
     result = {
         'id': self.id,
         'type': self.type,
         'type_text': self.get_type_display(),
         'user': self.user and self.user.id or None,
         'user_text': self.user and self.user.username or '',
         'description': self.description,
         'create_time': strftime(self.create_time)
     }
     return result
Exemplo n.º 11
0
 def to_dict(self):
     result = {
         'id': self.id,
         'type': self.type,
         'type_text': self.get_type_display(),
         'total_fee': self.total_fee,
         'balance': self.balance,
         'description': self.description,
         'notes': self.notes,
         'create_user_text': self.create_user.username,
         'create_time': utils.strftime(self.create_time),
     }
     return result
Exemplo n.º 12
0
 def to_dict(self):
     result = {
         'id': self.id,
         'type': self.type,
         'account_bank': self.account_bank,
         'type_text': self.get_type_display(),
         'account_number': self.account_number,
         'account_name': self.account_name,
         'create_time': utils.strftime(self.create_time),
         'create_user': self.create_user.id,
         'create_user_text': self.create_user.username,
         'balance': self.create_user.balance,
     }
     return result
Exemplo n.º 13
0
 def to_dict(self):
     result = {
         'id': self.id,
         'no': self.no,
         'status': self.status,
         'type': self.type,
         'type_text': self.get_type_display(),
         'balance_before': self.balance_before,
         'balance_after': self.balance_after,
         'status_text': self.get_status_display(),
         'notes': self.notes,
         'total_fee': round(self.total_fee, 2),
         'account_bank': self.account_bank,
         'account_number': self.account_number,
         'account_name': self.account_name,
         'create_time': utils.strftime(self.create_time),
         'create_user_text': self.create_user.username,
         'create_user': self.create_user.name,
         'user_type_text': self.create_user.get_type_display()
     }
     return result
Exemplo n.º 14
0
def order_store_save(request, user):
    """
    :param request:
        {
            "lines": [
                {
                    "product": 1,
                    "price": 5,
                    "quantily": 2,
                    "amount":10
                }
            ],
            "consignee": "zhangsan",
            "mobile":"18677886655",
            "address":"aleee",
            "total_fee":10,
            "message":"hello"
        }
    :param user:
    :return:
    """
    params = json.loads(request.body)
    try:
        consignee = params['consignee'].strip()
        mobile = params['mobile'].strip()
        address = params['address'].strip()
        message = params['message'].strip()
        total_fee = float(params['total_fee'])
        lines = params['lines']
    except Exception:
        return JSONError(u'参数无效!')

    # if consignee == '':
    #     return JSONError(u'收货人不能为空!')
    # if mobile == '':
    #     return JSONError(u'电话不能为空!')
    # if address == '':
    #     return JSONError(u'地址不能为空!')

    try:
        with transaction.atomic():
            order = Order.objects.create(
                type = Order.STORE,
                total_fee = total_fee,
                create_user = user,
                status = Order.STATUS_DEFAULT
            )
            store = Store.objects.create(
                order=order,
                mobile=mobile,
                address=address,
                consignee=consignee,
                message=message
            )

            amount = 0
            for line in lines:
                amount += float(line['amount'])

                StoreLine.objects.create(
                    order = order,
                    main = store,
                    product_id = line['product'],
                    quantily = line['quantily'],
                    price = line['price'],
                    amount = line['amount']
                )
                Cart.objects.filter(create_user=user,product_id=line['product']).delete()

            if amount <> total_fee:
                raise ValueError(u'金额错误!')

            return JSONResponse({'data': {'order_no':order.no,'create_time':strftime(order.create_time)}})
    except ValueError, e:
        return JSONError(unicode(e))