def filter_properties(query): """ .. function:: XML-RPC Env.filter_properties(query) Performs a search and returns the resulting list of env properties. Parameter ``query`` is dict which recognizes the following keys: :param id: ID of env properties :type id: int :param name: Name of peroperty :type name: str :param is_active: :type is_active: bool :param group: ForeignKey: TCMSEnvGroup :type group: int or :class:`tcms.management.models.TCMSEnvGroup` :param value: ForeignKey: TCMSEnvValues :type value: int or :class:`tcms.management.models.TCMSEnvValues` :returns: List of serialized env properties matching the query :rtype: list(dict) For example to get all env properties containing 'Desktop':: >>> Env.filter_properties({'name__icontains': 'Desktop'}) """ if 'is_active' in query: query['is_active'] = parse_bool_value(query['is_active']) return TCMSEnvProperty.to_xmlrpc(query)
def filter_properties(request, query): """ Description: Performs a search and returns the resulting list of env properties. Params: $query - Hash: keys must match valid search fields. +------------------------------------------------------------------+ | Product Search Parameters | +------------------------------------------------------------------+ | Key | Valid Values | | id | Integer: ID of env properties | | name | String | | is_active | Boolean | | group | ForeignKey: TCMSEnvGroup | | value | ForeignKey: TCMSEnvValues | +------------------------------------------------------------------+ Returns: Array: Matching env properties are retuned in a list of hashes. Example: # Get all of env properties name contains 'Desktop' >>> Env.filter_properties({'name__icontains': 'Desktop'}) """ if 'is_active' in query: query['is_active'] = parse_bool_value(query['is_active']) return TCMSEnvProperty.to_xmlrpc(query)
def get(self, request, env_group_id): env_group = get_object_or_404(TCMSEnvGroup, pk=env_group_id) context_data = { 'environment': env_group, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': env_group.property.all(), 'message': '', } return render(request, self.template_name, context=context_data)
def filter(query): """ .. function:: XML-RPC Env.Property.filter(query) Performs a search and returns the resulting list of environment properties. :param query: Field lookups for :class:`tcms.management.models.TCMSEnvProperty` :type query: dict :returns: List of serialized :class:`tcms.management.models.TCMSEnvProperty` objects :rtype: list(dict) """ if 'is_active' in query: query['is_active'] = parse_bool_value(query['is_active']) return TCMSEnvProperty.to_xmlrpc(query)
def get_properties(request, env_group_id=None, is_active=True): """Get the list of properties associated with this env group. :param int env_group_id: env_group_id of the env group in the Database Return all of properties when the argument is not specified. :param bool is_active: If ``True``, only include builds. Default: ``True``. :return: list of found environment properties. :rtype: list Example:: # Get all of properties >>> Env.get_properties() # Get the properties in group 10 >>> Env.get_properties(10) """ query = {'is_active': parse_bool_value(is_active)} if env_group_id: query['group__pk'] = env_group_id return TCMSEnvProperty.to_xmlrpc(query)
def get_properties(request, env_group_id=None, is_active=True): """ Description: Get the list of properties associated with this env group. Params: $env_group_id - Integer: env_group_id of the env group in the Database Return all of properties when the argument is not specific. $is_active - Boolean: True to only include builds where is_active is true. Default: True Returns: Array: Returns an array of env properties objects. Example: # Get all of properties >>> Env.get_properties() # Get the properties in group 10 >>> Env.get_properties(10) """ query = {'is_active': parse_bool_value(is_active)} if env_group_id: query['group__pk'] = env_group_id return TCMSEnvProperty.to_xmlrpc(query)
def filter_properties(request, query): """Performs a search and returns the resulting list of env properties. :param dict query: mapping containing following criteria to find out environment properties. * id: (int) environment property ID. * name: (str) property name. * is_active: (bool) whether to find active properties. * group: ForeignKey: :class:`TCMSEnvGroup` * value: ForeignKey: :class:`TCMSEnvValues` :return: Array: Matching env properties are retuned in a list of hashes. Example:: # Get all of env properties name contains 'Desktop' >>> Env.filter_properties({'name__icontains': 'Desktop'}) """ if 'is_active' in query: query['is_active'] = parse_bool_value(query['is_active']) return TCMSEnvProperty.to_xmlrpc(query)
def environment_group_edit(request, template_name='environment/group_edit.html'): """ Assign properties to environment group """ # Initial the response response = '' environment_id = request.GET.get('id', None) if environment_id is None: raise Http404 try: environment = TCMSEnvGroup.objects.get(pk=environment_id) except TCMSEnvGroup.DoesNotExist: raise Http404 # import pytest; pytest.set_trace() try: de = TCMSEnvGroup.objects.get(name=request.GET.get('name')) if environment != de: response = 'Duplicated name already exists, please change to ' \ 'another name.' context_data = { 'environment': environment, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': environment.property.all(), 'message': response, } return render(request, template_name, context=context_data) except TCMSEnvGroup.DoesNotExist: pass if request.GET.get('action') == 'modify': # Actions of modify environment_name = request.GET['name'] if environment.name != environment_name: original_value = environment.name environment.name = environment_name environment.log_action( who=request.user, field='name', original_value=original_value, new_value=environment_name) returned_env_status = 'enabled' in request.GET if environment.is_active != returned_env_status: original_value = environment.is_active environment.is_active = returned_env_status environment.log_action( who=request.user, field='is_active', original_value=original_value, new_value=returned_env_status) environment.modified_by_id = request.user.id environment.save() original_property_values = list( environment.property.values_list('name', flat=True)) original_property_values.sort() # Remove all of properties of the group. TCMSEnvGroupPropertyMap.objects.filter(group__id=environment.id).delete() # Readd the property to environemnt group and log the action for property_id in request.GET.getlist('selected_property_ids'): TCMSEnvGroupPropertyMap.objects.create(group_id=environment.id, property_id=property_id) new_property_values = list( environment.property.values_list('name', flat=True)) new_property_values.sort() environment.log_action( who=request.user, field='Property values', original_value=', '.join(original_property_values), new_value=', '.join(new_property_values)) response = 'Environment group saved successfully.' context_data = { 'environment': environment, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': environment.property.all(), 'message': response, } return render(request, template_name, context=context_data)
def environment_group_edit(request, template_name='environment/group_edit.html'): """ Assign properties to environment group """ # Initial the response response = '' environment_id = request.GET.get('id', None) if environment_id is None: raise Http404 try: environment = TCMSEnvGroup.objects.get(pk=environment_id) except TCMSEnvGroup.DoesNotExist: raise Http404 # import pytest; pytest.set_trace() try: de = TCMSEnvGroup.objects.get(name=request.GET.get('name')) if environment != de: response = 'Duplicated name already exists, please change to ' \ 'another name.' context_data = { 'environment': environment, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': environment.property.all(), 'message': response, } return render(request, template_name, context_data) except TCMSEnvGroup.DoesNotExist: pass if request.GET.get('action') == 'modify': # Actions of modify environment_name = request.GET['name'] if environment.name != environment_name: environment.name = environment_name environment.log_action(who=request.user, action='Modify name %s from to %s' % (environment.name, environment_name)) if environment.is_active != request.GET.get('enabled', False): environment.is_active = request.GET.get('enabled', False) environment.log_action(who=request.user, action='Change env group status to %s' % environment.is_active) environment.modified_by_id = request.user.id environment.save() # Remove all of properties of the group. TCMSEnvGroupPropertyMap.objects.filter( group__id=environment.id).delete() # Readd the property to environemnt group and log the action for property_id in request.GET.getlist('selected_property_ids'): TCMSEnvGroupPropertyMap.objects.create(group_id=environment.id, property_id=property_id) property_values = environment.property.values_list('name', flat=True) environment.log_action(who=request.user, action='Properties changed to %s' % (', '.join(property_values))) response = 'Environment group saved successfully.' context_data = { 'environment': environment, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': environment.property.all(), 'message': response, } return render(request, template_name, context_data)
def environment_group_edit(request, template_name="environment/group_edit.html"): """ Assign properties to environment group """ # Initial the response response = "" environment_id = request.REQUEST.get("id", None) if environment_id is None: raise Http404 try: environment = TCMSEnvGroup.objects.get(pk=environment_id) except TCMSEnvGroup.DoesNotExist: raise Http404 try: de = TCMSEnvGroup.objects.get(name=request.REQUEST.get("name")) if environment != de: response = "Duplicated name already exists, please change to " "another name." context_data = { "environment": environment, "properties": TCMSEnvProperty.get_active(), "selected_properties": environment.property.all(), "message": response, } return render_to_response(template_name, context_data, context_instance=RequestContext(request)) except TCMSEnvGroup.DoesNotExist: pass if request.REQUEST.get("action") == "modify": # Actions of modify environment_name = request.REQUEST["name"] if environment.name != environment_name: environment.name = environment_name environment.log_action( who=request.user, action="Modify name %s from to %s" % (environment.name, environment_name) ) if environment.is_active != request.REQUEST.get("enabled", False): environment.is_active = request.REQUEST.get("enabled", False) environment.log_action(who=request.user, action="Change env group status to %s" % environment.is_active) environment.modified_by_id = request.user.id environment.save() # Remove all of properties of the group. TCMSEnvGroupPropertyMap.objects.filter(group__id=environment.id).delete() # Readd the property to environemnt group and log the action for property_id in request.REQUEST.getlist("selected_property_ids"): TCMSEnvGroupPropertyMap.objects.create(group_id=environment.id, property_id=property_id) property_values = environment.property.values_list("name", flat=True) environment.log_action(who=request.user, action="Properties changed to %s" % (", ".join(property_values))) response = "Environment group saved successfully." context_data = { "environment": environment, "properties": TCMSEnvProperty.get_active(), "selected_properties": environment.property.all(), "message": response, } return render_to_response(template_name, context_data, context_instance=RequestContext(request))
def environment_group_edit(request, template_name='environment/group_edit.html'): """ Assign properties to environment group """ # Initial the response response = '' environment_id = request.GET.get('id', None) if environment_id is None: raise Http404 try: environment = TCMSEnvGroup.objects.get(pk=environment_id) except TCMSEnvGroup.DoesNotExist: raise Http404 try: de = TCMSEnvGroup.objects.get(name=request.GET.get('name')) if environment != de: context_data = { 'environment': environment, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': environment.property.all(), 'message': 'Duplicated name already exists, please change to ' 'another name.', } return render(request, template_name, context=context_data) except TCMSEnvGroup.DoesNotExist: pass if request.GET.get('action') == 'modify': # Actions of modify environment_name = request.GET['name'] if environment.name != environment_name: original_value = environment.name environment.name = environment_name environment.log_action(who=request.user, field='name', original_value=original_value, new_value=environment_name) returned_env_status = 'enabled' in request.GET if environment.is_active != returned_env_status: original_value = environment.is_active environment.is_active = returned_env_status environment.log_action(who=request.user, field='is_active', original_value=original_value, new_value=returned_env_status) environment.modified_by_id = request.user.id environment.save() original_property_values = list( environment.property.values_list('name', flat=True)) original_property_values.sort() # Remove all of properties of the group. TCMSEnvGroupPropertyMap.objects.filter( group__id=environment.id).delete() # Readd the property to environemnt group and log the action for property_id in request.GET.getlist('selected_property_ids'): TCMSEnvGroupPropertyMap.objects.create(group_id=environment.id, property_id=property_id) new_property_values = list( environment.property.values_list('name', flat=True)) new_property_values.sort() environment.log_action( who=request.user, field='Property values', original_value=', '.join(original_property_values), new_value=', '.join(new_property_values)) response = 'Environment group saved successfully.' context_data = { 'environment': environment, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': environment.property.all(), 'message': response, } return render(request, template_name, context=context_data)
def post(self, request, env_group_id): env_group = get_object_or_404(TCMSEnvGroup, pk=env_group_id) de = TCMSEnvGroup.objects.filter(name=request.POST['name']).first() if de and env_group != de: context_data = { 'environment': env_group, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': env_group.property.all(), 'message': 'Duplicated name already exists, please change to ' 'another name.', } return render(request, self.template_name, context=context_data) new_name = request.POST['name'] if env_group.name != new_name: original_name = env_group.name env_group.name = new_name env_group.log_action( who=request.user, field='name', original_value=original_name, new_value=new_name) enable_group = 'enabled' in request.POST if env_group.is_active != enable_group: original_value = env_group.is_active env_group.is_active = enable_group env_group.log_action( who=request.user, field='is_active', original_value=original_value, new_value=enable_group) env_group.modified_by_id = request.user.id env_group.save() existing_properties = set(env_group.property.all()) selected_property_ids = list( map(int, request.POST.getlist('selected_property_ids'))) selected_properties = set( TCMSEnvProperty.objects.filter(pk__in=selected_property_ids)) newly_selected_properties = selected_properties - existing_properties if newly_selected_properties: for env_property in newly_selected_properties: TCMSEnvGroupPropertyMap.objects.create( group=env_group, property=env_property) env_group.log_action( who=request.user, field='Property values', original_value=', '.join( sorted(item.name for item in existing_properties)), new_value=', '.join( sorted(item.name for item in newly_selected_properties)), ) response = 'Environment group saved successfully.' context_data = { 'environment': env_group, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': env_group.property.order_by('name'), 'message': response, } return render(request, self.template_name, context=context_data)
def environment_group_edit(request, template_name='environment/group_edit.html'): """ Assign properties to environment group """ # Initial the response response = '' environment_id = request.GET.get('id', None) if environment_id is None: raise Http404 try: environment = TCMSEnvGroup.objects.get(pk=environment_id) except TCMSEnvGroup.DoesNotExist: raise Http404 # import pytest; pytest.set_trace() try: de = TCMSEnvGroup.objects.get(name=request.GET.get('name')) if environment != de: response = 'Duplicated name already exists, please change to ' \ 'another name.' context_data = { 'environment': environment, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': environment.property.all(), 'message': response, } return render_to_response(template_name, context_data, context_instance=RequestContext(request)) except TCMSEnvGroup.DoesNotExist: pass if request.GET.get('action') == 'modify': # Actions of modify environment_name = request.GET['name'] if environment.name != environment_name: environment.name = environment_name environment.log_action( who=request.user, action='Modify name %s from to %s' % (environment.name, environment_name)) if environment.is_active != request.GET.get('enabled', False): environment.is_active = request.GET.get('enabled', False) environment.log_action( who=request.user, action='Change env group status to %s' % environment.is_active) environment.modified_by_id = request.user.id environment.save() # Remove all of properties of the group. TCMSEnvGroupPropertyMap.objects.filter(group__id=environment.id).delete() # Readd the property to environemnt group and log the action for property_id in request.GET.getlist('selected_property_ids'): TCMSEnvGroupPropertyMap.objects.create(group_id=environment.id, property_id=property_id) property_values = environment.property.values_list('name', flat=True) environment.log_action( who=request.user, action='Properties changed to %s' % (', '.join(property_values))) response = 'Environment group saved successfully.' context_data = { 'environment': environment, 'properties': TCMSEnvProperty.get_active(), 'selected_properties': environment.property.all(), 'message': response, } return render_to_response(template_name, context_data, context_instance=RequestContext(request))