Пример #1
0
class User(object):
    query = db_session.query_property()

    def __init__(self, name, username, password, admin=0, id=None):
        if not id == None:
            self.id = id
        else:
            self.id = randomString(6)

        self.username = username
        self.password = password
        self.admin = admin
        self.name = name

    def check_password(self, password):
        return check_password_hash(self.password, password)

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return self.id

    def __repr__(self):
        return '<User %r>' % (self.username)
class itemSubcategory(object):
    query = db_session.query_property()

    def __init__(self,
                 category_id,
                 name,
                 icon,
                 button_color="primary",
                 sort_order=999999,
                 added=datetime.datetime.utcnow(),
                 updated=datetime.datetime.utcnow()):
        self.category_id = category_id
        self.name = name
        self.icon = icon
        self.button_color = button_color
        self.sort_order = sort_order
        self.added = added
        self.updated = updated

    def __str__(self):
        return '<itemSubcategory {}>'.format(self.id)

    def getCategory(self):
        return itemCategory.query.filter_by(id=self.category_id).first()

    def getType(self):
        return itemType.query.filter_by(id=self.getCategory().type_id).first()

    def getPrice(self):
        return '{:,.2f}'.format(
            ItemPrice.query.filter_by(item_subcategory=self.id).first().price)

    def getAttributes(self):
        return attr_to_subcategory.query.filter_by(
            subcategory_id=self.id).all()
Пример #3
0
class ItemPrice(object):
    query = db_session.query_property()

    def __init__(self, item_type, category, subcategory, price):
        self.item_type = item_type
        self.item_category = category
        self.item_subcategory = subcategory
        self.price = price
Пример #4
0
class StudentToProject(object):
	query = db_session.query_property()

	def __init__(self, project_id, user_id, project_strengths):
		self.project_id = project_id
		self.user_id = user_id
		self.project_strengths = project_strengths
 
	def __repr__(self):
		return '<StudentToProject %r->%r->%r>' % (self.user_id, self.project_id, self.project_strengths)
Пример #5
0
class itemType(object):
	query = db_session.query_property()

	
	def __init__(self, name, icon, added=datetime.datetime.utcnow(), updated=datetime.datetime.utcnow()):
		self.name = name
		self.icon = icon
		self.added = added
		self.updated = updated


	def __str__(self):
		return '<itemType {}>'.format(self.item_id)
Пример #6
0
class GioOption(object):
    query = db_session.query_property()
    id = Column('id', Integer(), primary_key=True, unique=True)
    option_key = Column('option_key', Text())
    option_value = Column('option_value', Text())
    created = Column('created', DateTime(), default=datetime.datetime.utcnow())
    updated = Column('updated', DateTime(), default=datetime.datetime.utcnow())

    def __init__(self, id, option_key, option_value, created, updated):
        self.id = item_id
        self.option_key = option_key
        self.option_value = option_value
        self.created = created
        self.updated = updated
class attr_to_subcategory(object):
	query = db_session.query_property()

	def __init__(self, subcategory_id, attr_id):
		self.subcategory_id = subcategory_id
		self.attr_id = attr_id


	def __str__(self):
		return '<attr_to_subcategory {}>'.format(self.item_id)

	def getCategory(self):
		return itemSubcategory.query.filter_by(id=self.subcategory_id).first()

	def getAttribute(self):
		return itemAttribute.query.filter_by(id=self.attr_id).first()
Пример #8
0
class StudentToGroup(object):
    query = db_session.query_property()

    def __init__(self, group_id, user_id):
        self.group_id = group_id
        self.user_id = user_id
        self.project_id = self.get_group().get_project().project_id
        self.project = Project.query.filter_by(project_id=self.project_id)

    def get_group(self):
        return Group.query.filter_by(id=self.group_id).first()

    def get_user(self):
        return User.query.filter_by(id=self.user_id).first()

    def __repr__(self):
        return '<StudentToGroup %r->%r>' % (self.group_id, self.user_id)
Пример #9
0
class itemAttribute(object):
    query = db_session.query_property()

    def __init__(self,
                 attr_name,
                 attr_values,
                 added=datetime.datetime.utcnow(),
                 updated=datetime.datetime.utcnow()):
        attr_name = attr_name.replace("'", "").replace("\"",
                                                       "").replace("#", "")
        self.attr_name = attr_name
        self.attr_values = attr_values
        self.added = added
        self.updated = updated

    def __str__(self):
        return '<itemAttribute {}>'.format(self.id)
Пример #10
0
class Group(object):
	query = db_session.query_property()

	def __init__(self,  group_name, project_id, solution_desc):
		self.id = randomString(5)
		self.project_id = project_id
		self.name = group_name
		self.solution_desc = solution_desc
 
	def has_member(self, user_id):
		return StudentToGroup.query.filter_by(group_id=self.id, user_id=user_id).first() is not None

	def get_members(self):
		return [x.get_user() for x in StudentToGroup.query.filter_by(group_id=self.id).all()]

	def get_project(self):
		return Project.query.filter_by(project_id=self.project_id).first()
		
	def __repr__(self):
		return '<Group %r>' % (self.name)
Пример #11
0
class itemCategory(object):
    query = db_session.query_property()

    def __init__(self,
                 type_id,
                 name,
                 icon,
                 button_color="primary",
                 sort_order=999999,
                 added=datetime.datetime.utcnow(),
                 updated=datetime.datetime.utcnow()):
        self.type_id = type_id
        self.name = name
        self.icon = icon
        self.button_color = button_color
        self.sort_order = sort_order
        self.added = added
        self.updated = updated

    def getType(self):
        return itemType.query.filter_by(id=self.type_id).first()

    def __str__(self):
        return '<itemCategory {}>'.format(self.id)
Пример #12
0
class Project(object):
	query = db_session.query_property()

	def __init__(self,  project_name, user_id, description, autoAssign_group_id = None):
		self.project_id = randomString(50)
		self.project_name = project_name
		self.user_id = user_id
		self.description = description
		self.groups = self.get_groups()
		self.nice_url = self.project_id[:8]

		self.autoAssign_group_id = autoAssign_group_id


	def get_groups(self):
		self.groups = Group.query.filter_by(project_id=self.project_id).order_by(Group.name.asc()).all()

		return self.groups
	
	def get_members(self):
		self.members = StudentToProject.query.filter_by(project_id=self.project_id).all()

		return self.members

	def assign_autoassign(self):
		print("hello world")
		autoAssign_group = Group.query.filter_by(id=self.autoAssign_group_id).first()

		no_place = []

		members = autoAssign_group.get_members()

		numberOfMembers = len(members)

		left_overs = numberOfMembers % 3
		max_groups = 3

		if max_groups in [0, 1]:
			groups = [members]

		else:

			groups = []

			while len(groups) <= max_groups and numberOfMembers >= 1:
				print("GROUPS", len(groups) <= max_groups, len(groups), max_groups)
				print("MEMBERS", numberOfMembers > 1, numberOfMembers)

				#print(len(groups), max_groups)
				group = []
				found_group = False
				# Loop each member
				for x in range(numberOfMembers):
					# get the current member
					member = members[x]
					print("Found Member: ", member)
					group.append(member)

					schedule = json.loads(member.schedule)

					for y in range(numberOfMembers):

						member2 = members[y]
						schedule2 = json.loads(member2.schedule)

						if member == member2:
							continue
						
						print("TESTING MEMBER 2:", member2)

						compare = compareSchedules(schedule, schedule2)

						if not compare is False:
							print("Found Member: ", member2)

							if not len(compare[0]) > 2:
								continue

							group.append(member2)
							new_schedule = compare[0]

							for z in range(numberOfMembers):
								member3 = members[z]

								if member3 == member2 or member3 == member:
									continue

								print("TESTING MEMBER 3:", member3)
								final_schedule = compareSchedules(new_schedule, json.loads(member3.schedule))

								if not final_schedule is False:
									print("Found Member: ", member3)
									group.append(member3)
									groups.append(group)
									found_group = True

									if numberOfMembers == 3:
										numberOfMembers = 0

									break
								
								if left_overs == 2:
									groups.append(group)
									left_overs = 0
									found_group = True
									break


							if len(group) == 3 or found_group:
								break


					if found_group:
						break
					elif len(group) < 3:
						print("no group")
						no_place.append(member)
						print(no_place)
						members.remove(member)
						numberOfMembers = len(members)
						break

				if found_group:
					for student in group:
						members.remove(student)
					
					numberOfMembers = len(members)
					if numberOfMembers == 3:
						groups.append(members)
						members = []
						break

				if len(groups) == max_groups and 1 <= len(no_place) <= 4:
					groups.append(no_place)
					no_place = []
					print("no_place reset")
					break

			if not no_place == []:
				if len(no_place) == 1 and len(groups[-1]) < 4:
					groups[-1].append(no_place[0])
				elif len(groups[-1]) >= 4:
					groups.append([no_place[0]])
				else:
					for i in range(0, len(no_place), 3):
						print("no place %s " % i, no_place[i:i + 3])
						groups.append(no_place[i:i + 3])

		rows_to_add = []
		for i, group in enumerate(groups, start=1):
			groupObj = Group("Group #%s" % (i), self.project_id, "Describe your project here!")
			try:
				db_session.add(groupObj)
				db_session.commit()
			except:
				db_session.rollback()
				return False

			for user in group:
				stu_to_group = StudentToGroup(group_id=groupObj.id, user_id=user.id)
				rows_to_add.append(stu_to_group)


		db_session.delete(autoAssign_group)
		db_session.commit()
		db_session.add_all(rows_to_add)
		self.autoAssign_group_id = None
		db_session.commit()

		try:
			db_session.delete(autoAssign_group)
			db_session.add_all(rows_to_add)
			self.autoAssign_group_id = None
			db_session.commit()
		except:
			db_session.rollback()
			return False
		else:
			return True


 
	def __repr__(self):
		return '<Project %r>' % (self.project_name)
Пример #13
0
class Item(object):
	query = db_session.query_property()

	
	def __init__(self, item_id, item_type, category, subcategory, entered_by, removed_by=None, item_attributes="{}", unsold=0, price=None, tag_color=None, added=datetime.datetime.utcnow(), updated=datetime.datetime.utcnow()):
		self.item_id = item_id
		self.type = item_type
		self.category = category
		self.subcategory = subcategory
		self.entered_by = entered_by
		self.removed_by = removed_by

		original_price = ItemPrice.query.filter_by(item_type=item_type, item_category=category, item_subcategory=subcategory).first().price

		print(item_attributes)
		if not item_attributes == "{}":
			for attr in itemSubcategory.query.filter_by(id=self.subcategory).first().getAttributes():
				if not type(item_attributes) is dict:
					item_attributes = json.loads(item_attributes)
					
				if attr.getAttribute().attr_name.replace(" ", "_") in item_attributes.keys():
					attr_value = item_attributes[attr.getAttribute().attr_name.replace(" ", "_")]
					original_price += float(json.loads(attr.getAttribute().attr_values)[attr_value][1:])

		self.price = original_price
		self.item_attributes = json.dumps(item_attributes)
		self.tag_color = tag_color
		self.added = added
		self.unsold = 0
		self.updated = updated


	def __str__(self):
		return '<item {}>'.format(self.item_id)

	def as_dict(self):
		return {
			"item_id": self.item_id,
			"price": self.price,
			"tag_color": self.tag_color
		}

	def getTypeName(self):
		return itemType.query.filter_by(id=self.type).first().name

	def getCategoryName(self):
		return itemCategory.query.filter_by(id=self.category).first().name

	def getSubcategoryName(self):
		return itemSubcategory.query.filter_by(id=self.subcategory).first().name

	def getAttributes(self):
		return itemSubcategory.query.filter_by(id=self.subcategory).first().getAttributes()

	def getAttributeValues(self):
		return json.loads(self.item_attributes)

	def getTimeLeft(self):
		if self.unsold == 0:
			return timeago.format(self.added + datetime.timedelta(weeks=4))
		else:
			return "Unsold"
Пример #14
0
class User(object):
    query = db_session.query_property()

    def __init__(self,
                 email,
                 username=None,
                 password=None,
                 activation_token=None,
                 schedule={},
                 id=None,
                 user_type="student"):
        if not id == None:
            self.id = id
        else:
            self.id = randomString(50)

        self.username = username
        self.password = password
        self.email = email
        self.is_anonymous = False

        self.user_type = user_type

        self.schedule = json.dumps(schedule)
        self.activation_token = activation_token

    def check_password(self, password):
        return check_password_hash(self.password, password)

    def is_part_of_project(self, project_id):
        if self.user_type == "teacher":
            check = Project.query.filter_by(user_id=self.id,
                                            project_id=project_id).count()
        elif self.user_type == "student":
            check = StudentToProject.query.filter_by(
                user_id=self.id, project_id=project_id).count()

        if check == 1:
            return True
        else:
            return False

    def get_projects(self):
        if self.user_type == "teacher":
            self.projects = Project.query.filter_by(user_id=self.id).all()
        elif self.user_type == "student":
            projects = []
            links = StudentToProject.query.filter_by(user_id=self.id).all()
            for project in links:
                projects.append(
                    Project.query.filter_by(
                        project_id=project.project_id).first())

            self.projects = projects

        return self.projects

    def get_project_strength(self, project_id):
        if not self.is_part_of_project(project_id):
            return None
        else:
            connection = StudentToProject.query.filter_by(
                user_id=self.id, project_id=project_id).first()

            if not connection is None:
                return connection.project_strengths

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return self.id

    def refresh(self):
        self = self.query.filter_by(id=self.id)
        return self

    def __repr__(self):
        return '<User %r>' % (self.username)