Ejemplo n.º 1
0
def forum_details(request):
	main_response = {}
	json_response = {}
	if request.method == 'GET':
		required = ['forum']

		try:
			check_dict(request.GET, required)
		except Exception as e:
			if e.message == 'required':
				return JsonResponse({'code':1, 'response': e.message})

		short_name = request.GET['forum']
		related = request.GET['related']

		forum = Forum.objects.get(short_name = short_name)

		main_response = {'code':0}
		json_response['id'] = forum.id
		json_response['name'] = forum.name
		json_response['short_name'] = forum.short_name

		if related.count('user') == 1:
			json_response['user'] = get_user_info(forum.user)


	main_response['response'] = json_response
	response = JsonResponse(main_response)

	return response
Ejemplo n.º 2
0
def handle_section(section):
    userinfo = get_user_info(session)
    sections = set(userinfo['sections'])

    if request.method == 'DELETE': 
        # Removing a course
        try:
            sections.remove(section)
        except:
            pass
        sections = list(sections)
        update_user_schedule(session['userid'], sections)
        return simplejson.dumps(sections)

    else: 
        # Adding a course
        allTimes = {}
        conflictDetected = False

        if section in sections:
            return simplejson.dumps( get_sections_for_user(session) )

        for s in sections:
            allTimes[s] = convertTimeStringToDictionary(get_times_for_section(g.db, s))
            if not (noConflict(allTimes, convertTimeStringToDictionary(get_times_for_section(g.db, section)))):
                conflictDetected = True
                break

        if conflictDetected:
            return "Conflict detected", 400

        else:
            sections.add(section)
            update_user_schedule(session['userid'], list(sections))
            return simplejson.dumps( get_sections_for_user(session) )
Ejemplo n.º 3
0
def get_post_info(post_details, related):

	info = {}

	info['date']			= dateformat.format(post_details.date, settings.DATETIME_FORMAT)
	info['dislikes']		= post_details.dislikes

	if find_list(related, 'forum'):
		info['forum']	= get_forum_info(post_details.forum)
	else:
		info['forum']	= post_details.forum.short_name
	info['id']				= post_details.id
	info['isApproved']		= post_details.isApproved
	info['isDeleted']		= post_details.isDeleted
	info['isEdited']		= post_details.isEdited
	info['isHighlighted']	= post_details.isHighlighted
	info['isSpam']			= post_details.isSpam
	info['likes']			= post_details.likes
	info['message']			= post_details.message
	if post_details.parent != 0:
		info['parent']		= post_details.parent
	info['points']			= post_details.points

	if find_list(related, 'thread'):
		info['thread']	= get_thread_info(post_details.thread, [])
	else:
		info['thread']	= post_details.thread.id

	if find_list(related, 'user'):
		info['user']	= get_user_info(post_details.user)
	else:
		info['user']	= post_details.user.email

	return info
Ejemplo n.º 4
0
def get_thread_info(thread_detail, related):
	info = {}

	info['date']		= dateformat.format(thread_detail.date, settings.DATETIME_FORMAT)
	info['dislikes']	= thread_detail.dislikes
	
	if find_list(related, 'forum'):
		info['forum']	= get_forum_info(thread_detail.forum)
	else:
		info['forum']	= thread_detail.forum.short_name

	info['id']			= thread_detail.id
	info['isClosed']	= thread_detail.isClosed
	info['isDeleted']	= thread_detail.isDeleted
	info['likes']		= thread_detail.likes
	info['message']		= thread_detail.message
	info['points']		= thread_detail.points
	info['posts']		= Post.objects.filter(thread = thread_detail, isDeleted = False).count()
	info['slug']		= thread_detail.slug
	info['title']		= thread_detail.title
	if find_list(related, 'user'):
		info['user']	= get_user_info(thread_detail.user)
	else:
		info['user']	= thread_detail.user.email
	
	return info
Ejemplo n.º 5
0
def get_sections_for_user(session):
    userinfo = get_user_info(session)
    sections = set(userinfo['sections'])
    ret = {}

    for section in sections:
        ret[section] = convertTimeStringToDictionary(get_times_for_section(g.db, section))
 
    return ret
Ejemplo n.º 6
0
def forum_listUsers(request):

	main_response = {'code':0}
	
	if request.method == 'GET':
		since = int(request.GET.get('since', 0))
		order = request.GET.get('order', 'DESC')
		limit = int(request.GET.get('limit', 0))
		forum_name = request.GET['forum']

		sort_order = ''
		limit_string = ''
		since_string = ''

		sort_order = " ORDER BY subdapp_user.name ASC"

		if order == 'desc':
			sort_order = " ORDER BY subdapp_user.name DESC"
		
		if limit > 0:
			limit_string = "LIMIT %d" % limit
		if since > 0:
			since_string = "AND subdapp_user.id >= %d" % since
		user_list = []

		# forum = Forum.objects.get(short_name = forum_name)
		# user_list = list(Thread.objects.values_list('user', flat=True).filter(forum=forum)) #.order_by()

		out_list = []

		# # for out_thread_id in thread_list:
		# # 	out_thread = Thread.objects.get(id = out_thread_id)
		# # 	out_list.append(get_thread_info(out_thread, related))
		cursor = connection.cursor()
		query = "SELECT DISTINCT subdapp_user.id FROM subdapp_user INNER JOIN subdapp_post ON subdapp_user.id = subdapp_post.user_id \
			INNER JOIN subdapp_forum ON subdapp_post.forum_id = subdapp_forum.id \
			WHERE subdapp_forum.short_name = \"%s\" %s \
			%s %s" % (forum_name, since_string, sort_order, limit_string)
		cursor.execute(query)
#forum_name, since_string,
		for row in cursor.fetchall():
			user_list.append(row[0])


		for out_user_id in user_list:
		 	out_user = User.objects.get(id = out_user_id)
		 	out_list.append(get_user_info(out_user))

		json_response = out_list


	main_response['response'] = json_response

	response = JsonResponse(main_response)

	return response
Ejemplo n.º 7
0
def update_starred(courseid = ''):
    starred = set( get_user_info(session)['starred'] )
    
    if request.method == 'DELETE':
        try:
            starred.remove(courseid)
        except:
            pass
        starred = list(starred)
        update_user_starred(session['userid'], starred)
        return simplejson.dumps(starred)

    else:
        starred.add(courseid)
        starred = list(starred)
        update_user_starred(session['userid'], starred)
        return simplejson.dumps(starred)
Ejemplo n.º 8
0
def get_starred():
    starred = get_user_info(session)['starred']
    return simplejson.dumps(starred)
Ejemplo n.º 9
0
def index():
    userinfo = get_user_info(session)
    return render_template("index.html", sections = userinfo['sections'], starred = map(int, userinfo['starred']), allSections = get_courseids_for_all_sections(g.db))
Ejemplo n.º 10
0
def reset_stars():
    update_user_starred(session['userid'], [])
    starred = get_user_info(session)['starred']
    return simplejson.dumps(starred)    
Ejemplo n.º 11
0
def reset_sections():
    update_user_schedule(session['userid'], [])
    sections = get_user_info(session)['sections']
    return simplejson.dumps(sections)
Ejemplo n.º 12
0
def get_sections():
    sections = get_user_info(session)['sections']
    return simplejson.dumps(sections)