def get_filterable_fields(module): module_fields = SuiteCRMCached().get_module_fields(module)['module_fields'] filterable_fields = OrderedDict() for field_name, field_def in module_fields.items(): if field_def['type'] not in NON_FILTERABLE_FIELD_TYPES\ and field_name not in NON_FILTERABLE_FIELD_NAMES: filterable_fields[field_name] = field_def return filterable_fields
def get_allowed_module_fields(module): available_fields = SuiteCRMCached().get_module_fields( module)['module_fields'] allowed_fields = OrderedDict() for field_name, field_def in available_fields.items(): if field_def['type'] not in FIELD_TYPES_DISALLOWED_ON_VIEWS\ and field_name not in FIELD_NAMES_DISALLOWED_ON_VIEWS: allowed_fields[field_name] = field_def return allowed_fields
def cache(request): context = basepage_processor(request) if request.method == 'POST' and 'action' in request.POST: if request.POST['action'] == 'clean_cache': SuiteCRMCached().clear_cache() context.update({ 'success_msg': True, 'msg': _('The cache has been cleared.') }) context.update( {'cached_calls': SuiteCRMCached().get_number_of_cached_calls()}) template = loader.get_template('portal/cache.html') return HttpResponse(template.render(context, request))
def get_available_modules(): available_modules = OrderedDict() try: all_modules = SuiteCRMCached().get_available_modules()['modules'] for module in all_modules: if module['module_key'] not in FORBIDDEN_MODULES: available_modules[module['module_key']] = module except Exception as e: pass return available_modules
def get_filter_layout(module): try: ordered_module_fields = OrderedDict() view = Layout.objects.get(module=module, view='filter') fields_list = json.loads(view.fields) module_fields = SuiteCRMCached().get_module_fields( module, fields_list)['module_fields'] for field in fields_list: if field in module_fields: ordered_module_fields[field] = module_fields[field] return ordered_module_fields except Exception: return OrderedDict()
def get_module_view_fields(module, view): ordered_module_fields = [] try: view_def = Layout.objects.get(module=module, view=view) fields = json.loads(view_def.fields) module_fields = SuiteCRMCached().get_module_fields( module)['module_fields'] remove_colon_of_field_labels(module_fields) for row in fields: row_fields = [] for field in row: if field in module_fields: row_fields.append(module_fields[field]) elif not field: row_fields.append(None) ordered_module_fields.append(row_fields) except Exception: pass return ordered_module_fields
def get_bean_from_post(module, view, data): module_fields = SuiteCRMCached().get_module_fields(module)['module_fields'] view_def = Layout.objects.get(module=module, view=view) fields = json.loads(view_def.fields) bean = Bean(module) default_values = {} try: module_def = ModuleDefinitionFactory.get_module_definition(module) default_values = module_def.default_values except Exception: pass for row in fields: for field in row: if field in module_fields: if field in data: value = data[field] field_def = module_fields[field] field_type = field_def['type'] if field_type == 'multienum': bean[field] = encode_multienum(data.getlist(field)) elif field_type == 'datetime' or field_type == 'datetimecombo': bean[field] = iso_to_datetime(value) elif field_type == 'relate': relate_id_field = field_def['id_name'] if relate_id_field in data: bean[relate_id_field] = data[relate_id_field] elif field_type == 'parent_type': if 'parent_id' in data: bean[field] = value bean['parent_id'] = data['parent_id'] else: bean[field] = value if view == 'create': for field, value in default_values.items(): if field not in data: bean[field] = value return bean
def retrieve_list_view_records(module, arguments, user): try: module_def = ModuleDefinitionFactory.get_module_definition(module) except ModuleDefinitionNotFoundException: return {'module_key': module, 'unsupported_module': True} try: user_type = user.userattr.user_type if (user_type == 'account' \ and module_def.accounts_link_type != LinkType.CONTACT) \ or module_def.contacts_link_type == LinkType.ACCOUNT: related_module = 'Accounts' related_id = user.userattr.account_id link_type = module_def.accounts_link_type link_name = module_def.accounts_link_name else: related_module = 'Contacts' related_id = user.userattr.contact_id link_type = module_def.contacts_link_type link_name = module_def.contacts_link_name except: return {'module_key': module, 'error_retrieving_records': True} records = [] module_fields = {} ordered_module_fields = OrderedDict() filterable_fields = get_filter_layout(module) limit = arguments.get('limit') if limit: limit = int(limit) else: limit = 20 offset = arguments.get('offset') if offset: offset = int(offset) order_by = arguments.get('order_by') order = arguments.get('order') try: view = Layout.objects.get(module=module, view='list') fields_list = json.loads(view.fields) module_fields = SuiteCRMCached().get_module_fields( module, fields_list)['module_fields'] for field in fields_list: if field in module_fields: ordered_module_fields[field] = module_fields[field] remove_colon_of_field_labels(module_fields) set_sortable_atribute_on_module_fields(module_fields) order_by_string = None if order_by in fields_list and module_fields[order_by]['sortable']: order_by_string = order_by else: if not order_by: order_by = module_def.default_order_by_field order_by_string = order_by order = module_def.default_order else: order_by = None if order_by and order in ['asc', 'desc']: order_by_string += ' ' + order else: order = None filter_query = get_filter_query(module, filterable_fields, arguments) if link_type == LinkType.RELATED: if filter_query: filter_query += " AND " filter_query += get_filter_related(module, link_name, related_id) if module_def.custom_where: if filter_query: filter_query += " AND " filter_query += module_def.custom_where records = SuiteCRM().get_bean_list(module, max_results=limit, offset=offset, order_by=order_by_string, query=filter_query) elif link_type == LinkType.RELATIONSHIP: if module_def.custom_where: if filter_query: filter_query += " AND " filter_query += module_def.custom_where records = SuiteCRM().get_relationships( related_module, related_id, link_name, related_fields=['id'] + fields_list, limit=limit, offset=offset, order_by=order_by_string, related_module_query=filter_query) elif link_type == LinkType.PARENT: if filter_query: filter_query += " AND " filter_query += get_filter_parent(module, related_module, related_id) if module_def.custom_where: if filter_query: filter_query += " AND " filter_query += module_def.custom_where records = SuiteCRM().get_bean_list(module, max_results=limit, offset=offset, order_by=order_by_string, query=filter_query) elif link_type == LinkType.NONE: if module_def.custom_where: if filter_query: filter_query += " AND " filter_query += module_def.custom_where records = SuiteCRM().get_bean_list(module, max_results=limit, offset=offset, order_by=order_by_string, query=filter_query) except Exception as e: print e return { 'module_key': module, 'records': records, 'module_fields': ordered_module_fields, 'filterable_fields': filterable_fields, 'current_filters': get_listview_filter(arguments), 'order_by': order_by, 'order': order }