Changeset 58641b0


Ignore:
Timestamp:
05/27/11 17:03:22 (2 years ago)
Author:
Pall Sigurdsson <palli@…>
Branches:
master
Children:
349a990, f87a326
Parents:
c0847d6
git-author:
Pall Sigurdsson <palli@…> (05/27/11 17:03:22)
git-committer:
Pall Sigurdsson <palli@…> (05/27/11 17:03:22)
Message:

objectbrowser commit at end of day

Location:
adagios
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • adagios/configurator/views.py

    r99e2774 r58641b0  
    3535        c['contacts'] = get_contacts() 
    3636        return render_to_response('configurator/list_contacts.html', c) 
    37  
    3837 
    3938def host(request, host_name=None): 
  • adagios/objectbrowser/urls.py

    rc5564f7 r58641b0  
    99     
    1010    #(r'/contact/+$', 'objectbrowser.views.list_contacts'), 
     11    (r'/(?P<object_type>.+)/(?P<attribute_name>.+)=(?P<attribute_value>.+)$', 'objectbrowser.views.view_objects'), 
     12    (r'/(?P<attribute_name>.+)=(?P<attribute_value>.+)$', 'objectbrowser.views.list_objects'), 
    1113    (r'/(?P<object_type>.+)+$', 'objectbrowser.views.list_objects'), 
    12     (r'/(?P<object_type>.+)/+$', 'objectbrowser.views.list_objects'), 
     14    (r'/+$', 'objectbrowser.views.list_object_types'), 
     15     
    1316    #(r'/contact/(?P<contact_name>.+)$', 'objectbrowser.views.get_contact'), 
    1417 
  • adagios/objectbrowser/views.py

    rc5564f7 r58641b0  
    3030        return render_to_response('configurator/list_contacts.html', c) 
    3131 
    32 def list_objects( request, object_type ): 
     32 
     33def list_objects( request, object_type=None, attribute_name=None, attribute_value=None ): 
    3334    c = {} 
    3435    c['messages'] = m = [] 
    3536    c['objects'] = objects = [] 
     37    if attribute_name=='object_type': 
     38        object_type=attribute_value 
    3639    if not Model.string_to_class.has_key(object_type): 
    3740        m.append('Model does not have any objects of type %s, valid types are %s' % (object_type, Model.string_to_class.keys())) 
    3841    else: 
    3942        myClass = Model.string_to_class[object_type] 
    40         c['objects'] = myClass.objects.all 
     43        if attribute_name is None: 
     44            c['objects'] = myClass.objects.all 
     45        else: 
     46            tmp = {attribute_name:attribute_value} 
     47            c['objects'] = myClass.objects.filter(**tmp) 
     48            m.append("I used the filter %s=%s" % (attribute_name, attribute_value)) 
    4149    m.append( "Found %s objects of type %s" % (len(c['objects']), object_type)) 
    4250    return render_to_response('objectbrowser/list_objects.html', c) 
     
    5462''' 
    5563 
    56 def view_object( request, object_type, object_name ): 
    57         c = {} 
    58         c['object_type'] = object_type 
    59         o = ObjectDefinition(object_type) 
    60         return render_to_response('objectbrowser/view_object.html') 
     64def view_objects( request, object_type,  attribute_name=None, attribute_value=None ): 
     65    c = {} 
     66    c['messages'] = m = [] 
     67    c['objects'] = objects = [] 
     68    if not Model.string_to_class.has_key(object_type): 
     69        m.append('Model does not have any objects of type %s, valid types are %s' % (object_type, Model.string_to_class.keys())) 
     70    else: 
     71        myClass = Model.string_to_class[object_type] 
     72        if attribute_name is None: 
     73            c['objects'] = myClass.objects.all 
     74        else: 
     75            tmp = {attribute_name:attribute_value} 
     76            c['objects'] = myClass.objects.filter(**tmp) 
     77            m.append("I used the filter %s=%s" % (attribute_name, attribute_value)) 
     78    m.append( "Found %s objects of type %s" % (len(c['objects']), object_type)) 
     79    attributes = [] 
     80    c['first_object'] = c['objects'][0] 
     81    c['first_object'].data = ["1","2"] 
     82    for tmp in c['objects']: 
     83        for k in tmp.keys(): 
     84            if k not in attributes: attributes.append( k ) 
     85    for i in c['objects']: 
     86        i.my_data = "test" 
     87    attr_val = [] 
     88    for i in attributes: 
     89        if c['first_object']._defined_attributes.has_key(i): 
     90            defined_attr = c['first_object']._defined_attributes[i] 
     91        else: 
     92            defined_attr = "" 
     93        if i in c['first_object']._inherited_attributes: 
     94            inherited_attr = c['first_object']._inherited_attributes[i] 
     95        else: 
     96            inherited_attr = "" 
     97        if None != inherited_attr or None != defined_attr: 
     98            attr_val.append( [i, defined_attr, inherited_attr ] ) 
     99    c['attr_val'] = attr_val 
     100    c['attr_val'] = c['first_object'].get_attribute_tuple() 
     101    m.append( "id=%s" % c['first_object'].get_id()) 
     102    c['first_object'].id = c['first_object'].get_id() 
     103    return render_to_response('objectbrowser/view_object.html', c) 
    61104 
    62105def get_contact(request, contact_name=None): 
     
    72115    c['attributes'] = {} 
    73116    return render_to_response('configurator/contact.html', c) 
     117 
    74118def get_host(request, host_name): 
    75119        pass 
  • adagios/templates/objectbrowser/list_objects.html

    rc0847d6 r58641b0  
    11 
    22 
    3 {% block title %}Showing {{ object_type }}{% endblock %} 
     3{% block title %}{{ object_type }}{% endblock %} 
    44 
    55{% block content %} 
     
    1919        {% for o in objects %} 
    2020                <tr> 
    21                         <td><a href="{{ o.object_type }}/{{ o.name }}">{{ o.name }} </a></td> 
     21                        <td><a href="{{ o.object_type }}/id={{ o.id }}">{{ o.name }} </a></td> 
    2222                        <td>{{ o.object_type }}</td> 
    2323                        <td>{{ o.use }}</td> 
  • adagios/templates/objectbrowser/view_object.html

    rc0847d6 r58641b0  
    1 {% extends "configurator/base.html" %} 
    21 
    3 {% block title %}c.object_type{% endblock %} 
     2 
     3{% block title %}{{ object_type }}{% endblock %} 
    44 
    55{% block content %} 
     
    1414{% endif %} 
    1515 
    16 {% if contact %} 
    17 <h1>{{ contact.contact_name }}</h1> 
    18         <table border=1> 
    19         {% for key,value in not_template.items %} 
    20                 <tr><td>{{ key }}</td><td>{{ value }} </td></tr> 
    21         {% endfor %} 
    22         </table> 
    23 <pre> 
    24 Attributes from template: 
    25 <table border=1> 
    26         {% for key,value in template.items %} 
    27                 <tr><td>{{ key }}</td><td>{{ value }} </td></tr> 
    28         {% endfor %} 
    29         </table> 
    3016 
    31 </pre> 
    32  
     17{% if first_object %} 
     18<!-- 
     19{{ first_object }} 
     20--> 
     21id={{ first_object.id }} 
     22        <table border=1> 
     23        <tr><th>Attribute Name</th><th>Defined Value</th><th>Inherited Value</th></tr> 
     24        {{ first_object.data }} 
     25        {% for attr in attr_val %} 
     26                <tr> 
     27                        <td>{{ attr.0 }}</td><td>{{ attr.1 }}</td><td> {{attr.2}}</td> 
     28                </tr> 
     29        {% endfor %}  
     30         
    3331{% else %} 
    34         <p>{{ c.object_type }} not found. </p> 
     32        <p>No objects found. </p> 
    3533{% endif %} 
    3634 
Note: See TracChangeset for help on using the changeset viewer.