Esempio n. 1
0
def create_comment(request, post_id, data):
    """
        Creates a new comment on a Post
    """
    # Initial validations
    try:
        post_id = int(post_id)
    except ValueError:
        post_id = None
    if not ( type(post_id) is int ):
        raise InvalidArgumentTypeException("argument `post_id` should be of type integer")
    
    # Create a new comment
    append_string = ""
    data = deserialize_form(data).dict()

    
    # Attempt to get the post for the comment
    post = get_object_or_None(Post, id=int(post_id))
    comment_text = data['comment']
    if not post:
        raise InvalidArgumentValueException("No Post with id `post_id` was found in the database")

    comment_text, notification_list = parse_atwho(comment_text)

    rendered_comment_text = Template(
        '''
            {%load markdown_tags%}
            {%autoescape off%}
                {{ comment_text|markdown }}
            {%endautoescape%}
        '''
    ).render(RequestContext(request, { 
        'comment_text' : comment_text
    }))
    new_comment = Comment.objects.create(description=rendered_comment_text, by=request.user)
    post.comments.add(new_comment)
    
    post.add_notifications(notification_list)
    post_wall = post.wall
    if post_wall.parent:
        post.add_notifications([post_wall.parent, request.user]) # add to and from

    new_comment.send_notif() # Send notifs now, as all notif personnel are added
    
    # Render the new comment
    local_context = {
        'comment': new_comment, 
        'post': post
    }
    append_string =  render_to_string( 'modules/comment.html', local_context, context_instance=global_context(request, token_info=False))

    local_context = { 
        'append_string': append_string,
        'post_id' : post_id
    }
    return json.dumps(local_context)
Esempio n. 2
0
def create_comment(request, post_id, data):
    """
        Creates a new comment on a Post
    """
    # Initial validations
    try:
        post_id = int(post_id)
    except ValueError:
        post_id = None
    if not (type(post_id) is int):
        raise InvalidArgumentTypeException(
            "argument `post_id` should be of type integer")

    # Create a new comment
    append_string = ""
    data = deserialize_form(data).dict()

    # Attempt to get the post for the comment
    post = get_object_or_None(Post, id=int(post_id))
    comment_text = data['comment']
    if not post:
        raise InvalidArgumentValueException(
            "No Post with id `post_id` was found in the database")

    comment_text, notification_list = parse_atwho(comment_text)

    rendered_comment_text = Template('''
            {%load markdown_tags%}
            {%autoescape off%}
                {{ comment_text|markdown }}
            {%endautoescape%}
        ''').render(RequestContext(request, {'comment_text': comment_text}))
    new_comment = Comment.objects.create(description=rendered_comment_text,
                                         by=request.user)
    post.comments.add(new_comment)

    post.add_notifications(notification_list)
    post_wall = post.wall
    if post_wall.parent:
        post.add_notifications([post_wall.parent,
                                request.user])  # add to and from

    new_comment.send_notif(
    )  # Send notifs now, as all notif personnel are added

    # Render the new comment
    local_context = {'comment': new_comment, 'post': post}
    append_string = render_to_string('modules/comment.html',
                                     local_context,
                                     context_instance=global_context(
                                         request, token_info=False))

    local_context = {'append_string': append_string, 'post_id': post_id}
    return json.dumps(local_context)
Esempio n. 3
0
def create_post(request, wall_id, post_form):
    """
        Create a new wall post
    """
    # Initial validations
    try:
        wall_id = int(wall_id)
    except ValueError:
        wall_id = None
    
    if not ( type(wall_id) is int ):
        raise InvalidArgumentTypeException("argument `wall_id` should be of type integer")
    wall = get_object_or_404(Wall, id=int(wall_id))

    # create a new post
    append_string = ""
    data = deserialize_form(post_form)
   
    post_text = data["new_post"]
    
    post_subject = data.get("new_post_subject", "")
    post_text, notification_list = parse_atwho(post_text)
    rendered_post_text = Template(
        '''
            {%load markdown_tags%}
            {%autoescape off%}
                {{ post_text|markdown }}
            {%endautoescape%}
        '''
    ).render(RequestContext(request, { 
        'post_text' : post_text
    }))
    new_post = Post.objects.create(subject=post_subject, description=rendered_post_text, wall=wall, by=request.user)

    if( hasattr( wall, 'person' ) ):
        new_post.access_specifier = POST_TYPE['PUBLIC']
    else:
        new_post.access_specifier = POST_TYPE['PRIVATE_AND_TAGGED']

    new_post.add_notifications(notification_list)
    if wall.parent:
        new_post.add_notifications([wall.parent, request.user]) # add to and from

    new_post.send_notif()
    
    # Render the new post
    append_string =  render_to_string('modules/post.html', {'post': new_post}, context_instance=global_context(request, token_info=False)) + "<hr />"
    
    return json.dumps({ 'append_string': append_string })
Esempio n. 4
0
def create_post(request, wall_id, post_form):
    """
        Create a new wall post
    """
    # Initial validations
    try:
        wall_id = int(wall_id)
    except ValueError:
        wall_id = None

    if not (type(wall_id) is int):
        raise InvalidArgumentTypeException(
            "argument `wall_id` should be of type integer")
    wall = get_object_or_404(Wall, id=int(wall_id))

    # create a new post
    append_string = ""
    data = deserialize_form(post_form)

    post_text = data["new_post"]

    post_subject = data.get("new_post_subject", "")
    post_text, notification_list = parse_atwho(post_text)
    rendered_post_text = Template('''
            {%load markdown_tags%}
            {%autoescape off%}
                {{ post_text|markdown }}
            {%endautoescape%}
        ''').render(RequestContext(request, {'post_text': post_text}))
    new_post = Post.objects.create(subject=post_subject,
                                   description=rendered_post_text,
                                   wall=wall,
                                   by=request.user)

    new_post.add_notifications(notification_list)
    if wall.parent:
        new_post.add_notifications([wall.parent,
                                    request.user])  # add to and from

    new_post.send_notif()

    # Render the new post
    append_string = render_to_string('modules/post.html', {'post': new_post},
                                     context_instance=global_context(
                                         request, token_info=False)) + "<hr />"

    return json.dumps({'append_string': append_string})
Esempio n. 5
0
def quick_post(request, post_form):
    """
        Create a new wall post
    """
    # create a new post
    append_string = ""
    data = deserialize_form(post_form)
    post_subject = data.get("new_post_subject", "")
    post_text = data["quick_post"]
    post_text, notification_list = parse_atwho(post_text)

    # Figure out where to create post !
    to_list = data.getlist("quick_post_to")
    for i in to_list:
        obj = get_tag_object(i)
        if isinstance(obj, Dept) or isinstance(obj, Subdept) or isinstance(
                obj, Post):
            obj_wall = obj.wall
        else:
            obj_wall = obj.erp_profile.wall

        rendered_post_text = Template('''
                {%load markdown_tags%}
                {%autoescape off%}
                    {{ post_text|markdown }}
                {%endautoescape%}
            ''').render(RequestContext(request, {'post_text': post_text}))

        new_post = Post.objects.create(description=rendered_post_text,
                                       wall=obj_wall,
                                       by=request.user)
        new_post.add_notifications(notification_list)
        if obj_wall.parent:
            new_post.add_notifications([obj_wall.parent,
                                        request.user])  # add to and from

        new_post.send_notif()
    # Render the new post
    append_string = render_to_string('modules/post.html', {'post': new_post},
                                     context_instance=global_context(
                                         request, token_info=False)) + "<hr />"
    return json.dumps({'append_string': append_string})
Esempio n. 6
0
def quick_post(request, post_form):
    """
        Create a new wall post
    """
    # create a new post
    append_string = ""
    data = deserialize_form(post_form)
    post_subject = data.get("new_post_subject", "")
    post_text = data["quick_post"]
    post_text, notification_list = parse_atwho(post_text)

    # Figure out where to create post !
    to_list = data.getlist("quick_post_to")
    for i in to_list:
        obj = get_tag_object(i)
        if isinstance(obj, Dept) or isinstance(obj, Subdept) or isinstance(obj, Post):
            obj_wall =  obj.wall
        else:
            obj_wall =  obj.erp_profile.wall
    
        rendered_post_text = Template(
           '''
                {%load markdown_tags%}
                {%autoescape off%}
                    {{ post_text|markdown }}
                {%endautoescape%}
            '''
        ).render(RequestContext(request, { 
            'post_text' : post_text
        }))
 
        new_post = Post.objects.create(description=rendered_post_text, wall=obj_wall, by=request.user)
        new_post.add_notifications(notification_list)
        if obj_wall.parent:
            new_post.add_notifications([obj_wall.parent, request.user]) # add to and from

        new_post.send_notif()
    # Render the new post
    append_string =  render_to_string('modules/post.html', {'post': new_post}, context_instance=global_context(request, token_info=False)) + "<hr />"
    return json.dumps({ 'append_string': append_string })