models.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import os
  2. from django.db import models
  3. # Create your models here.
  4. from TestLaboratory.settings import PLAN_ROOT
  5. from apps.file.models import FileManager
  6. from apps.software.models import Software
  7. from apps.user.models import User
  8. from utils.util_add_id import gen_next_id
  9. class TestPlan(models.Model):
  10. id = models.CharField(max_length=128, unique=True, primary_key=True, verbose_name='测试计划编号',
  11. default='TestLaboratory_V1_Plan_1')
  12. title = models.CharField(max_length=30, verbose_name='测试计划标题')
  13. software = models.ForeignKey(Software, on_delete=models.CASCADE, verbose_name='测试软件')
  14. version = models.CharField(max_length=20, verbose_name='软件版本')
  15. type = models.CharField(max_length=20,verbose_name='测试任务类型')
  16. creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, verbose_name='测试计划执行者')
  17. state = models.IntegerField(verbose_name='测试计划执行状态')
  18. company_id = models.IntegerField(verbose_name='公司id')
  19. description = models.TextField(verbose_name='测试计划描述')
  20. statement_file = models.TextField(verbose_name='说明文档id路径')
  21. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  22. update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
  23. delete = models.BooleanField(default=False)
  24. def __str__(self):
  25. return self.title
  26. class Meta:
  27. verbose_name = '测试计划'
  28. verbose_name_plural = verbose_name
  29. db_table = 'plan'
  30. # def save_files(files, plan_id, time_stamp):
  31. # """
  32. #
  33. # """
  34. # fids = []
  35. # file_paths = []
  36. # for file in files:
  37. # try:
  38. # file_dir = PLAN_ROOT + "/" + plan_id + "/" + str(time_stamp)
  39. # if not os.path.exists(file_dir):
  40. # os.makedirs(file_dir)
  41. # file_path = file_dir + "/" + file.name
  42. # with open(file_path, 'wb') as f:
  43. # f.write(file.read())
  44. # f.close()
  45. # except:
  46. # return 0
  47. #
  48. # if not FileManager.objects.last():
  49. # id_file = "TestLaboratory_V1_File_1"
  50. # else:
  51. # id_file = gen_next_id(FileManager.objects.order_by('create_time').last().id)
  52. #
  53. # try:
  54. # file_new = FileManager.objects.create(id=id_file, category="plan_statement",
  55. # path=plan_id + "/" + str(time_stamp) + "/" + file.name,
  56. # create_time=time_stamp,
  57. # update_time=time_stamp)
  58. # except:
  59. # return 1
  60. # file_paths.append(PLAN_ROOT + file_new.path)
  61. # fids.append(id_file)
  62. # return file_paths, fids