Esempio n. 1
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))
Esempio n. 2
0
 def has_access(self, access_obj):
     from apps.walls.utils import check_access_rights
     return check_access_rights(access_obj, self)
Esempio n. 3
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))
Esempio n. 4
0
 def has_access(self, access_obj):
     from apps.walls.utils import check_access_rights
     check_access_rights(access_obj, self)