Commit 0cbec21a by Czémán Arnold

dashboard: add VmDescFilter and 'shared with me' search choice

parent 3cff165b
...@@ -1531,6 +1531,7 @@ class VmResourcesForm(forms.ModelForm): ...@@ -1531,6 +1531,7 @@ class VmResourcesForm(forms.ModelForm):
vm_search_choices = ( vm_search_choices = (
("owned", _("owned")), ("owned", _("owned")),
("shared", _("shared")), ("shared", _("shared")),
("shared_with_me", _("shared with me")),
("all", _("all")), ("all", _("all")),
) )
......
...@@ -46,6 +46,7 @@ from common.models import HumanReadableException, HumanReadableObject ...@@ -46,6 +46,7 @@ from common.models import HumanReadableException, HumanReadableObject
from ..models import GroupProfile, Profile from ..models import GroupProfile, Profile
from ..forms import TransferOwnershipForm from ..forms import TransferOwnershipForm
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
saml_available = hasattr(settings, "SAML_CONFIG") saml_available = hasattr(settings, "SAML_CONFIG")
...@@ -169,6 +170,26 @@ class FilterMixin(object): ...@@ -169,6 +170,26 @@ class FilterMixin(object):
return queryset return queryset
class VmDescFilterMixin(FilterMixin):
def create_acl_queryset(self, model):
cleaned_data = self.search_form.cleaned_data
stype = cleaned_data.get('stype', 'all')
queryset = super(VmDescFilterMixin, self).create_acl_queryset(model)
user = self.request.user
if stype == 'owned':
queryset = queryset.filter(owner=user)
elif stype == 'shared':
queryset = model.get_objects_with_level(
'owner', self.request.user)
pk_list = [record.pk for record in queryset
if record.object_level_set.count() > 1]
queryset = queryset.filter(pk__in=pk_list)
elif stype == 'shared_with_me':
queryset = queryset.exclude(owner=user)
return queryset
class CheckedDetailView(LoginRequiredMixin, DetailView): class CheckedDetailView(LoginRequiredMixin, DetailView):
read_level = 'user' read_level = 'user'
......
...@@ -56,7 +56,7 @@ from vm.models import ( ...@@ -56,7 +56,7 @@ from vm.models import (
) )
from .util import ( from .util import (
CheckedDetailView, AjaxOperationMixin, OperationView, AclUpdateView, CheckedDetailView, AjaxOperationMixin, OperationView, AclUpdateView,
FormOperationMixin, FilterMixin, GraphMixin, FormOperationMixin, VmDescFilterMixin, GraphMixin,
TransferOwnershipConfirmView, TransferOwnershipView, TransferOwnershipConfirmView, TransferOwnershipView,
) )
from ..forms import ( from ..forms import (
...@@ -921,7 +921,7 @@ vm_mass_ops = OrderedDict([ ...@@ -921,7 +921,7 @@ vm_mass_ops = OrderedDict([
]) ])
class VmList(LoginRequiredMixin, FilterMixin, ListView): class VmList(LoginRequiredMixin, VmDescFilterMixin, ListView):
template_name = "dashboard/vm-list.html" template_name = "dashboard/vm-list.html"
allowed_filters = { allowed_filters = {
'name': "name__icontains", 'name': "name__icontains",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment