Beispiel #1
0
 def get_node_details(data):
     try:
         client = data['client']
         pk = data['pk']
         n_type = data['node_type']
         clnt = OrgClient.get_client(client)
         obj = None
         sel = {'client': clnt, 'del_ind': False}
         if n_type != "":
             # Get the node
             node = Node.get_node(client, pk)
             node_type = node.node_type.node_type
             if node_type == 'ROOTNODE' or node_type == 'NODE':
                 return []
             elif node_type == "CC":
                 obj = OrgCompanies
                 sel['company_id'] = node.map_id
             elif node_type == "P_ORG":
                 obj = OrgPorg
                 sel['porg_id'] = node.map_id
             elif node_type == "P_GROUP":
                 obj = OrgPGroup
                 sel['pgroup_id'] = node.map_id
             node_det = get_object_or_404(obj, **sel)
             return [node_det]
         else:
             # Get the user
             sel['pk'] = pk
             user = get_object_or_404(OrgUsers, **sel)
             return [user]
     except KeyError:
         return ['{"error": "Invalid inputs found"}']
Beispiel #2
0
 def get_node(client_id, guid):
     try:
         client = OrgClient.get_client(client_id)
         node = get_object_or_404(OrgModel,
                                  client=client,
                                  node=guid,
                                  del_ind=False)
         return node
     except:
         return '{"error": "No node found"}'
 def get_all_org(client_id):
     """
     Get all the organization for client
     :param client_id: client which org belongs to
     :return: Queryset containing org list
     """
     client = OrgClient.get_client(client_id)
     orgs = OrgNames.objects.filter(client=client, del_ind=False)
     if orgs.count() == 0:
         return ['{"info": "No organizations found"}']
     return orgs
Beispiel #4
0
 def get_children(client_id, guid):
     try:
         client = OrgClient.get_client(client_id)
         node = OrgModel.objects.filter(client=client,
                                        parent_node=guid,
                                        del_ind=False)
         if node.exists():
             return node
         else:
             return ['{"error": "No children found"}']
     except:
         return ['{"error": "no valid input"}']
Beispiel #5
0
 def modify_node_details(data):
     try:
         client = data['client']
         pk = data['pk']
         n_type = data['node_type']
         clnt = OrgClient.get_client(client)
         obj = None
         sel = {'client': clnt, 'del_ind': False}
         inp = {'client': clnt}
         if n_type != "":
             # Get the node
             node = Node.get_node(client, pk)
             node_type = node.node_type.node_type
             if node_type == 'ROOTNODE' or node_type == 'NODE':
                 return []
             elif node_type == "CC":
                 obj = OrgCompanies
                 sel['company_id'] = node.map_id
                 inp['name1'] = data['name1']
                 inp['name2'] = data['name2']
             elif node_type == "P_ORG":
                 obj = OrgPorg
                 sel['porg_id'] = node.map_id
                 inp['description'] = data['description']
             elif node_type == "P_ORG":
                 obj = OrgPGroup
                 sel['pgroup_id'] = node.map_id
                 inp['description'] = data['description']
             try:
                 node_det = obj.objects.filter(**sel).update(**inp)
                 return [node_det]
             except obj.DoesNotExist:
                 node_det = obj()
                 node_det.objects.modify(**inp)
                 node_det.save()
                 return [node_det]
         else:
             # Get the user
             sel['pk'] = pk
             user = get_object_or_404(OrgUsers, **sel)
             inp['name1'] = data['name1']
             inp['name2'] = data['name2']
             user.objects.modify(**inp)
             return [user]
             pass
     except KeyError:
         return ['{"error": "Invalid inputs found"}']
Beispiel #6
0
 def __init__(self, klass, client_id, pk):
     """
     Initialization of utility
     :param klass: Name of the class
     :param client_id: Client
     :param pk: Primary key
     """
     client = OrgClient.get_client(client_id)
     if pk is None:
         self.base = klass()
         self.base.client = client
     else:
         self.base = get_object_or_404(klass,
                                       client=client,
                                       pk=pk,
                                       del_ind=False)
     self.error = False
     self.message = {}
Beispiel #7
0
 def get_node_basic_data(data):
     """
     Handles basic data tab details
     :param data: Node data
     :return: Response object/message
     """
     try:
         client = data['client']
         pk = data['pk']
         node_type = data['node_type']
         clnt = OrgClient.get_client(client)
         temp = {'client': clnt, 'del_ind': False}
         if node_type != "" and node_type is not None:
             node = Node.get_node(client, pk)
             obj = OrgModel
             temp['map_id'] = node.map_id
             node_detail = get_object_or_404(obj, **temp)
             return [node_detail]
         else:
             temp['pk'] = pk
             user = get_object_or_404(OrgUsers, **temp)
             return [user]
     except KeyError:
         return ['{"error": "Invalid inputs found"}']
Beispiel #8
0
 def get_node_types(client_id):
     client = OrgClient.get_client(client_id)
     return OrgNodeTypes.objects.filter(~Q(node_type='ROOTNODE'),
                                        client=client)
 def get_org_by_rootnode(client_id, guid):
     client = OrgClient.get_client(client_id)
     return get_object_or_404(OrgNames, client=client, root_node=guid, del_ind=False)