def post(self, request, project_id, usergroup_id):
        """
        Updates the user group permissions based on the data entered by the
        user.

        Parameter
        ---------
        request : django.http.HttpRequest
            Object representing the request
        project_id : int
            Identifies the project in the database
        usergroup_id : int
            Identifies the user group in the database

        Returns
        -------
        django.http.HttpResponse
            Rendered template when user group updated
        django.http.HttpResponse
            Rendered template, if project or user group does not exist
        """

        data = request.POST
        context = self.get_context_data(project_id, usergroup_id)
        usergroup = context.get('usergroup')

        if usergroup:
            cannot_modify = 'User group permissions cannot be modified.'

            if usergroup.project.islocked:
                messages.error(
                    self.request,
                    'The project is locked. %s' % cannot_modify
                )
            else:
                usergroup.can_moderate = False
                usergroup.can_contribute = False

                if data['permission'] == 'can_moderate':
                    usergroup.can_moderate = True
                elif data['permission'] == 'can_contribute':
                    usergroup.can_contribute = True

                usergroup.save()

                messages.success(
                    self.request,
                    'The user group has been updated.'
                )

        return self.render_to_response(context)
dataset/ETHPy150Open ExCiteS/geokey/geokey/users/views.py/UserGroupPermissions.post/original