def get(self, **kwargs): if "service" in kwargs: service = kwargs["service"] else: service = self.initialize_service() try: if "qt" in kwargs: qt = kwargs["qt"] # return self._get_data(service, kwargs['qt'], kwargs['id']) if qt == "accounts": query = service.management().accounts().list() if qt == "properties": query = service.management().webproperties().list(accountId=kwargs["account_id"]) if qt == "profiles": query = ( service.management() .profiles() .list(accountId=kwargs["account_id"], webPropertyId=kwargs["property_id"]) ) return query.execute() else: return self.get_results( service, kwargs["profile_id"], kwargs.get("query_type", None), kwargs.get("reference_date", None) ) except TypeError as error: # Handle errors in constructing a query. return "There was an error constructing your query : {0}".format(error) except HttpError as error: # Handle API errors. return "Arg, there was an API error : {0} : {1}".format(error.resp.status, error._get_reason()) except AccessTokenRefreshError: msg = _(u"The credentials have been revoked or expired," u"please re-run the application to re-authorize") return {"status": _(u"Error"), "msg": msg}
def available_services(self): services = { u'google': _(u"Google Analytics"), u'xovi': _(u"XOVI"), u'ac': _(u"activeCollab"), } data = [] for s in services: item = {} req_key = 'xeo.cxn.{0}_api_uri'.format(s) api_uri = api.portal.get_registry_record(req_key) item['name'] = services[s] item['sid'] = s item['uri'] = api_uri data.append(item) return data
def update(self): context = aq_inner(self.context) self.errors = {} unwanted = ('_authenticator', 'form.button.Submit') required = ('service') if 'form.button.Submit' in self.request: authenticator = getMultiAdapter((context, self.request), name=u"authenticator") if not authenticator.verify(): raise Unauthorized form = self.request.form form_data = {} form_errors = {} errorIdx = 0 for value in form: if value not in unwanted: form_data[value] = safe_unicode(form[value]) if not form[value] and value in required: error = {} error['active'] = True error['msg'] = _(u"This field is required") form_errors[value] = error errorIdx += 1 else: error = {} error['active'] = False error['msg'] = form[value] form_errors[value] = error if errorIdx > 0: self.errors = form_errors else: self._refresh_configuration(form)
def _refresh_configuration(self, data): context = aq_inner(self.context) xovi_tool = getUtility(IXoviTool) project_list = xovi_tool.get( service=u'project', method=u'getProjects', limit=50 ) projects = json.dumps(project_list) setattr(context, 'projects_xovi', projects) daily_domains = xovi_tool.get( service=u'seo', method=u'getDailyDomains', limit=50 ) domains = json.dumps(daily_domains) setattr(context, 'domains_xovi', domains) modified(context) context.reindexObject(idxs='modified') IStatusMessage(self.request).addStatusMessage( _(u"The Xovi configuration has sucessfully been refreshed"), type='info') portal_url = api.portal.get().absolute_url() param = '/adm/@@setup-xovi' url = portal_url + param return self.request.response.redirect(url)
def _update_report_data(self, data): context = aq_inner(self.context) metric = self.report() new_row = { 'xd:linkDate': data['lb-date'], 'xd:linkSourceURI': data['lb-source'], 'xd:linkTargetURI': data['lb-target'], 'xd:linkText': data['lb-text'] } table = metric['dataTable'] rows = table['rows'] rows.append(new_row) table['rows'] = rows metric['dataTable'] = table stored = getattr(context, 'report') data = json.loads(stored) items = data['items'] items[0] = metric setattr(context, 'report', json.dumps(data)) modified(context) context.reindexObject(idxs='modified') msg = _(u"Built links data table was successfully updated") api.portal.show_message(msg, self.request) portal_url = api.portal.get().absolute_url() url = '{0}/adm/'.format(portal_url) return self.request.response.redirect(url)
def update(self): self.has_dashboard = len(self.dashboard()) > 0 context = aq_inner(self.context) self.errors = {} unwanted = ("_authenticator", "form.button.Submit") required = "title" if "form.button.Submit" in self.request: authenticator = getMultiAdapter((context, self.request), name=u"authenticator") if not authenticator.verify(): raise Unauthorized form = self.request.form form_data = {} form_errors = {} errorIdx = 0 for value in form: if value not in unwanted: form_data[value] = safe_unicode(form[value]) if not form[value] and value in required: error = {} error["active"] = True error["msg"] = _(u"This field is required") form_errors[value] = error errorIdx += 1 else: error = {} error["active"] = False error["msg"] = form[value] form_errors[value] = error if errorIdx > 0: self.errors = form_errors else: self._update_dashboard(form)
def service_details(self): data = { 'ac': { u'id': u"ac", u'name': _(u"activeCollab"), u'iface': IACTool, }, 'google': { u'id': u"ga", u'name': _(u"Google Analytics"), u'iface': IGATool, }, 'xovi': { u'id': u"xovi", u'name': _(u"XOVI"), u'iface': IXoviTool, }, } return data
def _refresh_configuration(self, data): context = aq_inner(self.context) project_list = self.get_profiles() projects = json.dumps(project_list) setattr(context, 'projects_ga', projects) modified(context) context.reindexObject(idxs='modified') IStatusMessage(self.request).addStatusMessage( _(u"GA configuration has sucessfully been refreshed"), type='info') portal_url = api.portal.get().absolute_url() url = '{0}/adm/@@setup-google'.format(portal_url) return self.request.response.redirect(url)
def _refresh_configuration(self, data): context = aq_inner(self.context) xovi_tool = getUtility(IACTool) project_list = xovi_tool.make_request(path_info=u'projects') projects = json.dumps(project_list) setattr(context, 'projects_ac', projects) modified(context) context.reindexObject(idxs='modified') IStatusMessage(self.request).addStatusMessage( _(u"The activeCollab configuration was sucessfully refreshed"), type='info') portal_url = api.portal.get().absolute_url() param = '/adm/@@setup-ac' url = portal_url + param return self.request.response.redirect(url)
def applyChanges(self, data): context = aq_inner(self.context) user_id = django_random.get_random_string(length=12) properties = dict( fullname=data['fullname'], ) user = api.user.create( username=data['email'], email=data['email'], properties=properties, ) api.group.add_user( groupname=data['usergroup'], username=user.getId() ) IStatusMessage(self.request).addStatusMessage( _(u"New user account has been created succesfully"), type='info') next_url = context.absolute_url() + '/@@manage-users' return self.request.response.redirect(next_url)
def _update_dashboard(self, data): idx = int(data["project-idx"]) uuid = data["uuid"] item = api.content.get(UID=uuid) stored = getattr(item, "projects") project = stored[idx] project["ga"] = data["ga-profile"] if data["xovi-profile"]: project["xo"] = data["xovi-profile"] if data["ac-profile"]: project["ac"] = data["ac-profile"] stored[idx] = project setattr(item, "projects", stored) modified(item) item.reindexObject(idxs="modified") IStatusMessage(self.request).addStatusMessage( _(u"GA configuration has sucessfully been refreshed"), type="info" ) portal_url = api.portal.get().absolute_url() url = "{0}/adm/@@manage-dashboards?uuid={1}".format(portal_url, uuid) return self.request.response.redirect(url)
def handleCancel(self, action): context = aq_inner(self.context) IStatusMessage(self.request).addStatusMessage( _(u"User creation has been cancelled."), type='info') return self.request.response.redirect(context.absolute_url())
from plone.directives import form from plone.keyring import django_random from z3c.form import button from zope.schema.vocabulary import SimpleVocabulary from zope.schema.vocabulary import SimpleTerm from Products.statusmessages.interfaces import IStatusMessage from xpose.seotool.seotool import ISeoTool from xpose.seotool import MessageFactory as _ usergroups = SimpleVocabulary([ SimpleTerm(value=u'staff', title=_(u'Xdash Staff')), SimpleTerm(value=u'customers', title=_(u'Customers')) ]) class IUserCreation(form.Schema): fullname = schema.TextLine( title=_(u"Fullname"), required=False, ) email = schema.TextLine( title=_(u"E-Mail"), description=_(u"Enter a valid E-Mail address. Note: this address will " u"act as the login name"), required=True,
from plone.directives import form from plone.keyring import django_random from z3c.form import button from zope.schema.vocabulary import SimpleVocabulary from zope.schema.vocabulary import SimpleTerm from Products.statusmessages.interfaces import IStatusMessage from xpose.seotool.seotool import ISeoTool from xpose.seotool import MessageFactory as _ usergroups = SimpleVocabulary([ SimpleTerm(value=u'staff', title=_(u'Xpose414 Staff')), SimpleTerm(value=u'customers', title=_(u'Customers')) ]) class IUserCreation(form.Schema): fullname = schema.TextLine( title=_(u"Fullname"), required=False, ) email = schema.TextLine( title=_(u"E-Mail"), description=_(u"Enter a valid E-Mail address. Note: this address will " u"act as the login name"), required=True,
def dashboard_name(self): if self.has_token(): item = self.dashboard() return item.Title() return _(u"Untitled dashboard")