models.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, verbose_name='测试计划执行者')
  16. state = models.IntegerField(verbose_name='测试计划执行状态')
  17. description = models.TextField(verbose_name='测试计划描述')
  18. statement_file = models.TextField(verbose_name='说明文档id路径')
  19. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  20. update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
  21. delete = models.BooleanField(default=False)
  22. def __str__(self):
  23. return self.title
  24. class Meta:
  25. verbose_name = '测试计划'
  26. verbose_name_plural = verbose_name
  27. db_table = 'plan'
  28. # def save_files(files, plan_id, time_stamp):
  29. # """
  30. #
  31. # """
  32. # fids = []
  33. # file_paths = []
  34. # for file in files:
  35. # try:
  36. # file_dir = PLAN_ROOT + "/" + plan_id + "/" + str(time_stamp)
  37. # if not os.path.exists(file_dir):
  38. # os.makedirs(file_dir)
  39. # file_path = file_dir + "/" + file.name
  40. # with open(file_path, 'wb') as f:
  41. # f.write(file.read())
  42. # f.close()
  43. # except:
  44. # return 0
  45. #
  46. # if not FileManager.objects.last():
  47. # id_file = "TestLaboratory_V1_File_1"
  48. # else:
  49. # id_file = gen_next_id(FileManager.objects.order_by('create_time').last().id)
  50. #
  51. # try:
  52. # file_new = FileManager.objects.create(id=id_file, category="plan_statement",
  53. # path=plan_id + "/" + str(time_stamp) + "/" + file.name,
  54. # create_time=time_stamp,
  55. # update_time=time_stamp)
  56. # except:
  57. # return 1
  58. # file_paths.append(PLAN_ROOT + file_new.path)
  59. # fids.append(id_file)
  60. # return file_paths, fids