API & Client: Activity display update

This commit is contained in:
Sam
2018-05-16 23:52:55 +02:00
parent 3047655e1f
commit ca80a8b6d5
19 changed files with 229 additions and 91 deletions

View File

@ -76,6 +76,8 @@ class Sport(db.Model):
__tablename__ = "sports"
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
label = db.Column(db.String(50), unique=True, nullable=False)
img = db.Column(db.String(255), unique=True, nullable=True)
is_default = db.Column(db.Boolean, default=False, nullable=False)
activities = db.relationship('Activity',
lazy=True,
backref=db.backref('sports', lazy='joined'))
@ -93,7 +95,9 @@ class Sport(db.Model):
return {
'id': self.id,
'label': self.label,
'_can_be_deleted': len(self.activities) == 0
'img': self.img,
'_can_be_deleted':
len(self.activities) == 0 and not self.is_default
}

View File

@ -43,7 +43,7 @@ def create_activity(
duration=duration
)
if title is not None:
if title is not None and title != '':
new_activity.title = title
else:
sport = Sport.query.filter_by(id=new_activity.sport_id).first()

View File

@ -3,12 +3,14 @@ import json
expected_sport_1_cycling_result = {
'id': 1,
'label': 'Cycling',
'img': None,
'_can_be_deleted': True
}
expected_sport_2_running_result = {
'id': 2,
'label': 'Running',
'img': None,
'_can_be_deleted': True
}