Ejemplo n.º 1
0
def get_posts(request, **kwargs):
    page = kwargs.get("page", None)
    wall_id = kwargs.get("wall_id", None)
    post_id = kwargs.get("id", None)
    exhausted = False
    user = request.user

    if wall_id:
        posts_list = get_my_posts(
            user,
            Wall.objects.filter(id=wall_id)[0]).order_by('-time_created')
    else:
        posts_list = get_my_posts(user).order_by('-time_created')

    if page:
        items, exhausted = paginate_items(posts_list, **kwargs)
    elif post_id:
        items = posts_list.filter(id=int(post_id))

    append_string = ""
    for item in items:
        local_context = {
            'post': item,
            'show_post': 'True',
        }
        append_string += "<hr />" \
            + render_to_string('modules/post.html', local_context, context_instance= global_context(request, token_info=False))
    local_context = {
        "append_string": append_string,
        "exhausted": exhausted,
        "wall_id": wall_id,
    }
    return json.dumps(local_context)
Ejemplo n.º 2
0
def get_posts(request, **kwargs):
    page = kwargs.get("page", None)
    wall_id = kwargs.get("wall_id", None)
    post_id = kwargs.get("id", None)
    exhausted = False
    user = request.user

    if wall_id:
        posts_list = get_my_posts(user, Wall.objects.filter(id = wall_id)[0]).order_by('-time_created');
    else:
        posts_list = get_my_posts(user).order_by('-time_created')

    if page:
        items, exhausted = paginate_items(posts_list, **kwargs)
    elif post_id:
        items = posts_list.filter(id = int(post_id))
    
    append_string = ""
    for item in items:
        local_context = {
            'post' : item, 
            'show_post' : 'True',
        }
        append_string += "<hr />" \
            + render_to_string('modules/post.html', local_context, context_instance= global_context(request, token_info=False))
    local_context = {
        "append_string" : append_string,
        "exhausted" : exhausted,
        "wall_id" : wall_id,
    }
    return json.dumps(local_context)
Ejemplo n.º 3
0
def query(request, query):
	user = request.user
	results = SearchQuerySet().filter(content=query)
	results_list = [q.get_stored_fields() for q in results]
	accessible_posts_id = [post.id for post in get_my_posts(user)]
	for post in results_list:
		if post['post_id'] not in accessible_posts_id:
			results_list.remove(post)
	return json.dumps(results_list)
Ejemplo n.º 4
0
    def list(self, request):
        """
		Return posts to an authenticated User
		limit -- number of items to be returned
		offset -- offset
		wall_id --  wall id or post id
		"""
        message = ''
        data = []
        wall_id = request.QUERY_PARAMS.get('wall_id')
        offset = request.QUERY_PARAMS.get('offset')
        limit = request.QUERY_PARAMS.get('limit')

        if not wall_id:
            message = 'please enter wall id'
            return Response(viewset_response(message, data))
        wall = Wall.objects.filter(id=int(wall_id))
        if not wall:
            message = 'no wall with that id exists'
            return Response(viewset_response(message, data))
        posts = get_my_posts(request.user, wall, offset, limit)
        try:
            if posts['error']:
                message = posts['error']
                return Response(viewset_response(message, data))
        except:
            pass
        if not posts:
            message = 'no post with that id exists'
            return Response(viewset_response(message, data))
        postserializer = PostSerializer(posts, many=True)
        for i in range(len(postserializer.data)):
            postserializer.data[i]["description"] = HTMLParser.HTMLParser(
            ).unescape(
                strip_tags(postserializer.data[i]["description"].strip()))
            for j in range(len(postserializer.data[i]["comments"])):
                postserializer.data[i]["comments"][j][
                    "description"] = HTMLParser.HTMLParser().unescape(
                        strip_tags(postserializer.data[i]["comments"][j]
                                   ["description"].strip()))
        data = postserializer.data
        return Response(viewset_response(message, data))
Ejemplo n.º 5
0
	def list(self,request):
		"""
		Return posts to an authenticated User
		limit -- number of items to be returned
		offset -- offset
		wall_id --  wall id or post id
		"""
		message=''
		data=[]
		wall_id=request.QUERY_PARAMS.get('wall_id')
		offset=request.QUERY_PARAMS.get('offset')
		limit=request.QUERY_PARAMS.get('limit')
	
		if not wall_id:
			message='please enter wall id'
			return Response(viewset_response(message,data))
		wall= Wall.objects.filter(id=int(wall_id))
		if not wall:
			message='no wall with that id exists'
			return Response(viewset_response(message,data))
		posts = get_my_posts(request.user,wall,offset,limit)
		try:
			if posts['error']:
				message=posts['error']
				return Response(viewset_response(message,data))
		except:
			pass
		if not posts:
			message='no post with that id exists'
			return Response(viewset_response(message,data))
		postserializer = PostSerializer(posts,many=True)
		for i in range(len(postserializer.data)):
			postserializer.data[i]["description"]=HTMLParser.HTMLParser().unescape(strip_tags(postserializer.data[i]["description"].strip()))
			for j in range(len(postserializer.data[i]["comments"])):
				postserializer.data[i]["comments"][j]["description"] = HTMLParser.HTMLParser().unescape(strip_tags(postserializer.data[i]["comments"][j]["description"].strip()))
		data=postserializer.data
		return Response(viewset_response(message,data))
Ejemplo n.º 6
0
def wall (request, wall_id=None):
    """
        Renders a Wall. It can be of User, Department, subdepartment etc.

        Args:
            request     :The HTTP Request:
            wall_id     :ID of the wall that has to be shown

        Kwargs:
            None

        Returns:
            If id found in database : renders 'pages/wall.html'
            > Context variables in the `pages/wall.html` :-
                - global_context_variables : misc.utils.global_context()
                - wall      :  The current wall objects
                - posts     : Posts related to the wall
        Raises:
            None
    """
    # Default argument setting and checking
    user = request.user
    if hasattr(user, "erp_profile"):
        user_erp_profile = user.erp_profile
    else:
        user_erp_profile = None
    wall = None
    if wall_id == None:    
        if user_erp_profile and hasattr(request.user.erp_profile, "wall"):
            wall = user_erp_profile.wall
            wall_id = wall.id
    else:
        # Initial validations
        try:
            wall_id = int(wall_id)
        except ValueError:
            wall_id = None
        if not ( type(wall_id) is int ):
            raise InvalidArgumentTypeException("`wall_id` type is wrong. Expected an integer. Got : " + str(wall_id))
        wall = get_object_or_None(Wall, id=wall_id)

    wall_accessible = True

    # Logic
        # Check wall conditions
    if not wall:
        raise InvalidArgumentValueException("Wall with the `wall_id` " + str(wall_id) + " not found.")
    elif not wall.has_access(user) and not user.is_superuser:
        wall_accessible = False

    wall_admin =  user.is_superuser or ( check_access_rights( user, wall ) and user.is_staff )
    
        # Get wall posts
    #if not wall_accessible:
    #    wall_posts = get_my_posts(user, wall)[:5]
    #if wall_accessible:
    #    wall_posts = Post.objects.filter(wall=wall).order_by('-time_created')[:5]
    # single function to get all relevant posts.
    wall_posts = get_my_posts(user, wall)[:5]
    
    wall_parent = wall.parent
    #import pdb;pdb.set_trace();
    local_context = {
        "current_page" : "wall",
        "wall" : wall,
        "showing_user" : wall_parent,
        "wall_posts" : wall_posts,
        "wall_accessible" : wall_accessible,
        "wall_admin" : wall_admin
    }
    return render_to_response('pages/wall.html', local_context, context_instance= global_context(request))
Ejemplo n.º 7
0
def wall (request, wall_id=None, post_id=None):
    """
        Renders a Wall. It can be of User, Department, subdepartment etc.

        Args:
            request     :The HTTP Request:
            wall_id     :ID of the wall that has to be shown

        Kwargs:
            None

        Returns:
            If id found in database : renders 'pages/wall.html'
            > Context variables in the `pages/wall.html` :-
                - global_context_variables : misc.utils.global_context()
                - wall      :  The current wall objects
                - posts     : Posts related to the wall
        Raises:
            None
    """
    # Default argument setting and checking
    user = request.user
    if hasattr(user, "erp_profile"):
        user_erp_profile = user.erp_profile
    else:
        user_erp_profile = None
    wall = None
    if wall_id == None:    
        if user_erp_profile and hasattr(request.user.erp_profile, "wall"):
            wall = user_erp_profile.wall
            wall_id = wall.id
    else:
        # Initial validations
        try:
            wall_id = int(wall_id)
        except ValueError:
            wall_id = None
        if not ( type(wall_id) is int ):
            raise InvalidArgumentTypeException("`wall_id` type is wrong. Expected an integer. Got : " + str(wall_id))
        wall = get_object_or_None(Wall, id=wall_id)

    wall_accessible = True

    # Logic
        # Check wall conditions
    if not wall:
        raise InvalidArgumentValueException("Wall with the `wall_id` " + str(wall_id) + " not found.")
    elif not wall.has_access(user) and not user.is_superuser:
        wall_accessible = False

    wall_admin =  user.is_superuser or ( check_access_rights( user, wall ) and user.is_staff )
    
        # Get wall posts
    #if not wall_accessible:
    #    wall_posts = get_my_posts(user, wall)[:5]
    #if wall_accessible:
    #    wall_posts = Post.objects.filter(wall=wall).order_by('-time_created')[:5]
    # single function to get all relevant posts.

    wall_posts = get_my_posts(user, wall, id=post_id)[:5]
    
    wall_parent = wall.parent
    #import pdb;pdb.set_trace();
    local_context = {
        "current_page" : "wall",
        "wall" : wall,
        "showing_user" : wall_parent,
        "wall_posts" : wall_posts,
        "wall_accessible" : wall_accessible,
        "wall_admin" : wall_admin
    }
    return render_to_response('pages/wall.html', local_context, context_instance= global_context(request))