Пример #1
0
def file_upload(response):
    auth.require_user(response)
    user = auth.get_user(response)
    if user == None:
        return
    else:
        username = user.get_username()    
    ul_error_msg = ""
    filename, content_type, data = response.get_file('to_upload')
    if response.get_field("ul_flag") == "True":
        # we did submit a form
        print"#####", response.get_field("subject")
        if data == None or response.get_field("subject") == None or response.get_field("category") == None or response.get_field("description") == None:
            ul_error_msg = "Make sure you have all fields filled in and have selected a file. If you have joined any subject(s), you cannot upload files."
        else:
            #A form was submitted with content. Proceed with upload
            print "a form was submitted"
            _do_upload(response)
            return
    # we did not submit a form or it's wrong
    print "loading page first time"
    listofsubjects = []
    for item in user.get_subjects():
        listofsubjects.append([item, database_subject.get_subject(item).get_name().replace("_", " ")])
        print "item", item
    context = {"css": "fileupload",
               "title": "File Uploader",
               "ul_err_msg": ul_error_msg,
               "ulsubjects": listofsubjects,
               "ulcategories": ["Notes", "Exam Paper","Exercises", "Solution"],
               "user": user}
    template.render_template("templates/fileupload.html", context, response)
Пример #2
0
def viewsubject(response, subjectid, resourcetype, page):
    auth.require_user(response)
    if not resourcetype:
        resourcetype = 'All'
    if not page:
        page = 1
    user = auth.get_user(response)
    info = database_subject.get_subject(int(subjectid))
    lower = (int(page) - 1 )*10
    upper = int(page)*10 - 1
    
    top_resources = dbfiles.getFilesSubject(int(subjectid))
    sorted(top_resources, key=attrgetter('rank'), reverse=True)
    #eliminate those without the correct type
    new_top = []
    if len(top_resources):
        for s in top_resources:
            if s.category == resourcetype or resourcetype == 'All':
                new_top.append(s)
        top_resources = new_top[lower:upper]

    all_resources = dbfiles.getFilesSubject(int(subjectid))
    sorted(all_resources, key=attrgetter('ori_filename'))
    if len(all_resources):
        new_all = []
        for s in all_resources:
            if s.category == resourcetype or resourcetype == 'All':
                new_all.append(s)
        all_resources = new_all[lower:upper]

    template.render_template("templates/subject_view_template.html",{"user":user, "css":"subject","subject":info,"top_resources":top_resources,"all_resources":all_resources,'current_Wall':subjectid,'wallorfeed':'wallupdate','can_use_wall':True},response)
Пример #3
0
	def get_wall(self):
		
		final = []
		data = self.cursor.execute('SELECT * FROM WALL ORDER BY time DESC')
		if not data:
			return 0
		for row in data:
			current_Row = [[row[0],row[1],row[1],row[2],row[4],age(int(row[3])),'']];
			if row[2] == self.current_Wall:
				
				author = User.get(row[1])
				fullname = author.get_first_name() + " " + author.get_last_name()
				path = author.get_profile_pic_path()
				
				if not path:
					current_Row[0][6] = '/static/images/default_avatar.jpeg'
				else:
					current_Row[0][6] = path
				if current_Row[0][3].isdigit():
					current_Row[0][3] = database_subject.get_subject(current_Row[0][3]).get_name()
					current_Row[0][3] = current_Row[0][3].replace('_',' ')
					current_Row[0][3] = 'Posted to ' + current_Row[0][3]
				elif current_Row[0][3] == current_Row[0][2]:
						current_Row[0][3] = ''
				else:
					current_Row[0][3] = 'Posted to ' + current_Row[0][3] +'\'s wall'
					
				current_Row[0][1] = fullname
				final.append(current_Row[0])
			
		
		return final
Пример #4
0
def mysubjects(response):
    user = auth.get_user(response)
    subjectlist = user.get_subjects()
    tmp_list = []
    for sub in subjectlist:
        sub = database_subject.get_subject(sub)
        tmp_list.append(sub)
    subjectlist = tmp_list
    template.render_template("templates/subject_list_template.html",{"user":user, "css":"subject","subjectlist":subjectlist},response)
    targetsubject=response.get_field("subjectselected")
Пример #5
0
    def get_wall(self):

        final = []
        data = self.cursor.execute('SELECT * FROM WALL ORDER BY time DESC')
        if not data:
            return 0
        for row in data:
            current_Row = [[
                row[0], row[1], row[1], row[2], row[4],
                age(int(row[3])), ''
            ]]
            if row[2] == self.current_Wall:

                author = User.get(row[1])
                fullname = author.get_first_name(
                ) + " " + author.get_last_name()
                path = author.get_profile_pic_path()

                if not path:
                    current_Row[0][6] = '/static/images/default_avatar.jpeg'
                else:
                    current_Row[0][6] = path
                if current_Row[0][3].isdigit():
                    current_Row[0][3] = database_subject.get_subject(
                        current_Row[0][3]).get_name()
                    current_Row[0][3] = current_Row[0][3].replace('_', ' ')
                    current_Row[0][3] = 'Posted to ' + current_Row[0][3]
                elif current_Row[0][3] == current_Row[0][2]:
                    current_Row[0][3] = ''
                else:
                    current_Row[0][
                        3] = 'Posted to ' + current_Row[0][3] + '\'s wall'

                current_Row[0][1] = fullname
                final.append(current_Row[0])

        return final
Пример #6
0
 def getsubjectname(self):
     return database_subject.get_subject(self.subjectid).get_name().replace("_", " ")
Пример #7
0
	def get_feed(self):
		
		final = []
		friendsList = get_friends(self.current_User)
		
		data = self.cursor.execute('SELECT * FROM WALL ORDER BY time DESC LIMIT 15;')
		if not data:
			return 0
		for row in data:
			current_Row = [[row[0],row[1],row[1],row[2],row[4],age(int(row[3])),'']]		
			for user in friendsList:
				if user.get_username() == row[1]:
					if current_Row not in final:
						
						

						fullname = user.get_first_name() + " " + user.get_last_name()
						current_Row[0][1] = fullname
						#set the picture
						path = user.get_profile_pic_path()
						
						if not path:
							current_Row[0][6] = '/static/images/default_avatar.jpeg'
							
						else:
							current_Row[0][6] = path
						
							
						if current_Row[0][3].isdigit():
							current_Row[0][3] = database_subject.get_subject(current_Row[0][3]).get_name()
							current_Row[0][3] = current_Row[0][3].replace('_',' ')
							current_Row[0][3] = 'Posted to ' + current_Row[0][3]
						elif current_Row[0][3] == current_Row[0][2]:
							current_Row[0][3] = ''
						else:
							current_Row[0][3] = 'Posted to ' + current_Row[0][3] +'\'s wall'
						final.append(current_Row[0])
						
						
			if self.currentUserObject.get_username() == row[1]:
				currentuser = self.currentUserObject
				fullname = currentuser.get_first_name() + " " + currentuser.get_last_name()
				current_Row[0][1] = fullname
				path = currentuser.get_profile_pic_path()
				if not path:
					current_Row[0][6] = '/static/images/default_avatar.jpeg'
						
				else:
					current_Row[0][6] = path
				if current_Row[0][3].isdigit():
					current_Row[0][3] = database_subject.get_subject(current_Row[0][3]).get_name()
					current_Row[0][3] = current_Row[0][3].replace('_',' ')
					current_Row[0][3] = 'Posted to ' + current_Row[0][3]
				elif current_Row[0][3] == current_Row[0][2]:
						current_Row[0][3] = ''
				else:
					current_Row[0][3] = 'Posted to ' + current_Row[0][3]+'\'s wall'
				final.append(current_Row[0])
				
						
				#	elif row[0] not in final[0]:
				#		print final[0]
		
		return final
Пример #8
0
 def getsubjectname(self):
     return database_subject.get_subject(self.subjectid).get_name().replace(
         "_", " ")
Пример #9
0
    def get_feed(self):

        final = []
        friendsList = get_friends(self.current_User)

        data = self.cursor.execute(
            'SELECT * FROM WALL ORDER BY time DESC LIMIT 15;')
        if not data:
            return 0
        for row in data:
            current_Row = [[
                row[0], row[1], row[1], row[2], row[4],
                age(int(row[3])), ''
            ]]
            for user in friendsList:
                if user.get_username() == row[1]:
                    if current_Row not in final:

                        fullname = user.get_first_name(
                        ) + " " + user.get_last_name()
                        current_Row[0][1] = fullname
                        #set the picture
                        path = user.get_profile_pic_path()

                        if not path:
                            current_Row[0][
                                6] = '/static/images/default_avatar.jpeg'

                        else:
                            current_Row[0][6] = path

                        if current_Row[0][3].isdigit():
                            current_Row[0][3] = database_subject.get_subject(
                                current_Row[0][3]).get_name()
                            current_Row[0][3] = current_Row[0][3].replace(
                                '_', ' ')
                            current_Row[0][
                                3] = 'Posted to ' + current_Row[0][3]
                        elif current_Row[0][3] == current_Row[0][2]:
                            current_Row[0][3] = ''
                        else:
                            current_Row[0][3] = 'Posted to ' + current_Row[0][
                                3] + '\'s wall'
                        final.append(current_Row[0])

            if self.currentUserObject.get_username() == row[1]:
                currentuser = self.currentUserObject
                fullname = currentuser.get_first_name(
                ) + " " + currentuser.get_last_name()
                current_Row[0][1] = fullname
                path = currentuser.get_profile_pic_path()
                if not path:
                    current_Row[0][6] = '/static/images/default_avatar.jpeg'

                else:
                    current_Row[0][6] = path
                if current_Row[0][3].isdigit():
                    current_Row[0][3] = database_subject.get_subject(
                        current_Row[0][3]).get_name()
                    current_Row[0][3] = current_Row[0][3].replace('_', ' ')
                    current_Row[0][3] = 'Posted to ' + current_Row[0][3]
                elif current_Row[0][3] == current_Row[0][2]:
                    current_Row[0][3] = ''
                else:
                    current_Row[0][
                        3] = 'Posted to ' + current_Row[0][3] + '\'s wall'
                final.append(current_Row[0])

                #	elif row[0] not in final[0]:
                #		print final[0]

        return final