-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
50 lines (38 loc) · 1.27 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime
from enum import Enum
from typing import List, Optional, Union
from beanie import Document, Link
from pydantic import BaseModel, EmailStr, Field, HttpUrl, validator
class StringEnum(str, Enum):
pass
class RepositoryType(StringEnum):
ZENODO = "zenodo"
HYDROSHARE = "hydroshare"
EARTHCHEM = "earthchem"
EXTERNAL = "external"
class Submission(Document):
title: str = None
authors: List[str] = []
repo_type: RepositoryType = None
identifier: str = None
submitted: datetime = datetime.utcnow()
url: HttpUrl = None
metadata_json: str = "{}"
@validator('authors', pre=True, allow_reuse=True)
def extract_author_names(cls, values):
authors = []
for author in values:
if hasattr(author, 'name'):
authors.append(author.name)
else:
authors.append(author)
return authors
class User(Document):
name: str
email: Optional[EmailStr]
orcid: str
access_token: Optional[str]
orcid_access_token: Optional[str]
submissions: List[Link[Submission]] = []
def submission(self, identifier: str) -> Submission:
return next(filter(lambda submission: submission.identifier == identifier, self.submissions), None)