models.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import datetime
  2. from django.db import models
  3. from utils.util_add_id import gen_next_id
  4. from utils.util_create_file import create_version_file
  5. # Create your models here.
  6. class Software(models.Model):
  7. name = models.CharField(max_length=128, verbose_name='被测试软件名')
  8. id = models.CharField(max_length=128, unique=True, primary_key=True, verbose_name='被测试软件编号',
  9. default='TestLaboratory_V1_Software_1')
  10. type = models.CharField(max_length=20, verbose_name='被测试软件类型')
  11. creator_id = models.CharField(max_length=128, verbose_name='创建者id')
  12. company_id = models.IntegerField(verbose_name='公司id')
  13. report_file = models.TextField(null=True, verbose_name='测试报告id文件')
  14. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  15. update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
  16. delete = models.BooleanField(default=False)
  17. def __str__(self):
  18. return self.name
  19. class Meta:
  20. verbose_name = '被测试软件'
  21. verbose_name_plural = verbose_name
  22. db_table = 'software'
  23. class Version(models.Model):
  24. id = models.CharField(max_length=128, unique=True, primary_key=True, verbose_name='软件版本',
  25. default='TestLaboratory_V1_Version_1')
  26. number = models.CharField(max_length=20, verbose_name='版本号')
  27. software = models.ForeignKey(Software, on_delete=models.CASCADE, verbose_name='所属软件')
  28. version_file = models.TextField(verbose_name='软件路径id文件')
  29. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  30. update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
  31. delete = models.BooleanField(default=False)
  32. def __str__(self):
  33. return self.software.name + " " + self.number
  34. class Meta:
  35. verbose_name = '软件版本'
  36. verbose_name_plural = verbose_name
  37. db_table = 'version'
  38. def create_software(name, software_type, version_num, file):
  39. # duplicated
  40. # # step1:判断软件是否已存在
  41. # if Software.objects.filter(name=name):
  42. # return {'code': 500, 'msg': '被测试软件已存在,请修改软件名重新上传'}
  43. # step2:创建id和时间
  44. pass
  45. def get_software(name, software_type, sort):
  46. pass
  47. def create_version(software_id, version_num, file):
  48. # # step1:判断版本所属软件是否存在
  49. # software = Software.objects.filter(id=software_id, delete=False)
  50. # if not software:
  51. # return {'code': 500, 'msg': '被测软件不存在,请检查是否未创建或已删除'}
  52. # software = software[0]
  53. #
  54. # # step2:判断版本是否存在
  55. # software_version = software.version_set.filter(num=version_num, delete=False)
  56. # if software_version:
  57. # return {'code': 500, 'msg': '软件版本已存在,请修改版本号后重新上传'}
  58. #
  59. # # step3:上传版本软件实体到指定路径,返回文件路径
  60. # create_info = create_version_file(file, software.name, version_num)
  61. # if create_info['code'] != 200:
  62. # return create_info
  63. # file_path = create_info['file_path']
  64. #
  65. # # step4:创建版本id
  66. # id_version = None
  67. # if not Version.objects.order_by('create_time').last():
  68. # id_version = "Version_1"
  69. # else:
  70. # id_version = gen_next_id(Version.objects.order_by('create_time').last().id)
  71. #
  72. # # step5:设置创建时间和修改时间
  73. # create_time = update_time = datetime.datetime.now()
  74. #
  75. # # step6:数据库新增字段
  76. # version = Version.objects.create(id=id_version, num=version_num, software=software, create_time=create_time,
  77. # update_time=update_time, file=file_path)
  78. # return {'code': 200, 'msg': '新版本创建成功'}
  79. pass