Esempio n. 1
0
def add_extended_wallitem(wall,
                          author,
                          created_at=None,
                          template_name='default.html',
                          extra_context={}):

    # Default context variables for the wallitem
    context = Context({
        "wall": wall,
        "author": author,
    })

    context.update(extra_context)

    body = render_to_string('wallextend/%s' % template_name, context)

    try:
        # Create the standard WallItem
        wi = WallItem(wall=wall, body=body, author=author)
        if created_at:
            wi.created_at = created_at
        wi.save()
    except:
        pass
    else:
        #Success now create the extended item
        WallItemExtend(wallitem=wi, is_safe=True).save()
Esempio n. 2
0
def add(request, slug, form_class=WallItemForm,
            template_name='wall/home.html',
            success_url=None, can_add_check=None):
    """
    A view for adding a new WallItem.

    The optional 'can_add_check' callback passes you a user and a wall.
      Return True if the user is authorized and False otherwise.
      (Default: any user can create a wall item for the given wall.)
    """
    wall = get_object_or_404( Wall, slug=slug )
    if success_url == None:
        success_url = reverse( 'wall_home', args=(slug,))
    if request.method == 'POST':
        form = form_class(request.POST,request.FILES)
        if form.is_valid():
            posting = form.cleaned_data['posting']
            
            
            if (wall.max_item_length) and (len(posting) > wall.max_item_length):
                body = posting[:wall.max_item_length]
            else:
                body = posting
                
            body = sanitize(body)
            item = WallItem( author=request.user, wall=wall, body=body, created_at=datetime.now() )
            item.save()
            
            if request.FILES:
                file_content = request.FILES['img']
                item.item_pic.save(file_content.name, file_content, save=True)
            
            return HttpResponseRedirect(success_url)
        else:
            print 'errors'
            print form.errors
    else:
        form = form_class( help_text="Input text for a new item.<br/>(HTML tags will %sbe ignored. The item will be trimmed to %d characters.)" % ("not " if wall.allow_html else "", wall.max_item_length))
    return render_to_response(template_name,
        { 'form': form, 'wall': wall },
        context_instance = RequestContext( request ))
Esempio n. 3
0
def add( request, slug, form_class=WallItemForm,
            template_name='wall/add.html',
            success_url=None, can_add_check=None):
    """
    A view for adding a new WallItem.

    The optional 'can_add_check' callback passes you a user and a wall.
      Return True if the user is authorized and False otherwise.
      (Default: any user can create a wall item for the given wall.)
    """
    wall = get_object_or_404( Wall, slug=slug )
    if success_url == None:
        success_url = reverse( 'wall_home', args=(slug,))
    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            posting = form.cleaned_data['posting']
            if len(posting) > wall.max_item_length:
                body = posting[:wall.max_item_length]
            else:
                body = posting
            item = WallItem( author=request.user, wall=wall, body=body )
            item.save()
            return HttpResponseRedirect(success_url)
    else:
        if can_add_check != None:
            allowed = can_add_check( request.user, wall )
        else:
            allowed = True
        if not allowed:
            request.user.message_set.create(
                message='You do not have permission to add an item to this wall.')
            return HttpResponseRedirect(success_url)
        form = form_class( help_text="Input text for a new item.<br/>(HTML tags will %sbe ignored. The item will be trimmed to %d characters.)" % ("not " if wall.allow_html else "", wall.max_item_length))
    return render_to_response(template_name,
        { 'form': form, 'wall': wall },
        context_instance = RequestContext( request ))
Esempio n. 4
0
def add_extended_wallitem( wall, author, created_at=None, template_name='default.html', extra_context={}):


        # Default context variables for the wallitem
        context = Context({
            "wall": wall,
            "author": author,
        })
        
        context.update(extra_context)

        body = render_to_string('wallextend/%s' % template_name, context) 
        
        try:
            # Create the standard WallItem
            wi = WallItem(wall=wall,body=body, author=author)
            if created_at:
                wi.created_at = created_at
            wi.save()
        except:
            pass
        else:
            #Success now create the extended item
            WallItemExtend(wallitem=wi,is_safe=True).save()