Пример #1
0
 def get(self, *args, **kwargs):
     try:
         self.model_type_id = int(self.kwargs.get('type', ''))
     except ValueError:
         self.model_type_id = None
     try:
         self.group_id = int(self.kwargs.get('group', ''))
     except ValueError:
         self.group_id = None
         self.group = None
     else:
         self.group = get_object_or_404(ComponentModelGroup,
                                        id=self.group_id)
     if self.group:
         self.query = self.group.componentmodel_set.all()
     else:
         self.query = ComponentModel.objects.filter(
                 type=self.model_type_id).filter(group=None)
     self.unassigned_count = ComponentModel.objects.filter(
             type=self.model_type_id
         ).filter(
             group=None
         ).count()
     groups = list(ComponentModelGroup.objects.filter(
             type=self.model_type_id))
     for g in groups:
         g.count = g.get_count()
         g.modified_price = decimal.Decimal(
                 g.price or 0) / (g.size_modifier or 1)
     self.groups = groups
     if not self.form:
         self.form = ComponentModelGroupForm(instance=self.group)
     return super(CatalogComponent, self).get(*args, **kwargs)
Пример #2
0
 def get(self, *args, **kwargs):
     try:
         self.model_type_id = int(self.kwargs.get('type', ''))
     except ValueError:
         self.model_type_id = None
     try:
         self.group_id = int(self.kwargs.get('group', ''))
     except ValueError:
         self.group_id = None
         self.group = None
     else:
         self.group = get_object_or_404(ComponentModelGroup, id=self.group_id)
     if self.group:
         self.query = self.group.componentmodel_set.all()
     else:
         self.query = ComponentModel.objects.filter(
                 type=self.model_type_id).filter(group=None)
     self.unassigned_count = ComponentModel.objects.filter(
             type=self.model_type_id
         ).filter(
             group=None
         ).count()
     self.groups = ComponentModelGroup.objects.filter(type=self.model_type_id)
     if not self.form:
         self.form = ComponentModelGroupForm(instance=self.group)
     return super(CatalogComponent, self).get(*args, **kwargs)
Пример #3
0
 def post(self, *args, **kwargs):
     if not self.request.user.get_profile().has_perm(
             Perm.edit_device_info_financial):
         raise HttpResponseForbidden(
                 "You have no permission to edit catalog")
     if 'move' in self.request.POST:
         items = self.request.POST.getlist('items')
         if not items:
             messages.error(self.request, "Nothing to move.")
             return HttpResponseRedirect(self.request.path)
         target_id = self.request.POST.get('target', '')
         if target_id == 'none':
             target = None
         elif target_id == 'new':
             item = get_object_or_404(ComponentModel, id=items[0])
             target = ComponentModelGroup(name=item.name, type=item.type)
             target.save()
         else:
             target = get_object_or_404(ComponentModelGroup, id=target_id)
         for item in items:
             model = get_object_or_404(ComponentModel, id=item)
             model.group = target
             model.save()
         self.update_cached(target)
         messages.success(self.request, "Items moved.")
         return HttpResponseRedirect(self.request.path)
     elif 'delete' in self.request.POST:
         try:
             self.group_id = int(self.kwargs.get('group', ''))
         except ValueError:
             messages.error(self.request, "No such group.")
         else:
             self.group = get_object_or_404(ComponentModelGroup,
                                            id=self.group_id)
             self.group.price = 0
             self.group.save()
             self.update_cached(self.group)
             self.group.delete()
             messages.warning(self.request,
                              "Group '%s' deleted." % self.group.name)
         return HttpResponseRedirect(self.request.path+'..')
     else:
         try:
             self.group_id = int(self.kwargs.get('group', ''))
         except ValueError:
             self.group_id = None
             self.group = None
         else:
             self.group = get_object_or_404(ComponentModelGroup,
                                            id=self.group_id)
         self.form = ComponentModelGroupForm(self.request.POST,
                                             instance=self.group)
         if self.form.is_valid():
             self.form.save()
             self.update_cached(self.group)
             messages.success(self.request, "Changes saved.")
             return HttpResponseRedirect(self.request.path)
         else:
             messages.error(self.request, "Correct the errors.")
     return self.get(*args, **kwargs)
Пример #4
0
 def post(self, *args, **kwargs):
     if not self.request.user.get_profile().has_perm(
             Perm.edit_device_info_financial):
         raise HttpResponseForbidden(
                 "You have no permission to edit catalog")
     if 'move' in self.request.POST:
         items = self.request.POST.getlist('items')
         if not items:
             messages.error(self.request, "Nothing to move.")
             return HttpResponseRedirect(self.request.path)
         target_id = self.request.POST.get('target', '')
         if target_id == 'none':
             target = None
         elif target_id == 'new':
             item = get_object_or_404(ComponentModel, id=items[0])
             target = ComponentModelGroup(name=item.name, type=item.type)
             target.save(user=self.request.user)
         else:
             target = get_object_or_404(ComponentModelGroup, id=target_id)
         for item in items:
             model = get_object_or_404(ComponentModel, id=item)
             model.group = target
             model.save(user=self.request.user)
         self.update_cached(target)
         messages.success(self.request, "Items moved.")
         return HttpResponseRedirect(self.request.path)
     elif 'delete' in self.request.POST:
         try:
             self.group_id = int(self.kwargs.get('group', ''))
         except ValueError:
             messages.error(self.request, "No such group.")
         else:
             self.group = get_object_or_404(ComponentModelGroup,
                                            id=self.group_id)
             self.group.price = 0
             self.group.save(user=self.request.user)
             self.update_cached(self.group)
             self.group.delete()
             messages.warning(self.request,
                              "Group '%s' deleted." % self.group.name)
         return HttpResponseRedirect(self.request.path+'..')
     else:
         try:
             self.group_id = int(self.kwargs.get('group', ''))
         except ValueError:
             self.group_id = None
             self.group = None
         else:
             self.group = get_object_or_404(ComponentModelGroup,
                                            id=self.group_id)
         self.form = ComponentModelGroupForm(self.request.POST,
                                             instance=self.group)
         if self.form.is_valid():
             self.form.save(commit=False)
             self.form.instance.save(user=self.request.user)
             self.update_cached(self.group)
             messages.success(self.request, "Changes saved.")
             return HttpResponseRedirect(self.request.path)
         else:
             messages.error(self.request, "Correct the errors.")
     return self.get(*args, **kwargs)
Пример #5
0
class CatalogComponent(Catalog):
    template_name = 'ui/catalog-component.html'

    def __init__(self, *args, **kwargs):
        super(CatalogComponent, self).__init__(*args, **kwargs)
        self.form = None

    def update_cached(self, group):
        devices = set()
        for _class in (Storage, Memory, Processor, DiskShare, FibreChannel,
                       GenericComponent, OperatingSystem, Software):
            for component in _class.objects.filter(model__group=group):
                devices.add(component.device)
        for device in devices:
            pricing.device_update_cached(device)

    def post(self, *args, **kwargs):
        if not self.request.user.get_profile().has_perm(
                Perm.edit_device_info_financial):
            raise HttpResponseForbidden(
                    "You have no permission to edit catalog")
        if 'move' in self.request.POST:
            items = self.request.POST.getlist('items')
            if not items:
                messages.error(self.request, "Nothing to move.")
                return HttpResponseRedirect(self.request.path)
            target_id = self.request.POST.get('target', '')
            if target_id == 'none':
                target = None
            elif target_id == 'new':
                item = get_object_or_404(ComponentModel, id=items[0])
                target = ComponentModelGroup(name=item.name, type=item.type)
                target.save(user=self.request.user)
            else:
                target = get_object_or_404(ComponentModelGroup, id=target_id)
            for item in items:
                model = get_object_or_404(ComponentModel, id=item)
                model.group = target
                model.save(user=self.request.user)
            self.update_cached(target)
            messages.success(self.request, "Items moved.")
            return HttpResponseRedirect(self.request.path)
        elif 'delete' in self.request.POST:
            try:
                self.group_id = int(self.kwargs.get('group', ''))
            except ValueError:
                messages.error(self.request, "No such group.")
            else:
                self.group = get_object_or_404(ComponentModelGroup,
                                               id=self.group_id)
                self.group.price = 0
                self.group.save(user=self.request.user)
                self.update_cached(self.group)
                self.group.delete()
                messages.warning(self.request,
                                 "Group '%s' deleted." % self.group.name)
            return HttpResponseRedirect(self.request.path+'..')
        else:
            try:
                self.group_id = int(self.kwargs.get('group', ''))
            except ValueError:
                self.group_id = None
                self.group = None
            else:
                self.group = get_object_or_404(ComponentModelGroup,
                                               id=self.group_id)
            self.form = ComponentModelGroupForm(self.request.POST,
                                                instance=self.group)
            if self.form.is_valid():
                self.form.save(commit=False)
                self.form.instance.save(user=self.request.user)
                self.update_cached(self.group)
                messages.success(self.request, "Changes saved.")
                return HttpResponseRedirect(self.request.path)
            else:
                messages.error(self.request, "Correct the errors.")
        return self.get(*args, **kwargs)


    def get(self, *args, **kwargs):
        try:
            self.model_type_id = int(self.kwargs.get('type', ''))
        except ValueError:
            self.model_type_id = None
        try:
            self.group_id = int(self.kwargs.get('group', ''))
        except ValueError:
            self.group_id = None
            self.group = None
        else:
            self.group = get_object_or_404(ComponentModelGroup,
                                           id=self.group_id)
        if self.group:
            self.query = self.group.componentmodel_set.all()
        else:
            self.query = ComponentModel.objects.filter(
                    type=self.model_type_id).filter(group=None)
        self.unassigned_count = ComponentModel.objects.filter(
                type=self.model_type_id
            ).filter(
                group=None
            ).count()
        groups = list(ComponentModelGroup.objects.filter(
                type=self.model_type_id))
        for g in groups:
            g.count = g.get_count()
            g.modified_price = decimal.Decimal(
                    g.price or 0) / (g.size_modifier or 1)
        self.groups = groups
        if not self.form:
            self.form = ComponentModelGroupForm(instance=self.group)
        return super(CatalogComponent, self).get(*args, **kwargs)

    def get_context_data(self, **kwargs):
        ret = super(CatalogComponent, self).get_context_data(**kwargs)
        ret.update({
            'columns': ['count'],
            'groups': self.groups,
            'group': self.group,
            'unassigned_count': self.unassigned_count,
            'form': self.form,
            'CURRENCY': settings.CURRENCY,
        })
        ret.update(_prepare_model_groups(self.request, self.query))
        return ret
Пример #6
0
class CatalogComponent(Catalog):
    template_name = 'ui/catalog-component.html'

    def __init__(self, *args, **kwargs):
        super(CatalogComponent, self).__init__(*args, **kwargs)
        self.form = None

    def post(self, *args, **kwargs):
        if not self.request.user.get_profile().has_perm(
                Perm.edit_device_info_financial):
            raise HttpResponseForbidden('You have no permission to edit catalog')
        if 'move' in self.request.POST:
            items = self.request.POST.getlist('items')
            if not items:
                messages.error(self.request, "Nothing to move.")
                return HttpResponseRedirect(self.request.path)
            target_id = self.request.POST.get('target', '')
            if target_id == 'none':
                target = None
            elif target_id == 'new':
                item = get_object_or_404(ComponentModel, id=items[0])
                target = ComponentModelGroup(name=item.name, type=item.type)
                target.save()
            else:
                target = get_object_or_404(ComponentModelGroup, id=target_id)
            for item in items:
                model = get_object_or_404(ComponentModel, id=item)
                model.group = target
                model.save()
            messages.success(self.request, "Items moved.")
            return HttpResponseRedirect(self.request.path)
        elif 'delete' in self.request.POST:
            try:
                self.group_id = int(self.kwargs.get('group', ''))
            except ValueError:
                messages.error(self.request, "No such group.")
            else:
                self.group = get_object_or_404(ComponentModelGroup, id=self.group_id)
                messages.warning(self.request, "Group '%s' deleted." % self.group.name)
                self.group.delete()
            return HttpResponseRedirect(self.request.path+'..')
        else:
            try:
                self.group_id = int(self.kwargs.get('group', ''))
            except ValueError:
                self.group_id = None
                self.group = None
            else:
                self.group = get_object_or_404(ComponentModelGroup, id=self.group_id)
            self.form = ComponentModelGroupForm(self.request.POST, instance=self.group)
            if self.form.is_valid():
                self.form.save()
                messages.success(self.request, "Changes saved.")
                return HttpResponseRedirect(self.request.path)
            else:
                messages.error(self.request, "Correct the errors.")
        return self.get(*args, **kwargs)


    def get(self, *args, **kwargs):
        try:
            self.model_type_id = int(self.kwargs.get('type', ''))
        except ValueError:
            self.model_type_id = None
        try:
            self.group_id = int(self.kwargs.get('group', ''))
        except ValueError:
            self.group_id = None
            self.group = None
        else:
            self.group = get_object_or_404(ComponentModelGroup, id=self.group_id)
        if self.group:
            self.query = self.group.componentmodel_set.all()
        else:
            self.query = ComponentModel.objects.filter(
                    type=self.model_type_id).filter(group=None)
        self.unassigned_count = ComponentModel.objects.filter(
                type=self.model_type_id
            ).filter(
                group=None
            ).count()
        self.groups = ComponentModelGroup.objects.filter(type=self.model_type_id)
        if not self.form:
            self.form = ComponentModelGroupForm(instance=self.group)
        return super(CatalogComponent, self).get(*args, **kwargs)

    def get_context_data(self, **kwargs):
        ret = super(CatalogComponent, self).get_context_data(**kwargs)
        ret.update({
            'columns': ['count'],
            'groups': self.groups,
            'group': self.group,
            'unassigned_count': self.unassigned_count,
            'form': self.form,
        })
        ret.update(_prepare_model_groups(self.request, self.query))
        return ret