# Path: openunipay/weixin_pay/models.py
# class WeiXinOrder(models.Model):
#     appid = models.CharField(verbose_name=u'公众账号ID', max_length=32, editable=False)
#     mch_id = models.CharField(verbose_name=u'商户号', max_length=32, editable=False)
#     body = models.CharField(verbose_name=u'商品描述', max_length=128, editable=False)
#     attach = models.CharField(verbose_name=u'附加数据', max_length=127, null=True, blank=True, editable=False)
#     out_trade_no = models.CharField(verbose_name=u'商户订单号', max_length=32, db_index=True, editable=False)
#     fee_type = models.CharField(verbose_name=u'货币类型', max_length=16, editable=False)
#     total_fee = models.PositiveIntegerField(verbose_name=u'总金额', editable=False)
#     spbill_create_ip = models.CharField(verbose_name=u'终端IP', max_length=16, editable=False)
#     time_start = models.CharField(verbose_name=u'交易起始时间', max_length=14, editable=False)
#     time_expire = models.CharField(verbose_name=u'交易结束时间', max_length=14, editable=False)
#     notify_url = models.CharField(verbose_name=u'通知地址', max_length=256, editable=False)
#     trade_type = models.CharField(verbose_name=u'交易类型', max_length=16, editable=False)
#     openid = models.CharField(verbose_name=u'用户标识(openId)', null=True, blank=True, max_length=128, editable=False)
# 
#     class Meta:
#         verbose_name = u'微信统一订单'
#         verbose_name_plural = u'微信统一订单'
# 
#     def __str__(self):
#         return self.out_trade_no
# 
#     def _get_vlaue_dict(self):
#         fieldsList = WeiXinOrder._meta.get_fields()
#         return {item.attname: getattr(self, item.attname) for item in fieldsList if not item.auto_created and getattr(self, item.attname)}
# 
#     def to_xml(self):
#         # sign data
#         valueDict = self._get_vlaue_dict()
#         valueDict['nonce_str'] = random_helper.generate_nonce_str(23)
#         valueDict['sign'] = sign(valueDict)
#         return xml_helper.dict_to_xml(valueDict)


from django.contrib import admin
from .models import WeiXinOrder
from import_export import resources
from import_export.admin import ImportExportModelAdmin

# -*- coding: utf-8 -*-

class WeiXinOrderResource(resources.ModelResource):
    class Meta:
        model = WeiXinOrder
        import_id_fields = ('id',)

class WeiXinOrderAdmin(ImportExportModelAdmin):
    resource_class = WeiXinOrderResource
    # list page
    list_display = ('out_trade_no', 'body', 'attach', 'fee_type', 'total_fee', 'spbill_create_ip', 'time_start', 'time_expire', 'trade_type', 'get_pay_result')
    ordering = ('time_start',)
    search_fields = ['=out_trade_no', '=spbill_create_ip', ]
    
    def get_pay_result(self, obj):
        if hasattr(obj, 'pay_result'):
            return obj.pay_result
        else:
            return '-'
    get_pay_result.short_description = '支付结果'
    
    

# Path: openunipay/weixin_pay/models.py
# class WeiXinOrder(models.Model):
#     appid = models.CharField(verbose_name=u'公众账号ID', max_length=32, editable=False)
#     mch_id = models.CharField(verbose_name=u'商户号', max_length=32, editable=False)
#     body = models.CharField(verbose_name=u'商品描述', max_length=128, editable=False)
#     attach = models.CharField(verbose_name=u'附加数据', max_length=127, null=True, blank=True, editable=False)
#     out_trade_no = models.CharField(verbose_name=u'商户订单号', max_length=32, db_index=True, editable=False)
#     fee_type = models.CharField(verbose_name=u'货币类型', max_length=16, editable=False)
#     total_fee = models.PositiveIntegerField(verbose_name=u'总金额', editable=False)
#     spbill_create_ip = models.CharField(verbose_name=u'终端IP', max_length=16, editable=False)
#     time_start = models.CharField(verbose_name=u'交易起始时间', max_length=14, editable=False)
#     time_expire = models.CharField(verbose_name=u'交易结束时间', max_length=14, editable=False)
#     notify_url = models.CharField(verbose_name=u'通知地址', max_length=256, editable=False)
#     trade_type = models.CharField(verbose_name=u'交易类型', max_length=16, editable=False)
#     openid = models.CharField(verbose_name=u'用户标识(openId)', null=True, blank=True, max_length=128, editable=False)
# 
#     class Meta:
#         verbose_name = u'微信统一订单'
#         verbose_name_plural = u'微信统一订单'
# 
#     def __str__(self):
#         return self.out_trade_no
# 
#     def _get_vlaue_dict(self):
#         fieldsList = WeiXinOrder._meta.get_fields()
#         return {item.attname: getattr(self, item.attname) for item in fieldsList if not item.auto_created and getattr(self, item.attname)}
# 
#     def to_xml(self):
#         # sign data
#         valueDict = self._get_vlaue_dict()
#         valueDict['nonce_str'] = random_helper.generate_nonce_str(23)
#         valueDict['sign'] = sign(valueDict)
#         return xml_helper.dict_to_xml(valueDict)


# Path: openunipay/weixin_pay/admin.py
from django.contrib import admin
from .models import WeiXinOrder
from import_export import resources
from import_export.admin import ImportExportModelAdmin

# -*- coding: utf-8 -*-

class WeiXinOrderResource(resources.ModelResource):
    class Meta:
        model = WeiXinOrder
        import_id_fields = ('id',)

class WeiXinOrderAdmin(ImportExportModelAdmin):
    resource_class = WeiXinOrderResource
    # list page
    list_display = ('out_trade_no', 'body', 'attach', 'fee_type', 'total_fee', 'spbill_create_ip', 'time_start', 'time_expire', 'trade_type', 'get_pay_result')
    ordering = ('time_start',)
    search_fields = ['=out_trade_no', '=spbill_create_ip', ]
    
    def get_pay_result(self, obj):
        if hasattr(obj, 'pay_result'):
            return obj.pay_result
        else:
            return '-'
    get_pay_result.short_description = '支付结果'
    
    

admin.site.register(WeiXinOrder, WeiXinOrderAdmin)
