def execute(self): rtn = self._new_rtn() notebooks = NoteService.get_instance().fetch_notebooks(self._get_user_id()) std = stdModel() defaultnotebook = Notebook() defaultnotebook.uid = model.EMPTY_UID defaultnotebook.nb_name = i18n.get_i18n_message(conf.get_preferred_language(), "note_label_defaultnotebook") defaultnotebook.notecount = NoteService.get_instance().get_notecount(False, self._get_user_id(), notebook_id=model.EMPTY_UID) defaultnotebook.creator_id = self._get_user_id() notebooks.insert(0, defaultnotebook); trash = Notebook() trash.uid = -100 trash.nb_name = i18n.get_i18n_message(conf.get_preferred_language(), "note_label_recyclebin") trash.notecount = NoteService.get_instance().get_notecount(True, self._get_user_id()) trash.creator_id = self._get_user_id() notebooks.append(trash) std.notebooks = notebooks std.notecount = NoteService.get_instance().get_notecount(False, self._get_user_id()) std.contactGroups = ContactService.get_instance().fetch_my_groups(self._get_user_id()) stmnotebooks = NoteService.get_instance().fetch_notebooks(self._get_user_id(), sharetome=True) notebooks.extend(stmnotebooks) rtn.set_data(std) return rtn.to_json()
def execute(self): rtn = self._new_rtn() std = stdModel() select = self._get_bool_parameter("select", False) if not select: groups = ContactService.get_instance().fetch_groups(self._get_user_id()) std.groups = groups; defaultgroup = Group() defaultgroup.uid = model.EMPTY_UID defaultgroup.group_name = i18n.get_i18n_message(conf.get_preferred_language(), "cont_label_defaultgroup") defaultgroup.contactcount = ContactService.get_instance().get_contactcount(False, self._get_user_id(), group_id=model.EMPTY_UID) defaultgroup.creator_id = self._get_user_id() groups.insert(0, defaultgroup); trash = Group() trash.uid = -100 trash.group_name = i18n.get_i18n_message(conf.get_preferred_language(), "cont_label_recyclebin") trash.contactcount = ContactService.get_instance().get_contactcount(True, self._get_user_id()) trash.creator_id = self._get_user_id() groups.append(trash) stmgroups = ContactService.get_instance().fetch_groups(self._get_user_id(), sharetome=True) std.groups.extend(stmgroups) else: groups = ContactService.get_instance().fetch_groups(self._get_user_id(), withcontactcount=False) std.groups = groups; rtn.set_data(std) return rtn.to_json()
def _get_i18n_message(self, code, arguments): language = conf.get_preferred_language() if arguments is not None: for key, value in arguments.items(): if key == "label" or "label" in key: i1key = value value = i18n.get_i18n_message(language, i1key) value = i1key if value is None else value arguments[key] = value return i18n.get_i18n_message(language, code, arguments)
def get_worksheet_name(self, worksheet_id): if worksheet_id == None or int(worksheet_id) == model.EMPTY_UID: return i18n.get_i18n_message(conf.get_preferred_language(), "task_label_workbasket") name = cache.get(CACHESPACE_WORKSPACENAME, worksheet_id) if name != None: return name else: worksheet = self.get_worksheet(worksheet_id) name = worksheet.ws_name if worksheet is not None else '' cache.put(CACHESPACE_WORKSPACENAME, worksheet_id, name) return name
def execute(self): rtn = self._new_rtn() worksheets = TaskService.get_instance().fetch_worksheets(self._get_user_id()) std = stdModel() workbasket = Worksheet() workbasket.uid = model.EMPTY_UID workbasket.ws_name = i18n.get_i18n_message(conf.get_preferred_language(), "task_label_workbasket") workbasket.taskcount = TaskService.get_instance().get_taskcount(False, self._get_user_id(), worksheet_id=model.EMPTY_UID) workbasket.creator_id = self._get_user_id() worksheets.insert(0, workbasket) trash = Worksheet() trash.uid = -100 trash.ws_name = i18n.get_i18n_message(conf.get_preferred_language(), "task_label_recyclebin") trash.taskcount = TaskService.get_instance().get_taskcount(True, self._get_user_id()) trash.creator_id = self._get_user_id() worksheets.append(trash) std.worksheets = worksheets std.contactGroups = ContactService.get_instance().fetch_my_groups(self._get_user_id()) stmworksheets = TaskService.get_instance().fetch_worksheets(self._get_user_id(), sharetome=True) std.worksheets.extend(stmworksheets) std.worksheetComponents = {} std.worksheetVersions = {} std.worksheetContacts = {} for worksheet in std.worksheets: if worksheet.group_id != None and worksheet.group_id != model.EMPTY_UID: std.worksheetComponents[worksheet.key()] = ContactService.get_instance().fetch_groupcomponents(worksheet.group_id) std.worksheetVersions[worksheet.key()] = ContactService.get_instance().fetch_groupversions(worksheet.group_id) std.worksheetContacts[worksheet.key()] = ContactService.get_instance().fetch_contacts_by_group(worksheet.group_id) else: myself = ContactService.get_instance().get_myself(self._get_user_id()) if myself is not None: std.worksheetContacts[worksheet.key()] = [myself] rtn.set_data(std) return rtn.to_json()
def execute(self): web.header("Content-Type", "application/x-javascript") translations = {} langs = conf.get_supported_languages() for lang in langs: results = i18n.fetch_i18ns(locale=lang, return_dic=True) translations[lang] = results js = "var I18N = {" js += "translations : %s," % jsonutil.to_json(translations) js += "defaultLanguage : '%s'" % conf.get_preferred_language() js += "};" js += "var G_VERSION='%s';" % conf.G_VERSION js += "var EMPTY_UID=%d;" % model.EMPTY_UID js += "var LOGIN_USER=%s;" % jsonutil.to_json(session.get_token().to_dict()) js += conf.dynamicjs_hook() return js
def get_plan_progress(self): planprogress = 'NA' if self.due_finishdate is not None and self.due_startdate is not None: starttime = self.due_startdate finishtime = self.due_finishdate plantd = finishtime - starttime + timedelta(days=1) now = dtutil.localtoday(conf.get_preferred_timezone()) nowtd = now - starttime if starttime < now : if plantd.total_seconds() != 0: planprogress = round(nowtd.total_seconds() / plantd.total_seconds(), 3) * 100 if planprogress > 100: ps = round(plantd.total_seconds() * (planprogress - 100) / (100 * 60 * 60 * 24), 1) planprogress = "100%%+%0.0f%s" % (ps, i18n.get_i18n_message(conf.get_preferred_language(), "core_label_day")) else: planprogress = "%0.0f%%" % planprogress else: planprogress = "100%" else: planprogress = "0%" self.planProgress = planprogress return planprogress
def get_progress_data(self, user_id, start_date, end_date, worksheet_ids, group_id=None, assignee_ids=None): if worksheet_ids is None or len(worksheet_ids) == 0: raise RequiredError("task_label_worksheet") if start_date is None: raise RequiredError(label="rept_label_startdate") if end_date is None: raise RequiredError(label="rept_label_enddate") if end_date <= start_date: raise CompareError( label="rept_label_enddate", limitlabel="rept_label_startdate", limit=start_date, operator=">" ) today = dtutil.localtoday(conf.get_preferred_timezone()) finishtaskcount = 0 progressLine = stdModel(plan={}, actual={}, forecast={}) progressBar = {} for priority in i18n.get_i18n_messages( conf.get_preferred_language(), "task_priority_code", rtn_dict=True ).keys(): statusTaskCount = [0, 0, 0] # planFinishCount, actualFinishCount, cancelCount progressBar[priority] = statusTaskCount rtn = stdModel(progressLine=progressLine, progressBar=progressBar, deviationTasks=[]) dates = self.get_workdates(start_date, end_date, group_id) for date in dates: progressLine.plan[date] = [date, 0] # [date, finish count] if date <= today: progressLine.actual[date] = [date, 0] # [date, finish count] else: progressLine.forecast[date] = [date, 0] # [date, finish count] tasks = self.fetch_tasks(user_id, None, worksheet_ids, assignee_ids) for task in tasks: for date, planstd in progressLine.plan.items(): if date <= today and task.t_status_code == "task_code_closed" and task.actual_finishdate <= date: progressLine.actual[date][1] += 1 if task.due_finishdate <= date and task.t_status_code != "task_code_cancel": planstd[1] += 1 if task.t_status_code != "task_code_closed" and task.t_status_code != "task_code_cancel": progress = task.get_plan_progress_int() if progress > task.actual_progress: task.deviationStatus = "rept_label_deviationdelay" elif progress < task.actual_progress: task.deviationStatus = "rept_label_deviationadvance" if progress != task.actual_progress: task.assigneeName = ContactService.get_instance().get_contact_name(task.assignee_id) comments = TaskService.get_instance().fetch_taskcomments(task.key(), limit=1) task.lastComment = comments[0].tc_content if len(comments) > 0 else "" rtn.deviationTasks.append(task) else: if ( task.t_status_code == "task_code_closed" and task.actual_startdate >= start_date and task.actual_finishdate <= today ): finishtaskcount += 1 statusTaskCount = progressBar[task.t_priority_code] if task.due_finishdate <= end_date: if task.t_status_code == "task_code_cancel": statusTaskCount[2] += 1 else: statusTaskCount[0] += 1 if task.t_status_code == "task_code_closed": statusTaskCount[1] += 1 speed = finishtaskcount / float(self.get_workdays(start_date, today, None, None)) for date, forestd in progressLine.forecast.items(): forestd[1] = finishtaskcount + speed * ((date - today).days + 1) if end_date > today: progressLine.forecast[today] = [today, float(progressLine.actual[today][1])] progressLine.plan = progressLine.plan.values() progressLine.actual = progressLine.actual.values() progressLine.forecast = progressLine.forecast.values() return rtn
def get_allocation_data(self, user_id, group_id, start_date, end_date, worksheet_ids, assignee_ids): if group_id is None: raise RequiredError(label="cont_label_group") if start_date is None: raise RequiredError(label="rept_label_startdate") if end_date is None: raise RequiredError(label="rept_label_enddate") if worksheet_ids is None or len(worksheet_ids) == 0: raise RequiredError(label="task_label_worksheet") if assignee_ids is None or len(assignee_ids) == 0: raise RequiredError(label="rept_label_assignee") assignee_linedata = {} for assignee_id in assignee_ids: std = stdModel() std.assigneeName = ContactService.get_instance().get_contact_name(assignee_id) std.totalTaskCount = 0 std.totalTaskDays = 0 std.statusTaskCounts = {} for status in i18n.get_i18n_messages( conf.get_preferred_language(), "task_status_code", rtn_dict=True ).keys(): std.statusTaskCounts[status] = 0 std.plan = {} dates = self.get_workdates(start_date, end_date, group_id) for date in dates: std.plan[date] = [date, 0] # [date, finish count] assignee_linedata[assignee_id] = std tasks = self.fetch_tasks(user_id, group_id, worksheet_ids, assignee_ids) for task in tasks: assigneedata = assignee_linedata[task.assignee_id] for date, plan in assigneedata.plan.items(): if task.due_startdate <= date and date <= task.due_finishdate: plan[1] += 1 if task.due_finishdate <= end_date and task.due_startdate >= start_date: assigneedata.totalTaskCount += 1 assigneedata.totalTaskDays += self.get_workdays( task.due_startdate, task.due_finishdate, group_id, task.assignee_id ) assigneedata.statusTaskCounts[task.t_status_code] += 1 sum1 = stdModel(totalTaskCount=0, totalTaskDays=0, totalWorkdays=0, totalIdleDays=0, totalBusyDays=0) for assignee_id, ad in assignee_linedata.items(): ad.plan = ad.plan.values() idleDates = [] busyDates = [] for p in ad.plan: if p[1] == 0: idleDates.append(p[0]) elif p[1] >= 2: busyDates.append(p[0]) ad.idlePeriod = self.get_period(idleDates, group_id, assignee_id) ad.busyPeriod = self.get_period(busyDates, group_id, assignee_id) ad.totalWorkdays = self.get_workdays(start_date, end_date, group_id, assignee_id) sum1.totalTaskCount += ad.totalTaskCount sum1.totalTaskDays += ad.totalTaskDays sum1.totalWorkdays += ad.totalWorkdays sum1.totalIdleDays += ad.idlePeriod.totalDays sum1.totalBusyDays += ad.busyPeriod.totalDays std = stdModel() std.details = assignee_linedata.values() std.sum = sum1 return std