def user_properties(self): member_data = api.user.get(username=self.username) profile__properties = [ _(u'fullname'), _(u'email'), _(u'phone'), _(u'country'), _(u'position'), _(u'wop_programs'), _(u'wop_platforms'), _(u'wop_partners'), _(u'type_of_organization'), _(u'common_working_areas'), _(u'donor'), _(u'other') ] rendered_properties = [] for prop in profile__properties: if prop != 'common_working_areas': rendered_properties.append( dict(name=_(prop), value=member_data.getProperty(prop, ''))) else: rendered_properties.append( dict(name=_(prop), value=utils.getTranslatedWorkingAreaFromID( member_data.getProperty(prop, '')))) return rendered_properties
def getAreas(self): """ Returns all the Improvement Areas in a Project """ items = api.content.find(portal_type=['ImprovementArea'], context=self.context) results = [] for project in items: item = project.getObject() results.append( dict(title=getTranslatedWorkingAreaFromID(item.id), url='/'.join(item.getPhysicalPath()), id=item.id, description=item.description, portal_type=item.portal_type)) return sorted(results, key=itemgetter('title'), reverse=False)
def getImprovementAreas(self): items = api.content.find(portal_type='ImprovementArea', path='/'.join(self.context.getPhysicalPath()), depth=1) results = [] for item in items: obj = item.getObject() if obj.image is None: image = obj.absolute_url_path( ) + '/++theme++gwopa.theme/assets/images/default_image.jpg' else: image = obj.absolute_url_path() + '/@@images/image/thumb' results.append( dict(title=utils.getTranslatedWorkingAreaFromID(item.id), image=image, url='/'.join(obj.getPhysicalPath()), description=item.Description)) results.sort(key=lambda x: x['title'], reverse=False) return results
def updateReport(self): if not hasattr(self, 'context'): self.context = self request = getRequest() refresh = request.form.get('refresh', False) if refresh: logger.info('YYY - User: '******'YYY - ' + str(self.context.save_data)) try: project = self.aq_parent.aq_parent except: project = self.context.aq_parent.aq_parent if self.context.save_data and self.context.save_data != "": self.context.save_data['project_overview']['project_name'] = project.title self.context.save_data['project_overview']['project_code'] = project.code self.context.save_data['summary']['progress']['roadblock'] = self.context.overall_project_status == 'roadblock' self.context.save_data['summary']['progress']['potential'] = self.context.overall_project_status == 'potential' self.context.save_data['summary']['progress']['ontrack'] = self.context.overall_project_status == 'ontrack' self.context.save_data['summary']['progress']['stakeholders'] = self.context.progress_stakeholders self.context.save_data['summary']['other'] = self.context.other_additional_challenges self.context.save_data['next_steps'] = self.context.next_steps if not refresh: return self.context.save_data data = {} attr_lang = getTitleAttrLang() project_manager_admin = getProjectManagerAdmin(self) today = datetime.datetime.now() data['project_url'] = project.absolute_url() data['generation_report_date'] = today.strftime('%m/%d/%Y %H:%M:%S') data['project_overview'] = { 'project_name': project.title, 'project_code': project.code, 'reporting_type': utils.getTranslatedMesuringFrequencyFromID(project.measuring_frequency).split(',')[0], 'reporting_period': { 'project_year': self.context.project_year, 'from': self.context.gwopa_year_phases[int(self.context.project_year) - 1]['start'], 'to': self.context.gwopa_year_phases[int(self.context.project_year) - 1]['end'] }, 'author_report': project_manager_admin[0]['fullname'], 'position_report': project_manager_admin[0]['position'], 'currency': utils.project_currency(self), 'water_operators': getProjectWaterOperators(project), # Array 'donors': getProjectDonors(project), # Array 'other_organizations': getProjectOtherOrganizations(project), # Array 'total_budget': "", 'project_location': { 'country': project.country, 'location': project.location }, 'project_duration': { 'start': project.startactual.strftime('%B %d, %Y'), 'end': project.completionactual.strftime('%B %d, %Y') }, 'association': { 'wop_platform': project.wop_platform, 'wop_program': project.wop_program }, 'project_description': project.objectives.output if hasattr(project.objectives, 'output') else '', 'project_image': project.absolute_url() + '/@@images/image' if project.image else None, 'logos': getLogosFirstpage(project), } data['project_overview']['total_budget'] = getTotalBudget( data['project_overview']['water_operators'] + data['project_overview']['donors'] + data['project_overview']['other_organizations']) totalBugdets = float(data['project_overview']['total_budget']) dataChartBudgets = {'chart': {'water_operators': {'series': [], 'colors': []}, 'donors': {'series': [], 'colors': []}, 'other_organizations': {'series': [], 'colors': []}}, 'legend': {'water_operators': [], 'donors': [], 'other_organizations': []}} pos = totalWO = 0 for wo in data['project_overview']['water_operators']: inkind = float(wo['inkind']) if 'inkind' in wo and wo['inkind'] else 0 incash = float(wo['incash']) if 'incash' in wo and wo['incash'] else 0 woValue = inkind + incash totalWO += woValue dataChartBudgets['chart']['water_operators']['series'].append(woValue) color = getHexColor(pos) pos += 1 dataChartBudgets['chart']['water_operators']['colors'].append(color) wo.update({'color': color}) dataChartBudgets['legend']['water_operators'].append(wo) dataChartBudgets['chart']['water_operators']['series'].append(totalBugdets - totalWO) dataChartBudgets['chart']['water_operators']['colors'].append('#F1F1F1') dataChartBudgets['chart']['donors']['series'].append(totalWO) dataChartBudgets['chart']['donors']['colors'].append('#F1F1F1') pos = totalDonors = 0 for donor in data['project_overview']['donors']: inkind = float(donor['inkind']) if 'inkind' in donor and donor['inkind'] else 0 incash = float(donor['incash']) if 'incash' in donor and donor['incash'] else 0 donorsValue = inkind + incash totalDonors += donorsValue dataChartBudgets['chart']['donors']['series'].append(donorsValue) color = getHexColor(pos) pos += 1 dataChartBudgets['chart']['donors']['colors'].append(color) donor.update({'color': color}) dataChartBudgets['legend']['donors'].append(donor) dataChartBudgets['chart']['donors']['series'].append(totalBugdets - totalWO - totalDonors) dataChartBudgets['chart']['donors']['colors'].append('#F1F1F1') dataChartBudgets['chart']['other_organizations']['series'].append(totalWO + totalDonors) dataChartBudgets['chart']['other_organizations']['colors'].append('#F1F1F1') pos = totalOO = 0 for oo in data['project_overview']['other_organizations']: inkind = float(oo['inkind']) if 'inkind' in oo and oo['inkind'] else 0 incash = float(oo['incash']) if 'incash' in oo and oo['incash'] else 0 ooValue = inkind + incash totalOO += ooValue dataChartBudgets['chart']['other_organizations']['series'].append(ooValue) color = getHexColor(pos) pos += 1 dataChartBudgets['chart']['other_organizations']['colors'].append(color) oo.update({'color': color}) dataChartBudgets['legend']['other_organizations'].append(oo) data['project_overview'].update({'chart_budget': dataChartBudgets['chart'], 'chart_budget_legend': dataChartBudgets['legend']}) working_areas = getWorkingAreas(project) data['summary'] = { 'working_areas': ", ".join([utils.getTranslatedWorkingAreaFromID(wa.id) for wa in working_areas]), 'progress': { 'roadblock': self.context.overall_project_status == 'roadblock', 'potential': self.context.overall_project_status == 'potential', 'ontrack': self.context.overall_project_status == 'ontrack', 'stakeholders': self.context.progress_stakeholders }, 'other': self.context.other_additional_challenges } data['activities_outputs'] = {} KEY = "GWOPA_TARGET_YEAR_" + str(self.context.project_year) for wa in working_areas: wa_title = utils.getTranslatedWorkingAreaFromID(wa.id) data['activities_outputs'].update({wa_title: { 'title': wa_title, 'activities': {}, }}) activities = getActivitiesWA(self, wa.getObject()) for activity in activities: activityObj = activity.getObject() activityAnn = IAnnotations(activityObj) activity_title = activityObj.title data['activities_outputs'][wa_title]['activities'].update({activity_title: { 'title': activity_title, 'start': activityObj.start.strftime('%m/%d/%Y'), 'completion': activityObj.end.strftime('%m/%d/%Y'), 'progress_tracker': { 'progress': activityAnn[KEY]['monitoring']['progress'] if 'progress' in activityAnn[KEY]['monitoring'] and activityAnn[KEY]['monitoring']['progress'] else 0, 'real': '100', 'measuring_unit': '%', 'style': '' }, 'description': { 'description': activityObj.description, 'planning': activityObj.initial_situation, 'explanation_progress': activityAnn[KEY]['monitoring']['explanation'] if 'explanation' in activityAnn[KEY]['monitoring'] else "", }, 'main_obstacles': { 'internal': 'obstacles' in activityAnn[KEY]['monitoring'] and 'Internal organizational' in activityAnn[KEY]['monitoring']['obstacles'], 'external': 'obstacles' in activityAnn[KEY]['monitoring'] and 'External environment' in activityAnn[KEY]['monitoring']['obstacles'], "wop_related": 'obstacles' in activityAnn[KEY]['monitoring'] and 'WOP project - related' in activityAnn[KEY]['monitoring']['obstacles'], }, 'main_contributing': { 'internal': 'contributing' in activityAnn[KEY]['monitoring'] and 'Internal organizational' in activityAnn[KEY]['monitoring']['contributing'], 'external': 'contributing' in activityAnn[KEY]['monitoring'] and 'External environment' in activityAnn[KEY]['monitoring']['contributing'], "wop_related": 'contributing' in activityAnn[KEY]['monitoring'] and 'WOP project - related' in activityAnn[KEY]['monitoring']['contributing'], }, 'explain_limiting': activityAnn[KEY]['monitoring']['limiting'] if 'limiting' in activityAnn[KEY]['monitoring'] else "", 'cosidetation_for_future': activityAnn[KEY]['monitoring']['consideration'] if 'consideration' in activityAnn[KEY]['monitoring'] else "", 'outputs': {} }}) progress = int(data['activities_outputs'][wa_title]['activities'][activity_title]['progress_tracker']['progress']) data['activities_outputs'][wa_title]['activities'][activity_title]['progress_tracker']['style'] = 'transform: translateX(' + str(progress - 100) + '%);' outputs = getOutputsActivity(self, activityObj) for output in outputs: outputObj = output.getObject() outputAnn = IAnnotations(outputObj) output_title = outputObj.title data['activities_outputs'][wa_title]['activities'][activity_title]['outputs'].update({output_title: { 'title': output_title, 'start': outputObj.start.strftime('%m/%d/%Y'), 'completion': outputObj.end.strftime('%m/%d/%Y'), 'progress_tracker': { 'progress': outputAnn[KEY]['planned'] if 'planned' in outputAnn[KEY] and outputAnn[KEY]['planned'] else 0, 'real': outputAnn[KEY]['real'] if 'real' in outputAnn[KEY] and outputAnn[KEY]['real'] else 0, 'measuring_unit': utils.getTranslatedMesuringUnitFromID(outputObj.measuring_unit), 'style': '' }, 'description': { 'description': outputObj.description, 'explanation_progress': outputAnn[KEY]['monitoring']['explanation'] if 'explanation' in outputAnn[KEY]['monitoring'] else "", }, 'main_obstacles': { 'internal': 'obstacles' in outputAnn[KEY]['monitoring'] and 'Internal organizational' in outputAnn[KEY]['monitoring']['obstacles'], 'external': 'obstacles' in outputAnn[KEY]['monitoring'] and 'External environment' in outputAnn[KEY]['monitoring']['obstacles'], "wop_related": 'obstacles' in outputAnn[KEY]['monitoring'] and 'WOP project - related' in outputAnn[KEY]['monitoring']['obstacles'], }, 'main_contributing': { 'internal': 'contributing' in outputAnn[KEY]['monitoring'] and 'Internal organizational' in outputAnn[KEY]['monitoring']['contributing'], 'external': 'contributing' in outputAnn[KEY]['monitoring'] and 'External environment' in outputAnn[KEY]['monitoring']['contributing'], "wop_related": 'contributing' in outputAnn[KEY]['monitoring'] and 'WOP project - related' in outputAnn[KEY]['monitoring']['contributing'], }, 'explain_limiting': outputAnn[KEY]['monitoring']['limiting'] if 'limiting' in outputAnn[KEY]['monitoring'] else "", 'cosidetation_for_future': outputAnn[KEY]['monitoring']['consideration'] if 'consideration' in outputAnn[KEY]['monitoring'] else "", 'means_of_verification': outputObj.means, }}) try: progress = int(float(data['activities_outputs'][wa_title]['activities'][activity_title]['outputs'][output_title]['progress_tracker']['real']) / float(data['activities_outputs'][wa_title]['activities'][activity_title]['outputs'][output_title]['progress_tracker']['progress']) * 100) except: progress = 0 data['activities_outputs'][wa_title]['activities'][activity_title]['outputs'][output_title]['progress_tracker']['style'] = 'transform: translateX(' + str(progress - 100) + '%);' data['outcomes'] = {'dash_info': getItems(project), 'list': {}} outcomes = getOutcomes(project) for outcome in outcomes: outcomeObj = outcome.getObject() annotations = IAnnotations(outcomeObj) outcome_title = getTranslatedOutcomesFromTitle(outcomeObj.title) data['outcomes']['list'].update({outcome_title: { 'title': outcome_title, 'zone': outcomeObj.zone, 'baseline_date': outcomeObj.baseline_date.strftime('%Y-%m'), 'baseline_value': outcomeObj.baseline, 'target_value_real': annotations[KEY]['real'] if 'real' in annotations[KEY] and annotations[KEY]['real'] else 0, 'target_value_planned': annotations[KEY]['planned'] if 'planned' in annotations[KEY] and annotations[KEY]['planned'] else 0, 'target_value_style': '', 'description': { 'description': outcomeObj.description, 'explanation_progress': annotations[KEY]['monitoring']['explanation'] if 'explanation' in annotations[KEY]['monitoring'] else "", }, 'main_obstacles': { 'internal': 'obstacles' in annotations[KEY]['monitoring'] and 'Internal organizational' in annotations[KEY]['monitoring']['obstacles'], 'external': 'obstacles' in annotations[KEY]['monitoring'] and 'External environment' in annotations[KEY]['monitoring']['obstacles'], "wop_related": 'obstacles' in annotations[KEY]['monitoring'] and 'WOP project - related' in annotations[KEY]['monitoring']['obstacles'], }, 'main_contributing': { 'internal': 'contributing' in annotations[KEY]['monitoring'] and 'Internal organizational' in annotations[KEY]['monitoring']['contributing'], 'external': 'contributing' in annotations[KEY]['monitoring'] and 'External environment' in annotations[KEY]['monitoring']['contributing'], "wop_related": 'contributing' in annotations[KEY]['monitoring'] and 'WOP project - related' in annotations[KEY]['monitoring']['contributing'], }, 'explain_contributed': annotations[KEY]['monitoring']['limiting'] if 'limiting' in annotations[KEY]['monitoring'] else "", 'consideration': annotations[KEY]['monitoring']['consideration'] if 'consideration' in annotations[KEY]['monitoring'] else "", 'means_of_verification': outcomeObj.means, # TODO ??? }}) try: progress = int(float(data['outcomes']['list'][outcome_title]['target_value_real']) / float(data['outcomes']['list'][outcome_title]['target_value_planned']) * 100) except: progress = 0 data['outcomes']['list'][outcome_title]['target_value_style'] = 'transform: translateX(' + str(progress - 100) + '%);' data['outcomes_capacity'] = {} for wa in working_areas: wa_title = utils.getTranslatedWorkingAreaFromID(wa.id) wa_object = wa.getObject() data['outcomes_capacity'].update({wa_title: { 'title': wa_title, 'getCurrentStage': getCurrentStage(wa_object, self.context.project_year), 'getOutcomeCC': getOutcomeCC(wa_object, self.context.project_year), 'capacities': {}, }}) outcomecc = getOutcomesCapacityWA(wa_object)[0] annotations = IAnnotations(outcomecc.getObject()) for capacity in annotations[KEY]['monitoring']: if 'selected' in capacity['selected_specific']: capacity_title = getTitleSpecific(capacity) data['outcomes_capacity'][wa_title]['capacities'].update({capacity_title: { 'title': capacity_title, 'degree_changes': capacity['degree_changes'] if 'degree_changes' in capacity and capacity['degree_changes'] else '', 'contributed_project': capacity['contributed_project'] if 'contributed_project' in capacity and capacity['contributed_project'] else '', 'consensus': capacity['consensus'] if 'consensus' in capacity and capacity['consensus'] else '', 'main_obstacles': { 'internal': 'obstacles' in capacity and 'Internal organizational' in capacity['obstacles'], 'external': 'obstacles' in capacity and 'External environment' in capacity['obstacles'], "wop_related": 'obstacles' in capacity and 'WOP project - related' in capacity['obstacles'], }, 'main_contributing': { 'internal': 'contributing_factors' in capacity and 'Internal organizational' in capacity['contributing_factors'], 'external': 'contributing_factors' in capacity and 'External environment' in capacity['contributing_factors'], "wop_related": 'contributing_factors' in capacity and 'WOP project - related' in capacity['contributing_factors'], }, 'explain': capacity['explain'], 'means_of_verification': "", # TODO ??? }}) data['budget'] = { 'planned_activities': {}, 'total_budget': "", } allActivities = api.content.find( portal_type=['Activity'], context=project) for activity in allActivities: title = '[' + getattr(activityObj.aq_parent, attr_lang.lower()) + '] ' + activity.Title activityObj = activity.getObject() data['budget']['planned_activities'].update({title: { 'title': title, 'wa_title': utils.getTranslatedWorkingAreaFromID(activityObj.aq_parent.id), 'act_title': activity.Title, 'assigned_budget': activityObj.budget }}) if not refresh: data['budget']['planned_activities'][title].update({'expenditure_reporting_period': ''}) data['budget']['planned_activities'][title].update({'total_expenditure_date': ''}) else: data['budget']['planned_activities'][title].update({'expenditure_reporting_period': self.context.save_data['budget']['planned_activities'][title]['expenditure_reporting_period'] if 'expenditure_reporting_period' in data['budget']['planned_activities'][title] else ''}) data['budget']['planned_activities'][title].update({'total_expenditure_date': self.context.save_data['budget']['planned_activities'][title]['total_expenditure_date'] if 'total_expenditure_date' in data['budget']['planned_activities'][title] else ''}) data['budget']['total_budget'] = getTotalAssignedBudget(data['budget']['planned_activities']) data['next_steps'] = self.context.next_steps self.context.save_data = data return data
def listOutcomesCC(self): items = api.content.find(portal_type=['OutcomeCC'], context=self.context) results = [] KEY = "GWOPA_TARGET_YEAR_" + str(self.year) for item in items: members = [] obj = item.getObject() annotations = IAnnotations(item.getObject()) base_value = '' base_date = '' description = '' objective = '' objective_date = '' target_value_planned = '' specifics = '' if KEY in annotations.keys(): if annotations[KEY] != '' or annotations[ KEY] is not None or annotations[KEY] != 'None': base_value = annotations[KEY]['generic'][0]['baseline'] base_date = annotations[KEY]['generic'][0]['baseline_date'] description = annotations[KEY]['generic'][0]['description'] objective = annotations[KEY]['generic'][0]['objective'] objective_date = annotations[KEY]['generic'][0][ 'objective_date'] target_value_planned = annotations[KEY]['planned'] specifics = annotations[KEY]['specifics'] if obj.members: users = obj.members if isinstance(users, (str, )): for member in users.split(','): user = api.user.get(username=member) if user: members.append(user.getProperty('fullname')) else: for member in users: user = api.user.get(username=member) if user: members.append(user.getProperty('fullname')) if obj.aq_parent.portal_type == 'ImprovementArea': area = getTranslatedWorkingAreaFromID(obj.aq_parent.id) else: area = getTranslatedWorkingAreaFromID( obj.aq_parent.aq_parent.id) results.append( dict(rid=item.getRID(), area=area, title=item.title, description=description, base_date=base_date, base_value=base_value, objective=objective, objective_date=objective_date, target_value_planned=target_value_planned, specifics=specifics, portal_type=item.portal_type, responsible=members, url='/'.join(obj.getPhysicalPath()))) return sorted(results, key=itemgetter('area'), reverse=False)