def node_setting(auth, node, **kwargs): #check institutions: try: email_domains = [email.split('@')[1] for email in auth.user.emails] inst = Institution.find_one(Q('email_domains', 'in', email_domains)) if inst not in auth.user.affiliated_institutions: auth.user.affiliated_institutions.append(inst) auth.user.save() except (IndexError, NoResultsFound): pass ret = _view_project(node, auth, primary=True) addons_enabled = [] addon_enabled_settings = [] for addon in node.get_addons(): addons_enabled.append(addon.config.short_name) if 'node' in addon.config.configs: config = addon.to_json(auth.user) # inject the MakoTemplateLookup into the template context # TODO inject only short_name and render fully client side config['template_lookup'] = addon.config.template_lookup config['addon_icon_url'] = addon.config.icon_url addon_enabled_settings.append(config) addon_enabled_settings = sorted( addon_enabled_settings, key=lambda addon: addon['addon_full_name'].lower()) ret['addon_categories'] = settings.ADDON_CATEGORIES ret['addons_available'] = sorted([ addon for addon in settings.ADDONS_AVAILABLE if 'node' in addon.owners and addon.short_name not in settings.SYSTEM_ADDED_ADDONS['node'] and addon.short_name != 'wiki' ], key=lambda addon: addon.full_name.lower()) for addon in settings.ADDONS_AVAILABLE: if 'node' in addon.owners and addon.short_name not in settings.SYSTEM_ADDED_ADDONS[ 'node'] and addon.short_name == 'wiki': ret['wiki'] = addon break ret['addons_enabled'] = addons_enabled ret['addon_enabled_settings'] = addon_enabled_settings ret['addon_capabilities'] = settings.ADDON_CAPABILITIES ret['addon_js'] = collect_node_config_js(node.get_addons()) ret['include_wiki_settings'] = node.include_wiki_settings(auth.user) ret['comments'] = { 'level': node.comment_level, } ret['categories'] = Node.CATEGORY_MAP ret['categories'].update({'project': 'Project'}) return ret
def node_setting(auth, node, **kwargs): #check institutions: try: email_domains = [email.split('@')[1] for email in auth.user.emails] inst = Institution.find_one(Q('email_domains', 'in', email_domains)) if inst not in auth.user.affiliated_institutions: auth.user.affiliated_institutions.append(inst) auth.user.save() except (IndexError, NoResultsFound): pass ret = _view_project(node, auth, primary=True) addons_enabled = [] addon_enabled_settings = [] for addon in node.get_addons(): addons_enabled.append(addon.config.short_name) if 'node' in addon.config.configs: config = addon.to_json(auth.user) # inject the MakoTemplateLookup into the template context # TODO inject only short_name and render fully client side config['template_lookup'] = addon.config.template_lookup config['addon_icon_url'] = addon.config.icon_url addon_enabled_settings.append(config) addon_enabled_settings = sorted(addon_enabled_settings, key=lambda addon: addon['addon_full_name'].lower()) ret['addon_categories'] = settings.ADDON_CATEGORIES ret['addons_available'] = sorted([ addon for addon in settings.ADDONS_AVAILABLE if 'node' in addon.owners and addon.short_name not in settings.SYSTEM_ADDED_ADDONS['node'] and addon.short_name != 'wiki' ], key=lambda addon: addon.full_name.lower()) for addon in settings.ADDONS_AVAILABLE: if 'node' in addon.owners and addon.short_name not in settings.SYSTEM_ADDED_ADDONS['node'] and addon.short_name == 'wiki': ret['wiki'] = addon break ret['addons_enabled'] = addons_enabled ret['addon_enabled_settings'] = addon_enabled_settings ret['addon_capabilities'] = settings.ADDON_CAPABILITIES ret['addon_js'] = collect_node_config_js(node.get_addons()) ret['include_wiki_settings'] = node.include_wiki_settings(auth.user) ret['comments'] = { 'level': node.comment_level, } ret['categories'] = Node.CATEGORY_MAP ret['categories'].update({ 'project': 'Project' }) return ret
def _create(cls, target_class, *args, **kwargs): from random import randint inst = ProjectFactory._create(target_class, *args, **kwargs) inst.institution_id = str(randint(1, 20000)) inst.institution_name = str(randint(10, 20000)) inst.institution_logo_name = 'logo.img' inst.institution_auth_url = 'http://thisIsUrl.biz' inst.save() return Institution(inst)
def _build(cls, target_class, *args, **kwargs): from random import randint '''Build an object without saving it.''' inst = ProjectFactory._build(target_class, *args, **kwargs) inst.institution_id = str(randint(1, 20000)) inst.institution_name = str(randint(10, 20000)) inst.institution_logo_name = 'logo.img' inst.institution_auth_url = 'http://thisIsUrl.biz' return Institution(inst)
def _build(cls, target_class, *args, **kwargs): inst = ProjectFactory._build(target_class) for inst_attr, node_attr in Institution.attribute_map.items(): default = cls.default_institution_attributes.get(inst_attr) if callable(default): default = default() setattr(inst, node_attr, kwargs.pop(inst_attr, default)) for key, val in kwargs.items(): setattr(inst, key, val) return Institution(inst)