예제 #1
0
class TaskStep(db.EmbeddedDocument):
    number = db.IntField(required=False, default=0)
    comment = db.StringField(required=False, default='')
    timestamp = db.LongField(required=False, default=time.time)

    def to_dict(self):
        return dict(self.to_mongo(fields=['number', 'comment', 'timestamp']))
예제 #2
0
class FATask(db.Document):
    wav_url = db.StringField(required=False, dafault='')
    wav_tmp_path = db.StringField(required=False, dafault='/tmp/tmppath')
    request_srt_content = db.StringField(required=False, dafault='')
    result_srt_content = db.StringField(required=False, dafault='')
    steps = db.EmbeddedDocumentListField(TaskStep)
    timestamp = db.LongField(required=False, default=time.time)
    segment = db.BooleanField(required=False, dafault=False)

    meta = {
        'collection': 'fa_task',
        'index_background': True,
        'indexes': ['timestamp'],
        'strict': False
    }

    def add_step(self, step_obj):
        self.steps.append(step_obj)
        return self.save()

    def to_dict(self):
        json_obj = dict(
            self.to_mongo(fields=[
                'wav_url', 'request_srt_content', 'result_srt_content',
                'steps', 'timestamp', 'segment'
            ]))
        json_obj.pop('_id', '')

        json_obj['steps'] = []
        for step in self.steps:
            json_obj['steps'].append(step.to_dict())

        json_obj['task_id'] = str(self.pk)
        return json_obj
예제 #3
0
class NMTTask(db.Document):
    request_srt_content = db.StringField(required=False, dafault='')
    result_srt_content = db.StringField(required=False, dafault='')
    steps = db.EmbeddedDocumentListField(TaskStep)
    timestamp = db.LongField(required=False, default=time.time)
    lang = db.StringField(required=False, dafault='en')

    meta = {
        'collection': 'nmt_task',
        'index_background': True,
        'indexes': ['timestamp'],
        'strict': False
    }

    def add_step(self, step_obj):
        self.steps.append(step_obj)
        return self.save()

    def to_dict(self):
        json_obj = dict(
            self.to_mongo(fields=[
                'request_srt_content', 'result_srt_content', 'steps',
                'timestamp', 'lang'
            ]))
        json_obj.pop('_id', '')

        json_obj['steps'] = []
        for step in self.steps:
            json_obj['steps'].append(step.to_dict())

        json_obj['task_id'] = str(self.pk)
        return json_obj