1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import os
- from django.db import models
- # Create your models here.
- from TestLaboratory.settings import PLAN_ROOT
- from apps.file.models import FileManager
- from apps.software.models import Software
- from apps.user.models import User
- from utils.util_add_id import gen_next_id
- class TestPlan(models.Model):
- id = models.CharField(max_length=128, unique=True, primary_key=True, verbose_name='测试计划编号',
- default='TestLaboratory_V1_Plan_1')
- title = models.CharField(max_length=30, verbose_name='测试计划标题')
- software = models.ForeignKey(Software, on_delete=models.CASCADE, verbose_name='测试软件')
- version = models.CharField(max_length=20, verbose_name='软件版本')
- creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, verbose_name='测试计划执行者')
- state = models.IntegerField(verbose_name='测试计划执行状态')
- description = models.TextField(verbose_name='测试计划描述')
- statement_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.title
- class Meta:
- verbose_name = '测试计划'
- verbose_name_plural = verbose_name
- db_table = 'plan'
- # def save_files(files, plan_id, time_stamp):
- # """
- #
- # """
- # fids = []
- # file_paths = []
- # for file in files:
- # try:
- # file_dir = PLAN_ROOT + "/" + plan_id + "/" + str(time_stamp)
- # if not os.path.exists(file_dir):
- # os.makedirs(file_dir)
- # file_path = file_dir + "/" + file.name
- # with open(file_path, 'wb') as f:
- # f.write(file.read())
- # f.close()
- # except:
- # return 0
- #
- # if not FileManager.objects.last():
- # id_file = "TestLaboratory_V1_File_1"
- # else:
- # id_file = gen_next_id(FileManager.objects.order_by('create_time').last().id)
- #
- # try:
- # file_new = FileManager.objects.create(id=id_file, category="plan_statement",
- # path=plan_id + "/" + str(time_stamp) + "/" + file.name,
- # create_time=time_stamp,
- # update_time=time_stamp)
- # except:
- # return 1
- # file_paths.append(PLAN_ROOT + file_new.path)
- # fids.append(id_file)
- # return file_paths, fids
|