예제 #1
0
파일: api.py 프로젝트: CoRfr/testman4trac
    def process_request(self, req):
        """
        Handles Ajax requests to change an object's property.
        """
        author = get_reporter_id(req, 'author')

        if req.path_info.startswith('/propertyupdate'):
            realm = req.args.get('realm')
            key_str = req.args.get('key')
            name = req.args.get('name')
            value = req.args.get('value')
            
            result = 'ERROR'
            
            key = get_dictionary_from_string(key_str)

            try:
                self.env.log.debug("Setting property %s to %s, in %s with key %s" % (name, value, realm, key))
                
                gclass_modelprovider = GenericClassModelProvider(self.env)

                gclass_modelprovider.check_permission(req, realm, key_str, name, value)

                obj = gclass_modelprovider.get_object(realm, key)
                
                # Set the required property
                obj[name] = value
                
                obj.author = author
                obj.remote_addr = req.remote_addr
                if obj is not None and obj.exists:
                    comment = "Property changed"
                    obj.save_changes(author, comment)

                    # Call listeners
                    self.object_changed(obj, comment, author)
                    
                else:
                    self.env.log.debug("Object to update not found. Creating it.")
                    props_str = req.args.get('props')
                    if props_str is not None and not props_str == '':
                        # In order to create an object, additional properties may be required
                        props = get_dictionary_from_string(props_str)
                        obj.set_values(props)
                    obj.insert()

                    # Call listeners
                    self.object_created(obj)

                result = 'OK'

            except:
                self.env.log.debug(formatExceptionInfo())

            req.send_header("Content-Length", len(result))
            req.write(result)
            return 

        return 'empty.html', {}, None
예제 #2
0
파일: api.py 프로젝트: CoRfr/testman4trac
    def get_search_results(self, req, terms, filters):
        gclass_modelprovider = GenericClassModelProvider(self.env)

        known_realms = gclass_modelprovider.get_known_realms()
        
        for realm in filters:
            if realm in known_realms:
                metadata = gclass_modelprovider.get_metadata(realm)
                
                if 'searchable' in metadata and metadata['searchable']:
                    obj = gclass_modelprovider.get_object(realm)
                    if obj is not None:
                        for result in obj.get_search_results(req, terms, filters):
                            yield result
예제 #3
0
파일: api.py 프로젝트: CoRfr/testman4trac
    def get_search_results(self, req, terms, filters):
        gclass_modelprovider = GenericClassModelProvider(self.env)

        known_realms = gclass_modelprovider.get_known_realms()

        for realm in filters:
            if realm in known_realms:
                metadata = gclass_modelprovider.get_metadata(realm)

                if 'searchable' in metadata and metadata['searchable']:
                    obj = gclass_modelprovider.get_object(realm)
                    if obj is not None:
                        for result in obj.get_search_results(
                                req, terms, filters):
                            yield result
예제 #4
0
파일: api.py 프로젝트: CoRfr/testman4trac
    def get_search_filters(self, req):
        gclass_modelprovider = GenericClassModelProvider(self.env)

        for realm in gclass_modelprovider.get_known_realms():
            try:
                gclass_modelprovider.get_class_provider(realm).check_permission(req, realm, key_str=None, operation='search')

                metadata = gclass_modelprovider.get_metadata(realm)
                
                if 'searchable' in metadata and metadata['searchable']:
                    if 'label' in metadata:
                        label = metadata['label']
                    else:
                        label = realm.capitalize()
                    
                    yield (realm, label)
            
            except:
                self.env.log.debug("No permission to search on realm %s." % realm)
예제 #5
0
파일: api.py 프로젝트: CoRfr/testman4trac
    def get_search_filters(self, req):
        gclass_modelprovider = GenericClassModelProvider(self.env)

        for realm in gclass_modelprovider.get_known_realms():
            try:
                gclass_modelprovider.get_class_provider(
                    realm).check_permission(req,
                                            realm,
                                            key_str=None,
                                            operation='search')

                metadata = gclass_modelprovider.get_metadata(realm)

                if 'searchable' in metadata and metadata['searchable']:
                    if 'label' in metadata:
                        label = metadata['label']
                    else:
                        label = realm.capitalize()

                    yield (realm, label)

            except:
                self.env.log.debug("No permission to search on realm %s." %
                                   realm)
예제 #6
0
def get_all_table_columns_for_object(env, objtype, settings):
    genericClassModelProvider = GenericClassModelProvider(env)
    
    tcat_fields = genericClassModelProvider.get_custom_fields_for_realm('testcatalog')
    tcat_has_custom = tcat_fields is not None and len(tcat_fields) > 0
    
    tc_fields = genericClassModelProvider.get_custom_fields_for_realm('testcase')
    tc_has_custom = tc_fields is not None and len(tc_fields) > 0

    if objtype == 'testplan':
        tcip_fields = genericClassModelProvider.get_custom_fields_for_realm('testcaseinplan')
        tcip_has_custom = tcip_fields is not None and len(tcip_fields) > 0
    else:
        tcip_fields = False
        tcip_has_custom = None

    custom_ctx = {
        'testcatalog': [tcat_has_custom, tcat_fields],
        'testcase': [tc_has_custom, tc_fields],
        'testcaseinplan': [tcip_has_custom, tcip_fields]
        }
   
    result = []
    result_map = {}
    
    # Common columns
    result.append({'name': 'title', 'label': _("Name"), 'visible': _is_column_visible(objtype, 'title', settings), 'totals': _get_column_total_operation(objtype, 'title', settings)})
            
    # Custom testcatalog columns
    if tcat_has_custom:
        for f in tcat_fields:
            if f['type'] == 'text':
                result.append(_get_column_settings(objtype, f, settings))

    # Base testcase columns
    result.append({'name': 'id', 'label': _("ID"), 'visible': _is_column_visible(objtype, 'id', settings), 'totals': _get_column_total_operation(objtype, 'id', settings)})

    # Custom testcase columns
    if tc_has_custom:
        for f in tc_fields:
            if f['type'] == 'text':
                result.append(_get_column_settings(objtype, f, settings))

    if objtype == 'testplan':
        # Base testcaseinplan columns
        result.append({'name': 'status', 'label': _("Status"), 'visible': _is_column_visible(objtype, 'status', settings), 'totals': _get_column_total_operation(objtype, 'status', settings)})
        result.append({'name': 'author', 'label': _("Author"), 'visible': _is_column_visible(objtype, 'author', settings), 'totals': _get_column_total_operation(objtype, 'author', settings)})
        result.append({'name': 'time', 'label': _("Last Change"), 'visible': _is_column_visible(objtype, 'time', settings), 'totals': _get_column_total_operation(objtype, 'time', settings)})

        # Custom testcaseinplan columns
        if tcip_has_custom:
            for f in tcip_fields:
                if f['type'] == 'text':
                    result.append(_get_column_settings(objtype, f, settings))

    # Full test case description
    result.append({'name': 'description', 'label': _("Description"), 'visible': _is_column_visible(objtype, 'description', settings), 'totals': _get_column_total_operation(objtype, 'description', settings)})

    for r in result:
        result_map[r['name']] = r
    
    return result, result_map, custom_ctx
예제 #7
0
파일: admin.py 프로젝트: CoRfr/testman4trac
def get_all_table_columns_for_object(env, objtype, settings):
    genericClassModelProvider = GenericClassModelProvider(env)
    
    tcat_fields = genericClassModelProvider.get_custom_fields_for_realm('testcatalog')
    tcat_has_custom = tcat_fields is not None and len(tcat_fields) > 0
    
    tc_fields = genericClassModelProvider.get_custom_fields_for_realm('testcase')
    tc_has_custom = tc_fields is not None and len(tc_fields) > 0

    if objtype == 'testplan':
        tcip_fields = genericClassModelProvider.get_custom_fields_for_realm('testcaseinplan')
        tcip_has_custom = tcip_fields is not None and len(tcip_fields) > 0
    else:
        tcip_fields = False
        tcip_has_custom = None

    custom_ctx = {
        'testcatalog': [tcat_has_custom, tcat_fields],
        'testcase': [tc_has_custom, tc_fields],
        'testcaseinplan': [tcip_has_custom, tcip_fields]
        }
   
    result = []
    result_map = {}
    
    # Common columns
    result.append({'name': 'title', 'label': _("Name"), 'visible': _is_column_visible(objtype, 'title', settings), 'totals': _get_column_total_operation(objtype, 'title', settings)})
            
    # Custom testcatalog columns
    if tcat_has_custom:
        for f in tcat_fields:
            if f['type'] == 'text':
                result.append(_get_column_settings(objtype, f, settings))

    # Base testcase columns
    result.append({'name': 'id', 'label': _("ID"), 'visible': _is_column_visible(objtype, 'id', settings), 'totals': _get_column_total_operation(objtype, 'id', settings)})

    # Custom testcase columns
    if tc_has_custom:
        for f in tc_fields:
            if f['type'] == 'text':
                result.append(_get_column_settings(objtype, f, settings))

    if objtype == 'testplan':
        # Base testcaseinplan columns
        result.append({'name': 'status', 'label': _("Status"), 'visible': _is_column_visible(objtype, 'status', settings), 'totals': _get_column_total_operation(objtype, 'status', settings)})
        result.append({'name': 'author', 'label': _("Author"), 'visible': _is_column_visible(objtype, 'author', settings), 'totals': _get_column_total_operation(objtype, 'author', settings)})
        result.append({'name': 'time', 'label': _("Last Change"), 'visible': _is_column_visible(objtype, 'time', settings), 'totals': _get_column_total_operation(objtype, 'time', settings)})

        # Custom testcaseinplan columns
        if tcip_has_custom:
            for f in tcip_fields:
                if f['type'] == 'text':
                    result.append(_get_column_settings(objtype, f, settings))

    # Full test case description
    result.append({'name': 'description', 'label': _("Description"), 'visible': _is_column_visible(objtype, 'description', settings), 'totals': _get_column_total_operation(objtype, 'description', settings)})

    for r in result:
        result_map[r['name']] = r
    
    return result, result_map, custom_ctx
예제 #8
0
파일: api.py 프로젝트: CoRfr/testman4trac
    def process_request(self, req):
        """
        Handles Ajax requests to change an object's property.
        """
        author = get_reporter_id(req, 'author')

        if req.path_info.startswith('/propertyupdate'):
            realm = req.args.get('realm')
            key_str = req.args.get('key')
            name = req.args.get('name')
            value = req.args.get('value')

            result = 'ERROR'

            key = get_dictionary_from_string(key_str)

            try:
                self.env.log.debug(
                    "Setting property %s to %s, in %s with key %s" %
                    (name, value, realm, key))

                gclass_modelprovider = GenericClassModelProvider(self.env)

                gclass_modelprovider.check_permission(req, realm, key_str,
                                                      name, value)

                obj = gclass_modelprovider.get_object(realm, key)

                # Set the required property
                obj[name] = value

                obj.author = author
                obj.remote_addr = req.remote_addr
                if obj is not None and obj.exists:
                    comment = "Property changed"
                    obj.save_changes(author, comment)

                    # Call listeners
                    self.object_changed(obj, comment, author)

                else:
                    self.env.log.debug(
                        "Object to update not found. Creating it.")
                    props_str = req.args.get('props')
                    if props_str is not None and not props_str == '':
                        # In order to create an object, additional properties may be required
                        props = get_dictionary_from_string(props_str)
                        obj.set_values(props)
                    obj.insert()

                    # Call listeners
                    self.object_created(obj)

                result = 'OK'

            except:
                self.env.log.debug(formatExceptionInfo())

            req.send_header("Content-Length", len(result))
            req.write(result)
            return

        return 'empty.html', {}, None