示例#1
0
    def __call__(self, router_parse, sender, allow_group):
        """
        发送周报邮件的命令

        Arguments:
            router_parse {urlparse} -- url parse 解析出来的 router
            sender {string} -- 由谁发出的发送邮件指令
        """
        if allow_group == '1' and not User.check_user_group_id(
                sender, allow_group):
            return u'恭喜您没有权限。哈哈哈哈。'

        path = router_parse.path
        query = router_parse.query
        query_dict = parse_query_2_dict(query)
        msg = None
        if path == '/create':
            report = WeekReporter(name=sender, \
                next_week=query_dict.get('todo', u'继续完成相应需求'), \
                title=query_dict.get('title'), \
                desc=query_dict.get('desc'))
            msg = report.create_report()
        else:
            w_pr = Report.query_weekly_report(sender)
            if not w_pr:
                return u'%s:本周周报还未创建' % sender
            elif path == '/review':
                report_fix = w_pr.fix_report if w_pr.fix_report \
                    else w_pr.origin_report
                msg = u'周报标题:%s、描述:%s。\n%s\n下周任务:%s' \
                    % (w_pr.project_title, w_pr.description, \
                        report_fix, w_pr.next_week_todo)
            elif path == '/check':
                w_pr.report_checked()
                msg = u'%s:可以发送周报啦' % sender
            elif path == '/send':
                if w_pr.checked:
                    w_mail = WeeklyMail()
                    msg = w_mail.build_weekly_report_html(sender)
                else:
                    msg = u'%s:请确认周报无误后再发送' % sender
            elif path == '/update':
                msg = w_pr.update_report(done=query_dict.get('done'), \
                    todo=query_dict.get('todo'), title=query_dict.get('title'), \
                    desc=query_dict.get('desc'))
        return msg if msg else WeeklyCommand.helper_info()
示例#2
0
    def build_weekly_report_html(self, sender):
        with open(self.report_template_path, 'r') as f:
            html = unicode(f.read(), "utf-8")
            user = User.query_user(sender)
            report = Report.query_weekly_report(sender)

            if user and report:
                week_duration = Report.week_date_duration()
                html = html.replace(self.reporter_name_replacement, user.realname)
                html = html.replace(self.weekly_title_replacement, report.project_title)
                html = html.replace(self.weekly_description_replacement, report.description)
                html = html.replace(self.weekly_date_replacement, week_duration)
                contents = report.origin_report.splitlines()

                self.subject = u'工作周报-%s-技术-尚武研-员工平台-iOS-%s' \
                    % (user.realname, week_duration)
                self.sender_from = user.email
                self.sender_password = user.password

                finish_contents = u''
                for content in contents:
                    if content.startswith('-'):
                        header = self.content_header_p
                        header = header.replace(self.content_header_replacement, \
                            u'%s' % content[1:])
                        finish_contents += header
                    else:
                        body = self.content_body_p
                        body = body.replace(self.content_body_replacement, content)
                        finish_contents += body
                html = html.replace(self.weekly_finish_replacement, finish_contents)
                todo_texts = report.next_week_todo.split(u',')

                next_week_todo = u''
                for todo in todo_texts:
                    new_todo = self.content_body_p
                    new_todo = new_todo.replace(self.content_body_replacement, todo)
                    next_week_todo += new_todo
                html = html.replace(self.weekly_todo_replacement, next_week_todo)
                return self.send(html)
            else:
                return u'用户 %s 不存在或者本周周报还未生成' % sender