models.py 3.7 KB

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