Ejemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        user = self.request.user
        form = UpdateForm(self.request.POST)

        if not form.is_valid():
            return render_to_response('403.html', {},
                                      context_instance=RequestContext(request))

        requests_to_modify = form.cleaned_data['requests_to_modify']
        for obj in requests_to_modify:
            can_edit = user.has_perm(Request.get_permission_name('edit'), obj)
            if not can_edit:
                # Chicanery?
                return render_to_response(
                    '403.html', {}, context_instance=RequestContext(request))
            if form.cleaned_data['newduedate']:
                obj.due_date = form.cleaned_data['newduedate']
            if form.cleaned_data['newsubject']:
                obj.title = form.cleaned_data['newsubject']
            if form.cleaned_data['newupdateddate']:
                obj.date_updated = form.cleaned_data['newupdateddate']
            if form.cleaned_data['newfulfilleddate']:
                obj.date_fulfilled = form.cleaned_data['newfulfilleddate']
            if form.cleaned_data['newstatus']:
                #allow requests to be set even if they aren't sent because not all requests can be emailed
                obj.set_status(form.cleaned_data['newstatus'])
                if obj.status != 'F' and obj.status != 'P':
                    obj.date_fulfilled = None
                elif obj.status == 'F' or obj.status == 'P' and form.cleaned_data[
                        'newfulfilleddate']:
                    obj.date_fulfilled = form.cleaned_data['newfulfilleddate']
                elif obj.status == 'F' or obj.status == 'P' and not form.cleaned_data[
                        'newfulfilleddate']:
                    obj.date_fulfilled = datetime.now(tz=pytz.utc)
                else:
                    obj.date_fulfilled = None
            if form.cleaned_data['addgroups']:
                editperm = Request.get_permissions_path('edit')
                viewperm = Request.get_permissions_path('view')
                for group in form.cleaned_data['addgroups']:
                    assign_perm(editperm, group, obj)
                    assign_perm(viewperm, group, obj)
            if form.cleaned_data['removegroups']:
                for group in form.cleaned_data['removegroups']:
                    # Can't remove the author of the request
                    if group.name != obj.author.username:
                        remove_perm('edit_this_request', group, obj)

            action = form.cleaned_data['action']
            if action == "Make Public":
                obj.private = False
            if action == "Make Private":
                obj.private = True

            obj.save()

        return self.get(request, *args, **kwargs)
Ejemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        user = self.request.user
        form = UpdateForm(self.request.POST)

        if not form.is_valid():
            return render_to_response('403.html', {}, context_instance=RequestContext(request))

        requests_to_modify = form.cleaned_data['requests_to_modify']
        for obj in requests_to_modify:
            can_edit = user.has_perm(Request.get_permission_name('edit'), obj)
            if not can_edit:
                # Chicanery? 
                return render_to_response('403.html', {}, context_instance=RequestContext(request))
            if form.cleaned_data['newduedate']:
                obj.due_date = form.cleaned_data['newduedate']
            if form.cleaned_data['newsubject']:
                obj.title = form.cleaned_data['newsubject']
            if form.cleaned_data['newupdateddate']:
                obj.date_updated = form.cleaned_data['newupdateddate']
            if form.cleaned_data['newfulfilleddate']:
                obj.date_fulfilled = form.cleaned_data['newfulfilleddate']
            if form.cleaned_data['newstatus']:
                #allow requests to be set even if they aren't sent because not all requests can be emailed
                obj.set_status(form.cleaned_data['newstatus'])
                if obj.status != 'F' and obj.status != 'P':
                    obj.date_fulfilled = None
                elif obj.status == 'F' or obj.status == 'P' and form.cleaned_data['newfulfilleddate']:
                    obj.date_fulfilled = form.cleaned_data['newfulfilleddate']
                elif obj.status == 'F' or obj.status == 'P' and not form.cleaned_data['newfulfilleddate']:
                    obj.date_fulfilled = datetime.now(tz=pytz.utc)
                else:
                    obj.date_fulfilled = None
            if form.cleaned_data['addgroups']:
                editperm = Request.get_permissions_path('edit')
                viewperm = Request.get_permissions_path('view')
                for group in form.cleaned_data['addgroups']:
                    assign_perm(editperm, group, obj)
                    assign_perm(viewperm, group, obj)
            if form.cleaned_data['removegroups']:
                for group in form.cleaned_data['removegroups']:
                    # Can't remove the author of the request
                    if group.name != obj.author.username:
                        remove_perm('edit_this_request', group, obj)

            action = form.cleaned_data['action']
            if action == "Make Public":
                obj.private = False
            if action == "Make Private":
                obj.private = True

            obj.save()
            
        return self.get(request, *args, **kwargs)
Ejemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        """ 
        Lets user edit settings on posts
        """

        user = self.request.user
        form = UpdateForm(self.request.POST)

        if not form.is_valid():
            return render_to_response('403.html', {},
                                      context_instance=RequestContext(request))

        requests_to_modify = form.cleaned_data['requests_to_modify']
        action = form.cleaned_data['action']

        for obj in requests_to_modify:
            can_edit = user.has_perm(Request.get_permission_name('edit'), obj)
            if not can_edit:
                # Chicanery?
                return render_to_response(
                    '403.html', {}, context_instance=RequestContext(request))

            if action == "Make Public":
                obj.private = False
            elif action == "Make Private":
                obj.private = True
            elif action == "Delete":
                obj.status = 'X'
            else:
                obj.status = form.cleaned_data['newstatus']
                if obj.status != 'F' and obj.status != 'P':
                    obj.date_fulfilled = None
                elif obj.status == 'F' or obj.status == 'P':
                    obj.date_fulfilled = datetime.now()

                #groups = form.cleaned_data['groups']
            obj.save()

        # Now use the get handler to reapply the filters
        # and pagination
        return self.get(request, *args, **kwargs)
Ejemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        """ 
        Lets user edit settings on posts
        """

        user = self.request.user
        form = UpdateForm(self.request.POST)

        if not form.is_valid():
            return render_to_response('403.html', {}, context_instance=RequestContext(request))
            
        requests_to_modify = form.cleaned_data['requests_to_modify']
        action = form.cleaned_data['action']


        for obj in requests_to_modify:
            can_edit = user.has_perm(Request.get_permission_name('edit'), obj)
            if not can_edit:
                # Chicanery? 
                return render_to_response('403.html', {}, context_instance=RequestContext(request))

            if action == "Make Public":
                obj.private = False
            elif action == "Make Private":
                obj.private = True
            elif action == "Delete":
                obj.status = 'X'
            else:
                obj.status = form.cleaned_data['newstatus']
                if obj.status != 'F' and obj.status != 'P':
                    obj.date_fulfilled = None
                elif obj.status == 'F' or obj.status == 'P':
                    obj.date_fulfilled = datetime.now()

                #groups = form.cleaned_data['groups']
            obj.save()

        # Now use the get handler to reapply the filters
        # and pagination
        return self.get(request, *args, **kwargs)