class CourseWord(BaseModel): course = peewee.ForeignKeyField(Course) word = peewee.CharField() count = peewee.IntegerField()
class User_(UserMixin, BaseModel): username = pw.CharField(unique=False) password = pw.CharField() email = pw.CharField()
class Model(BaseModel): test = peewee.CharField(null=False)
class Session(BaseModel): title = pw.CharField(null=False) session_type = pw.CharField(null=False) description = pw.TextField(null=False) user = pw.ForeignKeyField(User, backref='sessions')
class Proposal(peewee.Model): wallet = peewee.ForeignKeyField(Wallet) destination_address = peewee.CharField() description = peewee.TextField() proposal_id = peewee.CharField() amount = peewee.BigIntegerField() fee = peewee.IntegerField() timestamp = peewee.DateTimeField( constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")]) tx_id = peewee.TextField(null=True) status = peewee.CharField(max_length=10, default="signing") class Meta: database = database def serialize(self): return { "destination_address": self.destination_address, "description": self.description, "proposal_id": self.proposal_id, "amount": self.amount, "fee": self.fee, "approvals": self.approve_list, "rejects": self.reject_list, "status": self.status, "last_signed_transaction": self.last_signed_transaction, "tx_id": self.tx_id.split(',') if self.tx_id else [], } def _get_decisions(self, approve): return ProposalDecision.select().where( ProposalDecision.proposal == self, ProposalDecision.approved == approve) @property def approvals(self): with objects.allow_sync(): return self._get_decisions(approve=True).count() @property def approve_list(self): return [ decision.source for decision in self._get_decisions(approve=True) ] @property def rejects(self): with objects.allow_sync(): return self._get_decisions(approve=False).count() @property def reject_list(self): return [ decision.source for decision in self._get_decisions(approve=False) ] @property def last_signed_transaction(self): with objects.allow_sync(): last_decision = ProposalDecision.select().where( ProposalDecision.proposal == self, ProposalDecision.approved == True, ).order_by(ProposalDecision.timestamp.desc()).first() if last_decision: return last_decision.signed_transaction return None @classmethod def generate_unique_id(cls): from api.utils import generate_random_string unique_id = generate_random_string() while cls.select().where(cls.proposal_id == unique_id).exists(): unique_id = generate_random_string() return unique_id
class User(BaseModel): username = pw.CharField(unique=False) email = pw.CharField(unique=True) password = pw.CharField(unique=False) profilepic = pw.CharField(unique=False, null=True)
class Dataset(BaseModel): name = orm.CharField(unique=True) created = orm.TimestampField() meta = orm.BlobField() session = orm.BooleanField()
class Weather(BaseTable): location_name = peewee.CharField() location_en = peewee.CharField() coordinates = peewee.CharField() date = peewee.DateField() max_temp = peewee.CharField() min_temp = peewee.CharField() pressures = peewee.CharField() cloudiness = peewee.CharField() cloud_cover = peewee.CharField() precipitation = peewee.CharField() humidity = peewee.CharField() wind_speed = peewee.CharField() precipitation_hours = peewee.IntegerField()
class TestImage(base_model.BaseModel): content = MediumBlobField() image_format = peewee.CharField()
class MaterialTopicWord(BaseModel): topic = peewee.IntegerField() word = peewee.CharField() weight = peewee.DoubleField()
class MaterialTopicInfo(BaseModel): topic = peewee.IntegerField() name = peewee.CharField()
class LectureTopicWord(BaseModel): topic = peewee.IntegerField() course = peewee.ForeignKeyField(Course) word = peewee.CharField() weight = peewee.DoubleField()
class CourseTopicInfo(BaseModel): topic = peewee.IntegerField() name = peewee.CharField()
class CorpusWord(BaseModel): word = peewee.CharField() count = peewee.IntegerField()
class Config(BaseModel): name = pw.CharField(max_length=255, primary_key=True) data = pw.TextField(default='{}')
class Type(db.Model): name = pw.CharField(max_length=60, null=False, unique=True)
class Version(BaseModel): name = pw.CharField(max_length=255, primary_key=True) version = pw.IntegerField(default=0)
class Machine(db.Model): name = pw.CharField(max_length=60, null=False) wattage = pw.FloatField(null=True) type = pw.ForeignKeyField(Type, related_name='machines')
class Image(BaseModel): '''Store information about images. Attributes ---------- path : str path to an image stored somewhere on disk datetime : str time when the original image was taken hash : str image file hash thumb : bytes JPEG-encoded image thumbnail ''' path = peewee.TextField(unique=True) datetime = peewee.DateTimeField() hash = peewee.CharField(unique=True, max_length=64) thumb = peewee.BlobField() class Meta: table_name = 'images' @classmethod def size(cls): '''Obtain the number of images in the database. Returns ------- int the number of images in the database ''' return Image.select().count() @classmethod def get_hash(cls, path): '''Return the hash of a particular image, given its file name. Parameters ---------- path : str image path Returns ------- str the associated hash or ``None`` if it does not exist ''' try: image = Image.select(Image.hash).where(Image.path == path).get() except Image.DoesNotExist: return None return image.hash @classmethod def get_path(cls, query): '''Return the path to a particular image. Parameters ---------- query: str a 64-character sha256 hash Returns ------- str or ``None`` the image path or ``None`` if it does not exist ''' try: image = Image.select(Image.path).where(Image.hash == query).get() except Image.DoesNotExist: return None return image.path @classmethod def get_thumbnail(cls, query): '''Retrieve a thumbnail given an image hash. Parameters ---------- query : str a 64-character sha256 hash Returns ------- bytes or ``None`` a JPEG-encoded thumbnail; will be ``None`` if the hash does not exist in the database ''' try: image = Image.select().where(Image.hash == query).get() except Image.DoesNotExist: return None return image.thumb
class User(db.Model): parent = pw.ForeignKeyField('self', related_name='children', null=True) name = pw.CharField(max_length=60, null=False)
class User(BaseModel): username = orm.CharField(unique=True) password = orm.CharField() email = orm.CharField()
class Group(db.Model): name = pw.CharField(max_length=60, null=False) members = ManyToManyField(User, related_name='memberships')
class Detail(BaseModel): id = pw.AutoField() detail = pw.CharField()
class Banned(peewee.Model): user_id = peewee.CharField(primary_key=True)
class Contact(ReminderModel): name = peewee.CharField() email = peewee.CharField() phone = peewee.CharField()
class Mention(BaseModel): id = pw.AutoField() mention = pw.CharField()
class PuppyModel(peewee.Model): id = peewee.IntegerField(primary_key=True) name = peewee.CharField() class Meta: database = database_component.database
class Preset(BaseModel): name = pw.CharField(max_length=255) number = pw.IntegerField(unique=True, null=True) data = pw.TextField(default='{}') data_schema = schema.PresetSchema() class Meta: order_by = ['number'] def __str__(self): return '<Preset id:{}, number:{}, name:{}>'.format( self.id, self.number, self.name) @DB.atomic() def save(self, *args, **kwargs): if self.number is None: highest = Preset.select(pw.fn.MAX(Preset.number)).scalar() or 0 self.number = highest + 1 super().save(*args, **kwargs) @DB.atomic() def delete_instance(self, *args, **kwargs): ret = super().delete_instance(*args, **kwargs) ids = [p.id for p in Preset.select(Preset.id)] self.reorder(ids) return ret @classmethod @DB.atomic() def reorder(cls, order): num = Preset.update(number=None).execute() assert len(order) == num for (number, pid) in enumerate(order): Preset.update(number=number + 1).where(Preset.id == pid).execute() def get_data(self): try: return self.data_schema.loads(self.data).data except Exception: log.exception('Unable to read data on preset {}'.format(self.id)) return {} def set_data(self, data): try: self.data = self.data_schema.dumps(data).data except Exception: log.exception('Unable to store data on preset {}'.format(self.id)) self.data = '{}' def to_dict(self): data = self.get_data() data['id'] = self.id data['number'] = self.number data['name'] = self.name for voice in data.get('voices', {}).get('trompette', []): if not voice.get('mode'): voice['mode'] = 'midigurdy' if voice.get('chien_threshold') is None: voice['chien_threshold'] = data.get('chien_threshold', 50) if (not voice.get('soundfont') or voice.get('bank') is None or voice.get('program') is None): voice['muted'] = True return data
class Model1(BaseModel): test1 = peewee.CharField(max_length=20) test2 = peewee.CharField(max_length=20) def __str__(self): return self.test1
class LectureWord(BaseModel): lecture = peewee.ForeignKeyField(Lecture) word = peewee.CharField() count = peewee.IntegerField() weight = peewee.DoubleField()