Ejemplo n.º 1
0
class UserMatch(db.Model):
    """holds matches made through the history of the app"""

    __tablename__ = "user_matches"

    match_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id_1 = db.Column(db.Integer,
                          db.ForeignKey('users.id'),
                          nullable=False)
    user_id_2 = db.Column(db.Integer,
                          db.ForeignKey('users.id'),
                          nullable=False)
    match_date = db.Column(db.DateTime, nullable=False)
    user_2_status = db.Column(db.Boolean, nullable=False)
    query_pincode = db.Column(db.String(20), nullable=False)

    def __repr__(self):
        """return interest choices of the user"""

        d1 = '< match_id={a}, user_id_1={b},'.format(a=self.match_id,
                                                     b=self.user_id_1)
        d2 = ' user_id_2={c}, match_date={d}>'.format(c=self.user_id_2,
                                                      d=self.match_date)

        return d1 + d2
Ejemplo n.º 2
0
class User(db.Model,
           UserMixin):  #This class defines several fields as class variables.
    """ User of the Dating website."""

    __tablename__ = 'users'

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

    firstname = db.Column(db.String(100), nullable=False)
    lastname = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), nullable=False, unique=True)
    username = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    date_of_birth = db.Column(db.String(100), nullable=False)
    gender = db.Column(db.Enum('M', 'F'))
    zipcode = db.Column(db.String(100), nullable=False)
    phone = db.Column(db.String(100), nullable=False)
    image_file = db.Column(db.String(20), nullable=True, default='default.jpg')

    messages_sent = db.relationship('Message',
                                    foreign_keys='Message.sender_id',
                                    backref='sender',
                                    lazy='dynamic')
    messages_received = db.relationship('Message',
                                        foreign_keys='Message.recipient_id',
                                        backref='recipient',
                                        lazy='dynamic')

    last_message_read_time = db.Column(db.DateTime)
    notifications = db.relationship('Notification',
                                    backref='user',
                                    lazy='dynamic')

    #profile_picture = db.Column(db.String(250), default = 'default.jpg', nullable=True)

    def _repr_(
        self
    ):  #The __repr__ method tells Python how to print objects of this class
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"

    def new_messages(self):
        last_read_time = self.last_message_read_time or datetime(1900, 1, 1)
        return Message.query.filter_by(recipient=self).filter(
            Message.timestamp > last_read_time).count()

    def add_notification(self, name, data):
        self.notifications.filter_by(name=name).delete()
        n = Notification(name=name, payload_json=json.dumps(data), user=self)
        db.session.add(n)
        return n
Ejemplo n.º 3
0
class Notification(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128), index=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    timestamp = db.Column(db.Float, index=True, default=time)
    payload_json = db.Column(db.Text)

    def get_data(self):
        return json.loads(str(self.payload_json))
Ejemplo n.º 4
0
class Message(db.Model):

    __tablename__ = 'messages'
    id = db.Column(db.Integer, primary_key=True)
    sender_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    recipient_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    body = db.Column(db.String(140))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)

    def __repr__(self):
        return '<Message {}>'.format(self.body)
Ejemplo n.º 5
0
class User(db.Model, UserMixin):  #This class defines several fields as class variables.
    """ User of the Dating website."""

    __tablename__ = 'users'

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

    firstname = db.Column(db.String(100), nullable=False)
    lastname = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), nullable=False, unique=True)
    username = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    date_of_birth = db.Column(db.String(100), nullable=False)
    city = db.Column(db.String(100), nullable=False)
    phone = db.Column(db.String(100), nullable=False)
    image_file = db.Column(db.String(20), nullable=True, default='default.jpg')
    #profile_picture = db.Column(db.String(250), default = 'default.jpg', nullable=True)

    def _repr_(self): #The __repr__ method tells Python how to print objects of this class
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
Ejemplo n.º 6
0
class Outdoor(db.Model):
    """Holds the outdoor_activities and their corresponding ids"""

    __tablename__ = 'outdoors'

    outdoor_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    outdoor_activity = db.Column(db.String(40), nullable=False)

    interest = db.relationship('Interest', backref=db.backref('outdoor'))

    def __repr__(self):
        """displays the ids of oa, and oa
        Can be cross-referenced with the interests table"""

        return '<outdoor_id={}, outdoor_activity={}>'.format(
            self.outdoor_id, self.outdoor_activity)
Ejemplo n.º 7
0
class Religion(db.Model):
    """Holds the religious views and their corresponding ids"""

    __tablename__ = 'religions'

    religion_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    religion_name = db.Column(db.String(40), nullable=False)

    interest = db.relationship('Interest', backref=db.backref('religion'))

    def __repr__(self):
        """displays the ids of religion and religion names
        Can be cross-referenced with the interests table"""

        return '<religion_id={}, religion_name={}>'.format(
            self.religion_id, self.religion_name)
Ejemplo n.º 8
0
class Hobby(db.Model):
    """Holds the list of hobbies and thier corresponding ids"""

    __tablename__ = 'hobbies'

    hobby_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    hobby_name = db.Column(db.String(40), nullable=False)

    interest = db.relationship('Interest', backref=db.backref('hobby'))

    def __repr__(self):
        """displays the ids of hobbies and hobby names
        Can be cross-referenced with the interests table"""

        return '<hobby_id={}, hobby_name={}>'.format(self.hobby_id,
                                                     self.hobby_name)
Ejemplo n.º 9
0
class BookGenre(db.Model):
    """Holds the Music_genres and their corresponding ids"""

    __tablename__ = 'book_genres'

    book_genre_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    book_genre_name = db.Column(db.String(40), nullable=False)

    interest = db.relationship('Interest', backref=db.backref('book_genre'))

    def __repr__(self):
        """displays the ids of Book genres and book genres
        Can be cross-referenced with the interests table"""

        return '<book_genre_id={}, book_genre_name={}>'.format(
            self.book_genre_id, self.book_genre_name)
Ejemplo n.º 10
0
class FavCuisine(db.Model):
    """Holds the types of cuisines and thier corresponding ids"""

    __tablename__ = 'fav_cuisines'

    fav_cuisine_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    fav_cuisine_name= db.Column(db.String(40), nullable=False)

    interest = db.relationship('Interest',
                            backref=db.backref('fav_cuisine'))

    def __repr__ (self):
        """displays the ids of cuisines and cuisine names
        Can be cross-referenced with the interests table"""

        return'<fav_cuisine_id={}, fav_cuisine_name={}>'.format(self.fav_cuisine_id,
                                                                self.fav_cuisine_name)
Ejemplo n.º 11
0
class User(db.Model, UserMixin):
	id = db.Column(db.Integer, primary_key=True)
	username = db.Column(db.String(20), unique=True, nullable=False)
	email = db.Column(db.String(120), unique=True, nullable=True)
	dp = db.Column(db.String(20), nullable=False, default='default.jpg')
	dp2 = db.Column(db.String(20), nullable=False, default='flip.png')
	dp3 = db.Column(db.String(20), nullable=False, default='plane.png')
	password = db.Column(db.String(60), nullable=False)
	last_seen = db.Column(db.DateTime, default=datetime.utcnow)
	date_joined = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
	department = db.Column(db.String(20), nullable=False)
	student_number = db.Column(db.Integer(), unique=True, nullable=True)
	age = db.Column(db.DateTime, nullable=False)
	gender = db.Column(db.String(20), nullable=False)
	country = db.Column(db.String(20), default="Cyprus", nullable=True)
	bio = db.Column(db.String(120), nullable=True)
	private = db.Column(db.Boolean, default=False, nullable=False)
	snapchat = db.Column(db.String(20), default="snapchat", nullable=True)
	instagram = db.Column(db.String(20), default="instagram", nullable=True)
	followed = db.relationship(
		'User', secondary=followers,
		primaryjoin=(followers.c.follower_id == id),
		secondaryjoin=(followers.c.followed_id == id),
		backref=db.backref('followers', lazy='dynamic'), lazy='dynamic')
	messages_sent = db.relationship('Message',
									foreign_keys='Message.sender_id',
									backref='author', lazy='dynamic', cascade="all, delete-orphan")
	messages_received = db.relationship('Message',
										foreign_keys='Message.recipient_id',
										backref='recipient', lazy='dynamic', cascade="all, delete-orphan")
	last_message_read_time = db.Column(db.DateTime)


	def get_reset_token(self, expires_sec=1800):
		s = Serializer(app.config['SECRET_KEY'], expires_sec)
		return s.dumps({'user_id' : self.id}).decode('utf-8')


	@staticmethod
	def verify_reset_token(token):
		s = Serializer(app.config['SECRET_KEY'])
		try:
			user_id = s.loads(token)['user_id']
		except:
			return None
		return User.query.get(user_id)


	def __repr__(self):
		return f"User('{self.username}' , '{self.email}', '{self.dp}')"

	def birthday(self):
		if self.age.month == datetime.today().month:
			if self.age.day == datetime.today().day:
				return True

	def follow(self, user):
		if not self.is_following(user):
			self.followed.append(user)

	def unfollow(self, user):
		if self.is_following(user):
			self.followed.remove(user)

	def is_following(self, user):
		return self.followed.filter(followers.c.followed_id == user.id).count() > 0

	def new_messages(self):
		last_read_time = self.last_message_read_time or datetime(1900, 1, 1)
		return Message.query.filter_by(recipient=self).filter(
			Message.timestamp > last_read_time).count()

	@staticmethod
	def on_changed_body(target, value, oldvalue, initiator):
		allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
		'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul',
		'h3', 'p', 'iframe']
		target.content = bleach.linkify(bleach.clean(markdown(value, output_format='html'),
			tags=allowed_tags, strip=True))