Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Update DB models to be compatible with DB client (#188)
Browse files Browse the repository at this point in the history
* Update DB models to be compatible with DB client

* Add DB ChallengeOrganizer.v
  • Loading branch information
tschaffter authored Oct 12, 2021
1 parent 5f97ea1 commit 2ac0529
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
6 changes: 5 additions & 1 deletion server/openapi_server/dbmodels/account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
from bson import ObjectId
from mongoengine import Document, ObjectIdField, StringField
from mongoengine import Document, ObjectIdField, StringField, IntField, DateTimeField # noqa: E501


class Account(Document):
Expand All @@ -9,6 +10,9 @@ class Account(Document):
required=True,
choices=["User", "Organization"]
)
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
v = IntField(db_field='__v')

meta = {'allow_inheritance': True}

Expand Down
9 changes: 7 additions & 2 deletions server/openapi_server/dbmodels/challenge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from bson import ObjectId
from mongoengine import DateTimeField, Document, ReferenceField, StringField, ObjectIdField, URLField, ListField # noqa: E501
import datetime
from mongoengine import DateTimeField, Document, ReferenceField, StringField, ObjectIdField, URLField, ListField, IntField # noqa: E501
# , ListField

from openapi_server.dbmodels.account import Account
from openapi_server.dbmodels.challenge_platform import ChallengePlatform
Expand All @@ -10,7 +12,7 @@ class Challenge(Document):
name = StringField(required=True)
displayName = StringField(min_length=3, max_length=60)
description = StringField(required=True)
fullName = StringField(required=True, unique=True)
fullName = StringField() # TODO restore required=True, unique=True after fixing JSON seed # noqa: E501
ownerId = ReferenceField(Account)
websiteUrl = URLField()
status = StringField(
Expand All @@ -22,6 +24,9 @@ class Challenge(Document):
platformId = ReferenceField(ChallengePlatform)
topics = ListField(StringField(unique=True), default=[])
doi = StringField()
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
v = IntField(db_field='__v')

# summary = StringField()
# startDate = DateTimeField()
Expand Down
3 changes: 2 additions & 1 deletion server/openapi_server/dbmodels/challenge_organizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from bson import ObjectId
from mongoengine import DateTimeField, Document, ObjectIdField, StringField, ListField, ReferenceField # noqa: E501
from mongoengine import DateTimeField, Document, ObjectIdField, StringField, ListField, ReferenceField, IntField # noqa: E501

from openapi_server.dbmodels.challenge import Challenge

Expand All @@ -13,6 +13,7 @@ class ChallengeOrganizer(Document):
challengeId = ReferenceField(Challenge, required=True)
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
v = IntField(db_field='__v')

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
3 changes: 2 additions & 1 deletion server/openapi_server/dbmodels/challenge_platform.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from bson import ObjectId
from mongoengine import DateTimeField, Document, ObjectIdField, StringField, URLField # noqa: E501
from mongoengine import DateTimeField, Document, ObjectIdField, StringField, URLField, IntField # noqa: E501


class ChallengePlatform(Document):
Expand All @@ -11,6 +11,7 @@ class ChallengePlatform(Document):
avatarUrl = URLField()
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
v = IntField(db_field='__v')

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
3 changes: 2 additions & 1 deletion server/openapi_server/dbmodels/challenge_readme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from bson import ObjectId
from mongoengine import DateTimeField, Document, ObjectIdField, StringField, ReferenceField # noqa: E501
from mongoengine import DateTimeField, Document, ObjectIdField, StringField, ReferenceField, IntField # noqa: E501

from openapi_server.dbmodels.challenge import Challenge

Expand All @@ -11,6 +11,7 @@ class ChallengeReadme(Document):
challengeId = ReferenceField(Challenge, required=True, unique=True)
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
v = IntField(db_field='__v')

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
6 changes: 5 additions & 1 deletion server/openapi_server/dbmodels/org_membership.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from mongoengine import Document, ReferenceField, StringField # noqa: E501
import datetime
from mongoengine import Document, ReferenceField, StringField, IntField, DateTimeField # noqa: E501

from openapi_server.dbmodels.organization import Organization
from openapi_server.dbmodels.user import User
Expand All @@ -15,6 +16,9 @@ class OrgMembership(Document):
)
organizationId = ReferenceField(Organization)
userId = ReferenceField(User, unique_with='organizationId')
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
v = IntField(db_field='__v')

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
5 changes: 1 addition & 4 deletions server/openapi_server/dbmodels/organization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
from mongoengine import DateTimeField, EmailField, StringField, URLField # noqa: E501
from mongoengine import EmailField, StringField, URLField # noqa: E501

from openapi_server.dbmodels.account import Account

Expand All @@ -10,8 +9,6 @@ class Organization(Account):
avatarUrl = URLField()
websiteUrl = URLField()
description = StringField()
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
5 changes: 1 addition & 4 deletions server/openapi_server/dbmodels/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
from mongoengine import DateTimeField, EmailField, StringField, URLField # noqa: E501
from mongoengine import EmailField, StringField, URLField # noqa: E501
from werkzeug.security import check_password_hash, generate_password_hash

from openapi_server.dbmodels.account import Account
Expand All @@ -10,8 +9,6 @@ class User(Account):
name = StringField(required=True)
avatarUrl = URLField()
bio = StringField()
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
passwordHash = StringField(required=True)

def to_dict(self):
Expand Down

0 comments on commit 2ac0529

Please sign in to comment.