Changeset f116422


Ignore:
Timestamp:
05/29/11 23:06:01 (2 years ago)
Author:
Pall Sigurdsson <palli@…>
Branches:
master
Children:
69e8ce1
Parents:
582de6e
git-author:
Pall Sigurdsson <palli@…> (05/29/11 23:06:01)
git-committer:
Pall Sigurdsson <palli@…> (05/29/11 23:06:01)
Message:

Refactoring and bugfixes.

Location:
adagios
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • adagios/objectbrowser/urls.py

    r582de6e rf116422  
    33 
    44urlpatterns = patterns('', 
    5     # Example: 
    6     #(r'^/', 'objectbrowser.views.index'), 
    7     #(r'^/host', 'objectbrowser.views.list_hosts'), 
    8     #(r'^/host/(?P<host_name>.+)$', 'objectbrowser.views.get_host'), 
    9      
    10     #(r'/contact/+$', 'objectbrowser.views.list_contacts'), 
    115    (r'/id=(?P<object_id>.+)$', 'objectbrowser.views.view_object'), 
     6 
    127    (r'/(?P<attribute_name>.+)=(?P<attribute_value>.+?)/(?P<attribute2_name>.+)=(?P<attribute2_value>.+?)/(?P<attribute3_name>.+)=(?P<attribute3_value>.+?)/?$', 'objectbrowser.views.list_objects'), 
    13     #(r'/(?P<attribute_name>.+)=(?P<attribute_value>.+?)$', 'objectbrowser.views.list_objects'), 
    14     (r'/(?P<attribute_name>.+)=(?P<attribute_value>.+?)/(?P<attribute2_name>.+)=(?P<attribute2_value>.+?)$', 'objectbrowser.views.list_objects'), 
     8    (r'/(?P<attribute_name>.+)=(?P<attribute_value>.+?)/(?P<attribute2_name>.+)=(?P<attribute2_value>.+?)/?$', 'objectbrowser.views.list_objects'), 
    159    (r'/(?P<attribute_name>.+)=(?P<attribute_value>.+?)/?$', 'objectbrowser.views.list_objects'), 
    1610 
     11    # By default, lets just display a list of object_types available 
    1712    (r'/$', 'objectbrowser.views.list_object_types'), 
     13    #  
    1814    (r'/(?P<object_type>.+)/?$', 'objectbrowser.views.list_objects'), 
    1915     
  • adagios/objectbrowser/views.py

    r582de6e rf116422  
     1# -*- coding: utf-8 -*- 
     2# 
     3# Copyright 2010, Pall Sigurdsson <palli@opensource.is> 
     4# 
     5# This script is free software: you can redistribute it and/or modify 
     6# it under the terms of the GNU General Public License as published by 
     7# the Free Software Foundation, either version 3 of the License, or 
     8# (at your option) any later version. 
     9# 
     10# This script is distributed in the hope that it will be useful, 
     11# but WITHOUT ANY WARRANTY; without even the implied warranty of 
     12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     13# GNU General Public License for more details. 
     14# 
     15# You should have received a copy of the GNU General Public License 
     16# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     17 
    118from django.shortcuts import render_to_response, redirect 
    219from django.core import serializers 
     
    2037        return list_hosts(request) 
    2138 
     39## DEPRECATED for list_objects 
    2240def list_hosts(request): 
    2341        c = {} 
    2442        c['hosts'] = Host.objects.all 
    2543        return render_to_response('configurator/index.html', c) 
    26  
     44## Deprecated for list_objects 
    2745def list_contacts(request): 
    2846        c = {} 
     
    3654    c['objects'] = objects = [] 
    3755     
    38     if attribute_name=='object_type': 
    39         object_type=attribute_value 
     56    search = tmp = {} 
     57    if attribute_name != None: 
     58        search = {attribute_name:attribute_value} 
     59    if attribute2_name != None: 
     60        search[attribute2_name]=attribute2_value 
     61    if attribute3_name != None: 
     62        search[attribute3_name]=attribute3_value 
     63     
     64    for k,v in search.items(): 
     65        if k == 'object_type': 
     66            object_type = v 
     67        elif v == 'None': 
     68            search[k] = None 
    4069    # If a non-existent object_type is requested, lets display a warning 
    4170    if not Model.string_to_class.has_key(object_type): 
     
    4978        c['objects'] = myClass.objects.all 
    5079    else: 
    51         if attribute_name != None: 
    52             tmp = {attribute_name:attribute_value} 
    53         if attribute2_name != None: 
    54             tmp[attribute2_name]=attribute2_value 
    55         if attribute3_name != None: 
    56             tmp[attribute3_name]=attribute3_value 
    57  
    58         c['objects'] = myClass.objects.filter(**tmp) 
    59         m.append("I used the filter %s=%s" % (tmp.keys(), tmp.values())) 
     80        c['objects'] = myClass.objects.filter(**search) 
     81        m.append("I used the filter %s=%s" % (search.keys(), search.values())) 
    6082    m.append( "Found %s objects of type %s" % (len(c['objects']), object_type)) 
    6183    return render_to_response('objectbrowser/list_objects.html', c) 
     
    6486    c = {} 
    6587    c['object_types'] = t = [] 
    66     for i in Model.string_to_class.keys(): 
    67         t.append( i ) 
     88    for name,Class in Model.string_to_class.items(): 
     89        if name != None: 
     90            active = inactive = 0 
     91            all_instances = Class.objects.all 
     92            for i in all_instances: 
     93                if i['register'] == "0": 
     94                    inactive += 1 
     95                else: 
     96                    active += 1 
     97            c['object_types'].append( (name, active, inactive) ) 
    6898    return render_to_response('objectbrowser/list_object_types.html', c) 
    6999 
     
    72102    c['messages'] = m = [] 
    73103    o = ObjectDefinition.objects.filter(id=object_id)[0] 
     104    #o = ObjectDefinition.objects.get_by_id(id=object_id) 
    74105    c['my_object'] = o 
    75106    c['attr_val'] = o.get_attribute_tuple() 
    76107    return render_to_response('objectbrowser/view_object.html', c) 
    77108 
    78 def get_services_without_service_description(self): 
    79     c = {} 
    80     s = Service.objects.filter(register=1, service_description=None) 
    81     return render_to_response('objectbrowser/list_objects.html', c) 
    82  
    83 def get_services_without_host_name(self): 
    84     c = {} 
    85     s = Service.objects.filter(register=1, host_name=None) 
    86     return render_to_response('objectbrowser/list_objects.html', c) 
    87109 
    88110 
  • adagios/templates/configurator/base.html

    r582de6e rf116422  
    3838        Cool Searches: 
    3939        <ul> 
    40                         <li><a href="/objectbrowser/">Services With no service_description</a></li> 
    41                 <li><a href="/objectbrowser/host">Services With no host_name</a></li> 
     40                        <li><a href="/objectbrowser/object_type=service/register=1/service_description=None">Services With no service_description</a></li> 
     41                <li><a href="/objectbrowser/object_type=service/register=1/host_name=None">Services With no host_name</a></li> 
    4242                        <li><a href="/objectbrowser/contact">Services that are not okconfig compatible</a></li> 
    4343        </ul> 
Note: See TracChangeset for help on using the changeset viewer.