Exemple #1
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))
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
Exemple #5
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)
Exemple #6
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)
Exemple #7
0
class Message(db.Model):
	id = db.Column(db.Integer, primary_key=True)
	sender_id = db.Column(db.Integer, db.ForeignKey('user.id'))
	recipient_id = db.Column(db.Integer, db.ForeignKey('user.id'))
	body = db.Column(db.Text) #db.String(140)
	timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)

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

	def __repr__(self):
		return '<Message {}>'.format(self.body)
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)
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}')"
class Interest(db.Model):
    """ User interests and hobbies for matchmaking, Each Column will
    hold integers that correspond to the information on other tables.
    """

    __tablename__ = 'interests'

    interest_id = db.Column(db.Integer, autoincrement=True,
                            primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    book_genre_id = db.Column(db.Integer,
                            db.ForeignKey('book_genres.book_genre_id'),
                            nullable=False)
    movie_genre_id = db.Column(db.Integer,
                                db.ForeignKey('movie_genres.movie_genre_id'),
                                nullable=False)
    music_genre_id = db.Column(db.Integer,
                                db.ForeignKey('music_genres.music_genre_id'),
                                nullable=False)
    fav_cuisine_id = db.Column(db.Integer,
                                db.ForeignKey('fav_cuisines.fav_cuisine_id'),
                                nullable=False)
    hobby_id = db.Column(db.Integer,
                        db.ForeignKey('hobbies.hobby_id'), nullable=False)
    religion_id = db.Column(db.Integer,
                        db.ForeignKey('religions.religion_id'),
                        nullable=False)
    outdoor_id = db.Column(db.Integer,
                        db.ForeignKey('outdoors.outdoor_id'),
                        nullable=False)

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

        d1 ='< interest_id={a}, book_genre_id={b},'.format(a=self.interest_id,
                                                        b=self.book_genre_id)
        d2 =' movie_genre_id={c}, music_genre_id={d},'.format(c=self.movie_genre_id,
                                                        d=self.music_genre_id)
        d3 =' food_habit_id={e}, fav_cuisine_id={f},'.format(e=self.food_habit_id,
                                                        f=self.fav_cuisine_id)
        d4 =' hobby_id={g}, politicial_view_id={h},'.format(g=self.hobby_id,
                                                        h=self.political_view_id)
        d5 =' religion_id={i}, outdoor_id={j}>'.format(i=self.religion_id,
                                                        j=self.outdoor_id)

        return d1 + d2 + d3 + d4 + d5
Exemple #11
0
class PendingMatch(db.Model):
    """holds a list of all pending matches for user queries"""

    __tablename__ = "pending_matches"

    user_query_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    query_pin_code = db.Column(db.Integer, nullable=False)
    query_time = db.Column(db.DateTime, nullable=False)
    pending = db.Column(db.Boolean, nullable=False)

    def __repr__(self):
        """return information about a user query"""

        d1 = "<user_query_id={a}, user_id={b},".format(a=self.user_query_id,
                                                       b=self.user_id)
        d2 = " query_pin_code={c}, query_time={d},".format(
            c=self.query_pin_code, d=self.query_time)
        d3 = " pending={e}>".format(e=self.pending)

        return d1 + d2 + d3
Exemple #12
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
Exemple #13
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)
    zipcode = db.Column(db.String(15), 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')

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

    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
Exemple #14
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))
Exemple #15
0
from datetime import datetime
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from dating import db, login_manager, app
from flask_login import UserMixin
from markdown import markdown
import bleach



@login_manager.user_loader
def load_user(user_id):
	return User.query.get(int(user_id))

followers = db.Table(
	'followers',
	db.Column('follower_id', db.Integer, db.ForeignKey('user.id')),
	db.Column('followed_id', db.Integer, db.ForeignKey('user.id'))
)

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)