示例#1
0
class Accessory(db.Model):
    __tablename__ = "accessory"
    id = db.Column(db.Integer, primary_key=True)

    state = db.Column(db.Integer(), nullable=False, default=0)  # ENUM_STATES
    state_notes = db.Column(db.String(255), nullable=True)

    manufacturer = db.Column(db.String(255), nullable=True)
    model = db.Column(db.String(255), nullable=True)
    model_notes = db.Column(db.Text, nullable=True)
    description = db.Column(db.String(255), nullable=True)
    serial = db.Column(db.String(255), nullable=True)
    mount = db.Column(db.String(255), nullable=True)
    batteries = db.Column(db.String(255), nullable=True)

    private = db.Column(db.Boolean(), default=False)

    url1 = db.Column(URLType(), nullable=True)
    url2 = db.Column(URLType(), nullable=True)
    url3 = db.Column(URLType(), nullable=True)

    pic_filename = db.Column(db.String(255), unique=False, nullable=True)

    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)

    def state_str(self):
        return enum_states[self.state]
示例#2
0
class Follower(db.Model):
    __tablename__ = "followers"

    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(UUID(as_uuid=True),
                     server_default=sa_text("uuid_generate_v4()"),
                     unique=True)
    actor_id = db.Column(db.Integer, db.ForeignKey("actor.id"))
    target_id = db.Column(db.Integer, db.ForeignKey("actor.id"))
    activity_url = db.Column(URLType(), unique=True, nullable=True)
    creation_date = db.Column(db.DateTime(timezone=False),
                              default=datetime.datetime.utcnow)
    modification_date = db.Column(db.DateTime(timezone=False),
                                  onupdate=datetime.datetime.now)

    actor = db.relationship("Actor", foreign_keys=[actor_id])
    target = db.relationship("Actor", foreign_keys=[target_id])

    __table_args__ = (UniqueConstraint("actor_id",
                                       "target_id",
                                       name="unique_following"), )

    def __repr__(self):
        return f"<Follower(id='{self.id}', actor_id='{self.actor_id}', target_id='{self.target_id}')>"

    def follow_back(self):
        f = (db.session.query(Follower.id).filter(
            Follower.actor_id == self.target_id,
            Follower.target_id == self.actor_id).first())
        return f
示例#3
0
class Activity(db.Model):
    __tablename__ = "activity"
    id = db.Column(db.Integer, primary_key=True)

    actor = db.Column(db.Integer, db.ForeignKey("actor.id"))

    uuid = db.Column(UUID(as_uuid=True), server_default=sa_text("uuid_generate_v4()"), unique=True)
    url = db.Column(URLType(), unique=True, nullable=True)
    type = db.Column(db.String(100), index=True)
    box = db.Column(db.String(100))
    payload = db.Column(JSONB())
    creation_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
    delivered = db.Column(db.Boolean, default=None, nullable=True)
    delivered_date = db.Column(db.DateTime(timezone=False), nullable=True)
    local = db.Column(db.Boolean, default=True)
    meta_deleted = db.Column(db.Boolean, default=False)
    meta_undo = db.Column(db.Boolean, default=False)
    meta_pinned = db.Column(db.Boolean, default=False)
示例#4
0
class Actor(db.Model):
    __tablename__ = "actor"
    ap_type = "Actor"

    id = db.Column(db.Integer, primary_key=True)

    url = db.Column(URLType(), unique=True, index=True)
    outbox_url = db.Column(URLType())
    inbox_url = db.Column(URLType())
    following_url = db.Column(URLType(), nullable=True)
    followers_url = db.Column(URLType(), nullable=True)
    shared_inbox_url = db.Column(URLType(), nullable=True)
    type = db.Column(ChoiceType(ACTOR_TYPE_CHOICES), server_default="Person")
    name = db.Column(db.String(200), nullable=True)
    domain = db.Column(db.String(1000), nullable=False)
    summary = db.Column(db.String(500), nullable=True)
    preferred_username = db.Column(db.String(200), nullable=True)
    public_key = db.Column(db.String(5000), nullable=True)
    private_key = db.Column(db.String(5000), nullable=True)
    creation_date = db.Column(db.DateTime(timezone=False),
                              default=datetime.datetime.utcnow)
    last_fetch_date = db.Column(db.DateTime(timezone=False),
                                default=datetime.datetime.utcnow)
    manually_approves_followers = db.Column(db.Boolean,
                                            nullable=True,
                                            server_default=None)
    # Who follows self
    followers = db.relationship("Follower",
                                backref="followers",
                                primaryjoin=id == Follower.target_id,
                                lazy="dynamic")
    # Who self follows
    followings = db.relationship("Follower",
                                 backref="followings",
                                 primaryjoin=id == Follower.actor_id,
                                 lazy="dynamic")
    # Relation on itself, intermediary with actor and target
    # By using an Association Object, which isn't possible except by using
    # two relations. This may be better than only one, and some hackish things
    # by querying directly the old db.Table definition

    meta_deleted = db.Column(db.Boolean, default=False)

    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True)
    user = db.relationship("User", backref=db.backref("actor"))

    __table_args__ = (UniqueConstraint("domain",
                                       "preferred_username",
                                       name="_domain_pref_username_uc"), )

    def __repr__(self):
        return f"<Actor(id='{self.id}', user_id='{self.user_id}', preferredUsername='******', domain='{self.domain}')>"

    def webfinger_subject(self):
        return f"{self.preferred_username}@{self.domain}"

    def private_key_id(self):
        return f"{self.url}#main-key"

    def mention_username(self):
        return f"@{self.preferred_username}@{self.domain}"

    def is_local(self):
        return self.domain == current_app.config["AP_DOMAIN"]

    def follow(self, activity_url, target):
        current_app.logger.debug(f"saving: {self.id} following {target.id}")

        rel = Follower.query.filter(Follower.actor_id == self.id,
                                    Follower.target_id == target.id).first()

        if not rel:
            rel = Follower()
            rel.actor_id = self.id
            rel.target_id = target.id
            rel.activity_url = activity_url
            db.session.add(rel)
            db.session.commit()

    def unfollow(self, target):
        current_app.logger.debug(f"saving: {self.id} unfollowing {target.id}")

        rel = Follower.query.filter(Follower.actor_id == self.id,
                                    Follower.target_id == target.id).first()
        if rel:
            db.session.delete(rel)
            db.session.commit()

    def is_followed_by(self, target):
        print(
            f"is {self.preferred_username} followed by {target.preferred_username} ?"
        )
        return self.followers.filter(Follower.actor_id == target.id).first()

    def is_following(self, target):
        print(
            f"is {self.preferred_username} following {target.preferred_username} ?"
        )
        return self.followings.filter(Follower.target_id == target.id).first()

    def to_dict(self):
        if self.user.path_avatar():
            url_avatar = url_for("get_uploads_stuff",
                                 thing="avatars",
                                 stuff=self.user.path_avatar(),
                                 _external=True)
        else:
            url_avatar = f"{current_app.config['REEL2BITS_URL']}/static/userpic_placeholder.svg"

        return {
            "@context": DEFAULT_CTX,
            "id": self.url,
            "type": self.type.code,
            "preferredUsername": self.preferred_username,
            "name": self.name,
            "inbox": self.inbox_url,
            "outbox": self.outbox_url,
            "followers": self.followers_url,
            "following": self.following_url,
            "manuallyApprovesFollowers": self.manually_approves_followers,
            "publicKey": {
                "id": self.private_key_id(),
                "owner": self.url,
                "publicKeyPem": self.public_key
            },
            "endpoints": {
                "sharedInbox": self.shared_inbox_url
            },
            "icon": {
                "type": "Image",
                "url": url_avatar
            },
        }
示例#5
0
class Camera(db.Model):
    __tablename__ = "camera"
    id = db.Column(db.Integer, primary_key=True)

    state = db.Column(db.Integer(), nullable=False, default=0)  # ENUM_STATES
    state_notes = db.Column(db.String(255), nullable=True)

    manufacturer = db.Column(db.String(255), nullable=True)
    model = db.Column(db.String(255), nullable=True)
    model_notes = db.Column(db.Text, nullable=True)
    description = db.Column(db.String(255), nullable=True)
    serial = db.Column(db.String(255), nullable=True)
    mount = db.Column(db.String(255), nullable=True)

    camera_type = db.Column(db.Integer(), nullable=False,
                            default=0)  # ENUM_CAMERAS_TYPES

    film_type = db.Column(db.Integer(), nullable=False,
                          default=0)  # ENUM_FILM_TYPES
    auto_expo = db.Column(db.Boolean(), default=True)
    auto_focus = db.Column(db.Boolean(), default=True)
    batteries = db.Column(db.String(255), nullable=True)
    hot_shoe = db.Column(db.Boolean(), default=True)
    fixed_lens = db.Column(db.Boolean(), default=False)

    iso_min = db.Column(db.Integer(), default=0)
    iso_max = db.Column(db.Integer(), default=0)
    focale_min = db.Column("focale", db.Integer(), nullable=False, default=0)
    focale_max = db.Column(db.Integer(), nullable=True, default=0)
    min_aperture = db.Column(db.Float(), default=0)
    max_aperture = db.Column(db.Float(), default=0)
    blades = db.Column(db.Boolean(), default=True)
    filter_diameter = db.Column(db.Integer(), nullable=True, default=0)
    weight = db.Column(db.Integer(), nullable=True, default=0)  # g.
    length = db.Column(db.Integer(), nullable=True, default=0)  # mm
    focus = db.Column(db.Integer(), nullable=False,
                      default=0)  # ENUM_FOCUSES_TYPES
    focus_length = db.Column(db.Integer(), nullable=True, default=0)
    macro = db.Column(db.Boolean(), default=True)
    macro_length = db.Column(db.Integer(), nullable=True, default=0)

    private = db.Column(db.Boolean(), default=False)

    url1 = db.Column(URLType(), nullable=True)
    url2 = db.Column(URLType(), nullable=True)
    url3 = db.Column(URLType(), nullable=True)

    pic_filename = db.Column(db.String(255), unique=False, nullable=True)

    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)

    def state_str(self):
        return enum_states[self.state]

    def camera_type_str(self):
        return enum_cameras_types[self.camera_type]

    def film_type_str(self):
        return enum_film_types[self.film_type]

    def focus_str(self):
        return enum_focuses_types[self.focus]

    def focale_str(self):
        if self.focale_min == self.focale_max:
            return self.focale_min

        mm = None
        if self.focale_min is not None and self.focale_min != "":
            mm = self.focale_min
        if self.focale_max is not None and self.focale_max != "":
            if mm:
                mm = f"{mm} - {self.focale_max}"
            else:
                # *shrug*
                mm = self.focale_max
        return mm

    def aperture_str(self):
        if self.min_aperture == self.max_aperture:
            return self.min_aperture

        f = None
        if self.min_aperture is not None and self.min_aperture != "":
            f = self.min_aperture
        if self.max_aperture is not None and self.max_aperture != "":
            if f:
                f = f"{f} - {self.max_aperture}"
            else:
                # *shrug*
                f = self.max_aperture
        return f
示例#6
0
class Lens(db.Model):
    __tablename__ = "lense"  # Leave this typo alone thx
    id = db.Column(db.Integer, primary_key=True)

    state = db.Column(db.Integer(), nullable=False, default=0)  # ENUM_STATES
    state_notes = db.Column(db.String(255), nullable=True)

    manufacturer = db.Column(db.String(255), nullable=True)
    model = db.Column(db.String(255), nullable=True)
    model_notes = db.Column(db.Text, nullable=True)
    description = db.Column(db.String(255), nullable=True)
    serial = db.Column(db.String(255), nullable=True)
    mount = db.Column(db.String(255), nullable=True)

    focale_min = db.Column("focale", db.Integer(), nullable=True, default=0)
    focale_max = db.Column(db.Integer(), nullable=True, default=0)
    min_aperture = db.Column(db.Float(), nullable=True, default=0)
    max_aperture = db.Column(db.Float(), nullable=True, default=0)
    lens_type = db.Column(db.Integer(), nullable=False,
                          default=0)  # ENUM_LENSES_TYPES
    macro = db.Column(db.Boolean(), default=True)
    macro_length = db.Column(db.Integer(), nullable=True, default=0)
    filter_diameter = db.Column(db.Integer(), nullable=True, default=0)
    blades = db.Column(db.Boolean(), default=True)
    angle = db.Column(db.Float(), nullable=True, default=0)
    focus = db.Column(db.Integer(), nullable=False,
                      default=0)  # ENUM_FOCUSES_TYPES
    focus_length = db.Column(db.Integer(), nullable=True, default=0)
    weight = db.Column(db.Integer(), nullable=True, default=0)  # g.
    length = db.Column(db.Float(), nullable=True, default=0)  # mm

    private = db.Column(db.Boolean(), default=False)

    url1 = db.Column(URLType(), nullable=True)
    url2 = db.Column(URLType(), nullable=True)
    url3 = db.Column(URLType(), nullable=True)

    pic_filename = db.Column(db.String(255), unique=False, nullable=True)

    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)

    def state_str(self):
        return enum_states[self.state]

    def focus_str(self):
        return enum_focuses_types[self.focus]

    def lens_type_str(self):
        return enum_lenses_types[self.lens_type]

    def focale_str(self):
        if self.focale_min == self.focale_max:
            return self.focale_min

        mm = None
        if self.focale_min is not None and self.focale_min != "":
            mm = self.focale_min
        if self.focale_max is not None and self.focale_max != "":
            if mm:
                mm = f"{mm} - {self.focale_max}"
            else:
                # *shrug*
                mm = self.focale_max
        return mm

    def aperture_str(self):
        if self.min_aperture == self.max_aperture:
            return self.min_aperture

        f = None
        if self.min_aperture is not None and self.min_aperture != "":
            f = self.min_aperture
        if self.max_aperture is not None and self.max_aperture != "":
            if f:
                f = f"{f} - {self.max_aperture}"
            else:
                # *shrug*
                f = self.max_aperture
        return f