def check_custom_metrics(portal, portal_dict, custom_metrics, account, wp, also_fix=False): for cm in CUSTOM_METRIC: exist_in_ga = utils.find_by_keys(custom_metrics, cm, 'name') exist_in_portal = portal.google_analytics_metrics.get(cm, None) if not exist_in_ga or not exist_in_portal or \ not exist_in_ga['index'] == exist_in_portal: if not exist_in_ga and not exist_in_portal: app.log.error( 'custom metric={} does not exist in ga nor portal={},{} creating' .format(cm, portal.id, portal.host), **app.log.extra(portal=portal_dict, account=account, web_property=wp)) if also_fix: portal.google_analytics_metrics[ cm] = ga.create_custom_metric(account_id=account['id'], web_property_id=wp['id'], dimension_name=cm) else: app.log.critical( 'something wrong with custom metric {}, at ga we have={}, at portal we have={}' .format(cm, exist_in_ga, exist_in_portal), **app.log.extra(portal=portal_dict, account=account, web_property=wp))
def check(self, membership_id): from profapp.models.portal import MemberCompanyPortal from profapp import utils membership = MemberCompanyPortal.get(membership_id) action = utils.find_by_keys(self.actions(membership), self._action, 'name') if not action: raise Exception("Unknown action {} for membership={}, publication={}".format( self._action, membership_id)) return action['enabled'] is True
def check(self, membership_id): from profapp.models.portal import MemberCompanyPortal from profapp import utils membership = MemberCompanyPortal.get(membership_id) action = utils.find_by_keys(self.actions(membership), self._action, 'name') if not action: raise Exception( "Unknown action {} for membership={}, publication={}".format( self._action, membership_id)) return action['enabled'] is True
def actions(cls, membership, material, check_only_for_action=None): from profapp.models.permissions import RIGHT_AT_COMPANY, RIGHT_AT_PORTAL from ..models.company import UserCompany employment = UserCompany.get_by_user_and_company_ids(company_id=material.company_id) ret = [ {'name': cls.ACTIONS['SUBMIT'], 'enabled': employment.rights[RIGHT_AT_COMPANY.ARTICLES_SUBMIT_OR_PUBLISH]} ] for change in ret: change['message'] = '' if check_only_for_action: return True if utils.find_by_keys(ret, check_only_for_action, 'name') else False else: return ret
def check_custom_metrics(portal, portal_dict, custom_metrics, account, wp, also_fix=False): for cm in CUSTOM_METRIC: exist_in_ga = utils.find_by_keys(custom_metrics, cm, 'name') exist_in_portal = portal.google_analytics_metrics.get(cm, None) if not exist_in_ga or not exist_in_portal or \ not exist_in_ga['index'] == exist_in_portal: if not exist_in_ga and not exist_in_portal: app.log.error( 'custom metric={} does not exist in ga nor portal={},{} creating'. format(cm, portal.id, portal.host), **app.log.extra(portal=portal_dict, account=account, web_property=wp)) if also_fix: portal.google_analytics_metrics[cm] = ga.create_custom_metric( account_id=account['id'], web_property_id=wp['id'], dimension_name=cm) else: app.log.critical( 'something wrong with custom metric {}, at ga we have={}, at portal we have={}'. format(cm, exist_in_ga, exist_in_portal), **app.log.extra(portal=portal_dict, account=account, web_property=wp))
def actions(cls, membership, material, check_only_for_action=None): from profapp.models.permissions import RIGHT_AT_COMPANY, RIGHT_AT_PORTAL from ..models.company import UserCompany employment = UserCompany.get_by_user_and_company_ids( company_id=material.company_id) ret = [{ 'name': cls.ACTIONS['SUBMIT'], 'enabled': employment.rights[RIGHT_AT_COMPANY.ARTICLES_SUBMIT_OR_PUBLISH] }] for change in ret: change['message'] = '' if check_only_for_action: return True if utils.find_by_keys(ret, check_only_for_action, 'name') else False else: return ret