コード例 #1
0
ファイル: views.py プロジェクト: kolabria/WikiWall-app
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():
#        ipdb.set_trace()
        # 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
ファイル: views.py プロジェクト: kolabria/WikiWall-app
def publish(request, wid):
    pub_wall = Wall.objects.get(id=wid)
    pub_form = PubWallForm(request.POST or None)

    if  pub_form.is_valid():
        messages.info(request, 'original published: %s' % pub_wall.published )
        publish = request.POST.getlist('publish')
        pub_wall.published = publish
        pub_wall.save()
        messages.info(request, 'updated published: %s'  % publish)

        #TODO Fix box updating logic, update > link on template to view that will
        #     process POST request
        #        boxes = Box.objects.filter(id=published)
        #        box.walls.append(published)
        #        box.save()

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

    messages.error(request, 'error: no valid POST data found')
    return HttpResponseRedirect('/walls/update/%s' % wid)