class Activity(PkModel): """ Public, real time, conversational """ __tablename__ = 'activities' name = Column(db.Enum('create', 'update', 'star', name="activity_type")) action = Column(db.String(32), nullable=True) # 'external', # 'boost', # 'sync', # 'post', # ... timestamp = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow) content = Column(db.UnicodeText, nullable=True) user_id = reference_col('users', nullable=False) user = relationship('User', backref='activities') project_id = reference_col('projects', nullable=False) project = relationship('Project', backref='activities') project_progress = Column(db.Integer, nullable=True) project_score = Column(db.Integer, nullable=True) resource_id = reference_col('resources', nullable=True) resource = relationship('Resource', backref='activities') @property def data(self): return { 'id': self.id, 'name': self.name, 'time': int(mktime(self.timestamp.timetuple())), 'timesince': timesince(self.timestamp), 'date': self.timestamp, 'content': self.content or '', 'user_name': self.user.username, 'user_id': self.user.id, 'project_id': self.project.id, 'project_name': self.project.name, 'project_score': self.project_score or 0, 'project_phase': getProjectPhase(self.project), 'resource_id': self.resource_id, 'resource_type': getResourceType(self.resource), } def __init__(self, name, user_id, project_id, **kwargs): if name: db.Model.__init__(self, name=name, user_id=user_id, project_id=project_id, **kwargs) def __repr__(self): return '<Activity({name})>'.format(name=self.name)
class Activity(SurrogatePK, Model): __tablename__ = 'activities' name = Column( db.Enum( 'create', 'update', # 'boost', 'star', name="activity_type")) timestamp = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow) user_id = reference_col('users', nullable=False) user = relationship('User', backref='activities') project_id = reference_col('projects', nullable=False) project = relationship('Project', backref='activities') @property def data(self): return { 'id': self.id, 'name': self.name, 'time': int(mktime(self.timestamp.timetuple())), 'date': self.timestamp, 'user_name': self.user.username, 'user_id': self.user.id, 'project_id': self.project.id, 'project_name': self.project.name, 'project_score': self.project.score } def __init__(self, name, user_id, project_id, **kwargs): if name: db.Model.__init__(self, name=name, user_id=user_id, project_id=project_id, **kwargs) def __repr__(self): return '<Activity({name})>'.format(name=self.name)
class Activity(PkModel): """ Public, real time, conversational """ __tablename__ = 'activities' name = Column(db.Enum('review', 'boost', 'create', 'update', 'star', name="activity_type")) action = Column(db.String(32), nullable=True) # 'external', 'commit', 'sync', 'post', ... timestamp = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow) content = Column(db.UnicodeText, nullable=True) ref_url = Column(db.String(2048), nullable=True) user_id = reference_col('users', nullable=True) user = relationship('User', backref='activities') project_id = reference_col('projects', nullable=True) project = relationship('Project', backref='activities') project_progress = Column(db.Integer, nullable=True) project_version = Column(db.Integer, nullable=True) project_score = Column(db.Integer, nullable=True) @property def data(self): localtime = current_app.tz.localize(self.timestamp) a = { 'id': self.id, 'time': int(mktime(self.timestamp.timetuple())), 'date': format_date(localtime, '%Y-%m-%dT%H:%M'), 'timesince': timesince(localtime), 'name': self.name, 'action': self.action or '', 'content': self.content or '', 'ref_url': self.ref_url or '', } if self.user: a['user_id'] = self.user.id a['user_name'] = self.user.username if self.project: a['project_id'] = self.project.id a['project_name'] = self.project.name a['project_score'] = self.project_score or 0 a['project_phase'] = getProjectPhase(self.project) return a def set_from_data(self, data): self.name = data['name'] self.action = data['action'] self.content = data['content'] self.ref_url = data['ref_url'] self.timestamp = dt.datetime.fromtimestamp(data['time']) if 'user_name' in data: uname = data['user_name'] user = User.query.filter_by(username=uname).first() if user: self.user = user def __init__(self, name, project_id, **kwargs): if name: db.Model.__init__( self, name=name, project_id=project_id, **kwargs ) def __repr__(self): return '<Activity({name})>'.format(name=self.name)