Пример #1
0
def update(request, wid):
    wall = Wall.objects.get(id=wid)
    boxids = wall.published
    boxes = [ Box.objects.get(id=str(boxid)) for boxid in boxids ]
        
    unpublish_form = UnpubWallForm()
    unpublish_form.initial['published'] = wall.published

    unshare_form = UnshareWallForm()
    unshare_form.initial['unshared'] = True

    pub_form = PubWallForm()
    pub_form.fields['publish'].label = 'Available Appliances'
    pub_form.initial['publish'] = wall.published

    unpub_form = UnpubWallForm()

    update_form = UpdateWallForm(request.POST or None)
    update_form.initial['name'] = wall.name
    update_form.fields['name'].label = 'Update WikiWall Name'
    update_form.fields['invited'].label = 'Invite new users by email address'

    if update_form.is_valid():
        # process invited if detected in POST
        if request.POST.get('invited'): 
            invited = request.POST.get('invited')
            real = User.objects.get(email=invited)
            if real and invited not in wall.sharing:
                wall.sharing.append(invited)
                messages.info(request, 'invited: %s' % invited)
                wall.save()
            else:
                error_msg = 'Error: %s not valid or already invited.' % invited
                messages.warning(request, error_msg)

        # update wall.name if name in POST different from model
        old_name = wall.name
        wall.name = request.POST['name']  # update wall name
        if old_name != wall.name:
            wall.save()
            update_msg = 'Updated WikiWall name to: %s. (old name: %s)' % (wall.name, old_name)
            messages.success(request, update_msg)
        else:
            update_msg = 'No changes detected. Not Updating %s' % wall.name

        return HttpResponseRedirect('/walls/update/%s' % wid)

       # then update records and publish to selected box.walls 
       # update wall.published with boxes (bids)
    data = {'title': 'Kolabria - Edit Board Details', 
            'wall': wall,
            'boxes': boxes,
            'pub_form': pub_form,
            'update_form': update_form,
            'unshare_form': unshare_form,
            'unpub_form': unpub_form, }

    return render_to_response('walls/update.html', data,
                              context_instance=RequestContext(request))
Пример #2
0
def unpublish(request, wid):
    wall = Wall.objects.get(id=wid)
 
    update_form = UpdateWallForm()
    update_form.initial['name'] = wall.name
    update_form.fields['name'].label = 'Update WikiWall Name'
    update_form.fields['invited'].label = 'Invite new users by email address'
    
    unpub_form = UnpubWallForm(request.POST or None)
   
    if unpub_form.is_valid():
        box_id = request.POST.get('box_id')
        if box_id in wall.published:
           wall.published.remove(box_id)
           wall.save()
           box = Box.objects.get(id=box_id)
           wall_unpub_msg = 'Publishing Updated - ' 
           wall_unpub_msg += 'wall.name: %s unpublished from  ' % wall.name
           wall_unpub_msg += '|  box.name: %s' % box.name
           messages.success(request, wall_unpub_msg)
        
        box = Box.objects.get(id=box_id)
        if box_id in box.walls:
            box.walls.remove(box_id)
            box.save()
            box_unpub_msg = 'Box Updated Successfully - '
            box_unpub_msg += 'wall.name: %s removed ' % wall.name
            box_unpub_msg += 'from box.published for %s' % box.name
            box.success(request, box_unpub_msg)

        return HttpResponseRedirect('/walls/update/%s' % wid)

    pub_form = PubWallForm(initial={'publish': wall.published})

    data = {'title': 'Kolabria - Unshare Wall with user',
            'wid': wid,
            'pub_form': pub_form,
            'update_form': update_form,
            'unpub_form': unpub_form, 
            'wall': wall,
            }
    return render_to_response('walls/update.html', data,
                              context_instance=RequestContext(request))