Ejemplo n.º 1
0
class CurriculumUnit(db.Model, _CurriculumUnit):
    __tablename__ = 'curriculum_unit'
    __table_args__ = (db.UniqueConstraint('subject_id', 'stud_group_id'), )

    id = db.Column('curriculum_unit_id',
                   db.INTEGER,
                   primary_key=True,
                   autoincrement=True)
    subject_id = db.Column(db.ForeignKey('subject.subject_id'),
                           nullable=False,
                           index=True)
    stud_group_id = db.Column(db.ForeignKey('stud_group.stud_group_id'),
                              nullable=False,
                              index=True)
    teacher_id = db.Column(db.ForeignKey('teacher.teacher_id'),
                           nullable=False,
                           index=True)
    mark_type = db.Column('mark_type',
                          db.Enum(*MarkTypeDict.keys()),
                          nullable=False)
    hours_att_1 = db.Column('hours_att_1', db.SMALLINT, nullable=False)
    hours_att_2 = db.Column('hours_att_2', db.SMALLINT, nullable=False)
    hours_att_3 = db.Column('hours_att_3', db.SMALLINT, nullable=False)

    subject = db.relationship('Subject')
    teacher = db.relationship('Teacher')
    att_marks = db.relationship('AttMark',
                                lazy=True,
                                backref='curriculum_unit')
Ejemplo n.º 2
0
class Show(db.Model):
    __tablename__ = 'Show'
    id = db.Column(db.Integer, primary_key=True)
    start_time = db.Column(db.DateTime)
    venue_id = db.Column(db.Integer, db.ForeignKey("Venue.id"), nullable=False)
    artist_id = db.Column(db.Integer,
                          db.ForeignKey("Artist.id"),
                          nullable=False)

    # helper method to unpack tuple search results into splatted dicts with info about a show
    @classmethod
    def unpack_tuples(cls, show_tuples):
        return [{
            **vars(_tuple[0]),
            **vars(_tuple[1])
        } for _tuple in show_tuples]

    # helper method to donvert show.start_time from datetime object to tstring
    @classmethod
    def datetimes_to_strings(cls, shows):
        converted_shows = shows
        for show in converted_shows:
            show['start_time'] = show['start_time'].strftime(
                '%Y-%m-%d %H:%M:%S')
        return converted_shows

    @classmethod
    def get_shows(cls, when='all'):
        query = cls.query
        if when == 'upcoming':
            shows = query.filter(cls.start_time > datetime.now()).order_by(
                cls.start_time).all()
        if when == 'past':
            shows = query.filter(cls.start_time <= datetime.now()).order_by(
                cls.start_time).all()
        if when == 'all':
            shows = query.order_by(cls.start_time).all()

        show_info = []
        for show in shows:
            venue = Venue.query.get(show.venue_id)
            artist = Artist.query.get(show.artist_id)
            show_info.append({
                'venue_id':
                venue.id,
                'venue_name':
                venue.name,
                'artist_id':
                artist.id,
                'artist_name':
                artist.name,
                'artist_image_link':
                artist.image_link,
                'start_time':
                show.start_time.strftime('%Y-%m-%d %H:%M:%S')
            })

        return show_info
Ejemplo n.º 3
0
class Show(db.Model):
    __tablename__ = 'Show'

    id = db.Column(db.Integer, primary_key=True)
    artist_id = db.Column(db.Integer,
                          db.ForeignKey('Artist.id'),
                          nullable=False)
    venue_id = db.Column(db.Integer, db.ForeignKey('Venue.id'), nullable=False)
    start_time = db.Column(db.DateTime, nullable=False)
Ejemplo n.º 4
0
class Record(db.Model):
    __tablename__='records'
    id= db.Column(db.Integer, primary_key = True)

    appointment_id = db.Column(db.Integer, db.ForeignKey('appointments.id'), nullable=False)
    appointment = db.relationship('Appointment')

    patient_id = db.Column(db.Integer, db.ForeignKey('patients.id'),nullable = False)
    patient = db.relationship('Patient')

    consult_type_id = db.Column(db.Integer, db.ForeignKey('consult_types.id'),nullable=False)
    consult_type = db.relationship('ConsultationType')
Ejemplo n.º 5
0
class ConsultationType(db.Model):
    __tablename__='consult_types'
    id = db.Column( db.Integer, primary_key=True)
    name = db.Column( db.String(120), nullable = False)

    department_id = db.Column(db.Integer, db.ForeignKey('departments.id'),nullable=False)
    department = db.relationship('Department', backref = db.backref('consultations',lazy = True))
Ejemplo n.º 6
0
class Student(db.Model, Person, _ObjectWithSemester):
    __tablename__ = 'student'

    id = db.Column('student_id', db.BIGINT, primary_key=True)
    surname = db.Column('student_surname', db.String(45), nullable=False)
    firstname = db.Column('student_firstname', db.String(45), nullable=False)
    middlename = db.Column('student_middlename', db.String(45))
    stud_group_id = db.Column(db.ForeignKey('stud_group.stud_group_id',
                                            ondelete='SET NULL',
                                            onupdate='SET NULL'),
                              index=True)
    semester = db.Column('student_semestr', db.SMALLINT)
    alumnus_year = db.Column('student_alumnus_year', db.SMALLINT)
    expelled_year = db.Column('student_expelled_year', db.SMALLINT)
    status = db.Column('student_status',
                       db.Enum(*StudentStateDict.keys()),
                       nullable=False)
    login = db.Column('student_login', db.String(45), unique=True)
    card_number = db.Column('card_number', db.BIGINT, unique=True)
    group_leader = db.Column('stud_group_leader',
                             db.BOOLEAN,
                             nullable=False,
                             default=False)

    @property
    def status_name(self):
        if self.status and self.status in StudentStateDict:
            return StudentStateDict[self.status]

    @property
    def role_name(self):
        return 'Student'
Ejemplo n.º 7
0
class ScheduleRecord(db.Model):
    __tablename__='chedule_records'
    id = db.Column(db.Integer, primary_key = True)

    doctor_id = db.Column(db.Integer, db.ForeignKey('doctors.id'),nullable=False)
    doctor = db.relationship('Doctor', backref=db.backref('schedules', lazy=True))

    date = db.Column(db.Date,nullable=False)
    status = db.Column(db.String(40), nullable=False)
    unique_status = db.UniqueConstraint('doctor_id','date')
Ejemplo n.º 8
0
class Appointment(db.Model):
    __tablename__='appointments'
    id = db.Column(db.Integer, primary_key=True)
    record = db.relationship('Record', uselist=False)

    doctor_id= db.Column(db.Integer, db.ForeignKey('doctors.id'), nullable=False)
    doctor = db.relationship('Doctor')

    date = db.Column(db.Date, nullable=False)
    time = db.Column(db.Time, nullable=False)
    unique_time = db.UniqueConstraint('doctor_id','date','time')
Ejemplo n.º 9
0
class Doctor(db.Model):
    __tablename__ = 'doctors'
    id = db.Column( db.Integer, primary_key=True)

    department_id = db.Column(db.Integer, db.ForeignKey('departments.id'), nullable=False)
    department = db.relationship('Department', backref=db.backref('doctors', lazy=True))

    first_name = db.Column( db.String(50), nullable =False)
    middle_name = db.Column( db.String(120), nullable =True)
    surname = db.Column(db.String(50), nullable=False)

    def __repr__(self):
        return '<Doctor %r %r>' % (self.first_name, self.surname)
class Event(db.Model):
    __tablename__ = 'wp_em_events'
    name = db.Column('event_name', db.String)
    slug = db.Column('event_slug', db.String)
    event_id = db.Column('event_id', db.Integer, primary_key=True)
    full_event = db.relationship("FullEvent",
                                 primaryjoin="Event.event_id == FullEvent.id",
                                 foreign_keys=event_id,
                                 viewonly=True)
    post_id = db.Column('post_id', db.Integer)
    start = db.Column('event_start', db.DateTime())
    end = db.Column('event_end', db.DateTime())
    all_day = db.Column('event_all_day', db.Boolean)
    content = db.Column('post_content', db.String)
    location_id = db.Column('location_id', db.Integer,
                            db.ForeignKey('wp_em_locations.location_id'))
    location = db.relationship("Location",
                               primaryjoin="Event.location_id == Location.id",
                               foreign_keys=location_id,
                               viewonly=True)
    # because location_id is not a ForeignKey, we need primaryjoin
    group_id = db.Column('group_id', db.Integer,
                         db.ForeignKey('wp_bp_groups.id'))
    group = db.relationship("Group",
                            primaryjoin="Event.group_id == Group.id",
                            foreign_keys=group_id,
                            viewonly=True)
    event_type = association_proxy('full_event', 'veranstaltungsart')
    recurrence = db.Column("recurrence", db.Integer)
    recurrence_id = db.Column("recurrence_id", db.Integer)
    recurrence_parent = db.relationship(
        "Event",
        primaryjoin="Event.recurrence_id == Event.event_id",
        remote_side=[event_id],
        foreign_keys=recurrence_id,
        backref="recurrence_children")
    visibility = db.Column(
        "event_status",
        db.Integer)  # 0 means not visible, None and 1 mean visible
    telephone = ""
    contact_email = ""
    accessible = "Nein"
    website = ""
    terms = db.relationship("Term", secondary=association_table, viewonly=True)
    terms_slugs = association_proxy('terms', 'slug')

    def get_full_image(self):
        try:  # remove this try later
            return BEWEGUNGSMELDER_BASE + self.full_event.image
        except AttributeError:
            return "error"

    def get_thumbnail_image(self):
        try:  # remove this try later
            thumb = re.sub(r"(\.[a-zA-Z]*$)", r"-150x150\g<1>", self.full_event.image) \
                if "bpthumb" not in self.full_event.image else self.full_event.image
            return BEWEGUNGSMELDER_BASE + thumb
        except AttributeError:
            return "error"

    def get_all_metadata(self):
        metadata = Metadata.query.filter(
            Metadata.post_id == self.post_id).all()
        meta = {}
        for metaentry in metadata:
            if not metaentry.meta_key.startswith(
                    "_") and metaentry.meta_value != "":
                if metaentry.meta_key == "Kontakt-Telefon":
                    self.telephone = metaentry.meta_value
                elif metaentry.meta_key == "Barrierefrei":
                    self.accessible = metaentry.meta_value
                elif metaentry.meta_key == "Kontakt-Email":
                    self.contact_email = metaentry.meta_value
                elif metaentry.meta_key == "Veranstaltungsart":
                    continue
                elif metaentry.meta_key == "weiterführende Links 1":
                    self.website = metaentry.meta_value
                else:
                    meta[metaentry.meta_key] = metaentry.meta_value
                # add more metadata here if necessary
        return meta
Ejemplo n.º 11
0
    Musical_Theatre = 'Musical Theatre'
    Pop = 'Pop'
    Punk = 'Punk'
    R_and_B = 'R&B'
    Reggae = 'Reggae'
    Rock_n_Roll = 'Rock n Roll'
    Soul = 'Soul'
    Other = 'Other'


# Association Tables for Arits/Genres and Venue/Genres
Artist_Genres = db.Table(
    'Artist_Genres',
    db.Column('artist_id',
              db.Integer,
              db.ForeignKey("Artist.id"),
              primary_key=True),
    db.Column('genre_name',
              db.Enum(Genre_Choices),
              db.ForeignKey('Genre.name'),
              primary_key=True))

Venue_Genres = db.Table(
    'Venue_Genres',
    db.Column('venue_id',
              db.Integer,
              db.ForeignKey("Venue.id"),
              primary_key=True),
    db.Column('genre_name',
              db.Enum(Genre_Choices),
              db.ForeignKey('Genre.name'),
Ejemplo n.º 12
0
    def __init__(self, next_state, condition):
        self.next_state = next_state
        self.condition = condition

    def __repr__(self):
        return '<Transition ({}, {}, {})>'.format(self.id, self.condition,
                                                  self.next_state)


prev_state_table = db.Table(
    'prev_state_table',
    db.Model.metadata,
    db.Column('prev_states_id',
              db.Integer,
              db.ForeignKey('state.id'),
              primary_key=True),
    db.Column('prev_state_id',
              db.Integer,
              db.ForeignKey('state.id'),
              primary_key=True),
)

transition_state_table = db.Table(
    'transition_state_table',
    db.Model.metadata,
    db.Column('transition_id',
              db.Integer,
              db.ForeignKey('transition.id'),
              primary_key=True),
    db.Column('state_id',
Ejemplo n.º 13
0
class AttMark(db.Model):
    __tablename__ = 'att_mark'
    __table_args__ = (db.UniqueConstraint('curriculum_unit_id',
                                          'student_id'), )

    att_mark_id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    curriculum_unit_id = db.Column(
        db.ForeignKey('curriculum_unit.curriculum_unit_id'), nullable=False)
    student_id = db.Column(db.ForeignKey('student.student_id'),
                           nullable=False,
                           index=True)
    att_mark_1 = db.Column(db.SMALLINT)
    att_mark_2 = db.Column(db.SMALLINT)
    att_mark_3 = db.Column(db.SMALLINT)
    att_mark_exam = db.Column(db.SMALLINT)
    att_mark_append_ball = db.Column(db.SMALLINT)
    student = db.relationship('Student')

    @property
    def result_print(self):
        att_marks = (self.att_mark_1, self.att_mark_2, self.att_mark_3)
        if any(m is None for m in att_marks):
            return None

        mark_results = MarkResult[self.curriculum_unit.mark_type]
        min_ball = MarkResult["test_simple"][1]["min"]
        max_ball = mark_results[-1]["max"]

        if self.curriculum_unit.mark_type == "exam" and self.att_mark_exam is None:
            return None

        if any(m < min_ball for m in att_marks):
            return min(att_marks), mark_results[0]

        hours = (self.curriculum_unit.hours_att_1,
                 self.curriculum_unit.hours_att_2,
                 self.curriculum_unit.hours_att_3)
        ball_raw = sum(
            [att_marks[i] * hours[i]
             for i in range(len(att_marks))]) / sum(hours)
        # Округление
        ball = int(ball_raw)
        if ball_raw - ball >= 0.5:
            ball += 1

        if self.curriculum_unit.mark_type == "exam":
            ball += self.att_mark_exam

        if self.curriculum_unit.mark_type in (
                "exam", "test_diff") and self.att_mark_append_ball is not None:
            ball += self.att_mark_append_ball

        if ball > max_ball:
            ball = max_ball

        for mr in mark_results:
            if mr["min"] <= ball <= mr["max"]:
                return ball, mr

    @property
    def fill_data(self):
        r = {
            "att_1": self.att_mark_1 is not None,
            "att_2": False,
            "att_3": False,
            "all": False
        }

        r["att_2"] = r["att_1"] and self.att_mark_2 is not None
        r["all"] = r["att_3"] = r["att_2"] and self.att_mark_3 is not None

        if self.curriculum_unit.mark_type == "exam":
            r["all"] = r["all"] and self.att_mark_exam is not None

        return r
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sqlalchemy.ext.associationproxy import association_proxy

from app_config import db
from backend.adapter.wordpress.taxonomy import Taxonomy

association_table = db.Table(
    'wp_term_relationships',
    db.Model.metadata,
    db.Column('object_id', db.Integer, db.ForeignKey('wp_em_events.post_id'),
              db.ForeignKey('wp_bp_groups.id')),
    db.Column('term_taxonomy_id', db.Integer,
              db.ForeignKey('wp_terms.term_id')),
)


class Term(db.Model):
    __tablename__ = 'wp_terms'
    id = db.Column('term_id', db.Integer, primary_key=True)
    name = db.Column('name', db.String)
    slug = db.Column('slug', db.String)
    term_group = db.Column(
        'term_group',
        db.Integer)  # this is unused and here only for completeness
    taxonomy_item = db.relationship('Taxonomy',
                                    primaryjoin="Taxonomy.term_id == Term.id",
                                    foreign_keys=id)
    type = association_proxy('taxonomy_item', 'taxonomy')