12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import datetime
- from django.db import models
- from utils.util_add_id import gen_next_id
- from utils.util_create_file import create_version_file
- # Create your models here.
- class Software(models.Model):
- name = models.CharField(max_length=128, verbose_name='被测试软件名')
- id = models.CharField(max_length=128, unique=True, primary_key=True, verbose_name='被测试软件编号',
- default='TestLaboratory_V1_Software_1')
- type = models.CharField(max_length=20, verbose_name='被测试软件类型')
- creator_id = models.CharField(max_length=128, verbose_name='创建者id')
- company_id = models.IntegerField(verbose_name='公司id')
- report_file = models.TextField(null=True, verbose_name='测试报告id文件')
- create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
- update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
- delete = models.BooleanField(default=False)
- def __str__(self):
- return self.name
- class Meta:
- verbose_name = '被测试软件'
- verbose_name_plural = verbose_name
- db_table = 'software'
- class Version(models.Model):
- id = models.CharField(max_length=128, unique=True, primary_key=True, verbose_name='软件版本',
- default='TestLaboratory_V1_Version_1')
- number = models.CharField(max_length=20, verbose_name='版本号')
- software = models.ForeignKey(Software, on_delete=models.CASCADE, verbose_name='所属软件')
- version_file = models.TextField(verbose_name='软件路径id文件')
- create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
- update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
- delete = models.BooleanField(default=False)
- def __str__(self):
- return self.software.name + " " + self.number
- class Meta:
- verbose_name = '软件版本'
- verbose_name_plural = verbose_name
- db_table = 'version'
- def create_software(name, software_type, version_num, file):
- # duplicated
- # # step1:判断软件是否已存在
- # if Software.objects.filter(name=name):
- # return {'code': 500, 'msg': '被测试软件已存在,请修改软件名重新上传'}
- # step2:创建id和时间
- pass
- def get_software(name, software_type, sort):
- pass
- def create_version(software_id, version_num, file):
- # # step1:判断版本所属软件是否存在
- # software = Software.objects.filter(id=software_id, delete=False)
- # if not software:
- # return {'code': 500, 'msg': '被测软件不存在,请检查是否未创建或已删除'}
- # software = software[0]
- #
- # # step2:判断版本是否存在
- # software_version = software.version_set.filter(num=version_num, delete=False)
- # if software_version:
- # return {'code': 500, 'msg': '软件版本已存在,请修改版本号后重新上传'}
- #
- # # step3:上传版本软件实体到指定路径,返回文件路径
- # create_info = create_version_file(file, software.name, version_num)
- # if create_info['code'] != 200:
- # return create_info
- # file_path = create_info['file_path']
- #
- # # step4:创建版本id
- # id_version = None
- # if not Version.objects.order_by('create_time').last():
- # id_version = "Version_1"
- # else:
- # id_version = gen_next_id(Version.objects.order_by('create_time').last().id)
- #
- # # step5:设置创建时间和修改时间
- # create_time = update_time = datetime.datetime.now()
- #
- # # step6:数据库新增字段
- # version = Version.objects.create(id=id_version, num=version_num, software=software, create_time=create_time,
- # update_time=update_time, file=file_path)
- # return {'code': 200, 'msg': '新版本创建成功'}
- pass
|