Esempio n. 1
0
class WorkMailSendHandler(APIHandler):
    model = models.MailModel()

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        try:
            result = utils.init_response_data()
            client = tornado.httpclient.AsyncHTTPClient()
            response = yield tornado.gen.Task(
                client.fetch, "http://120.26.226.63:20000/works")
            response_body = json.loads(response.body)
            data = response_body.get("data", {})
            works = data.get("works", [])

            t_s = open(
                os.path.dirname(options.root_path) + "/var/mail/工作日报.xls", "r")
            t_s_data = t_s.read()
            t_s.close()
            to_email = ["*****@*****.**"]
            for work in works:
                filename = os.path.dirname(options.root_path) + "/var/mail/工作日报%s.xls"%( str(datetime.datetime.now()).\
                                                                             replace(".","_").replace(":","_").replace(" ","_") )
                w_d = open(filename, "w")
                w_d.write(t_s_data)
                w_d.close()

                copy_data = [
                    (4, 1, work.get("name", "")),
                    (4, 2, work.get("hr_analytic_timesheet_id")[1]),
                ]
                curr_time = datetime.datetime.now()
                title = "东汇集团胜众科技有限公司征信项目组%s%s年%s月%s日工作日报" % (
                    work.get("user_id")[1], curr_time.year, curr_time.month,
                    curr_time.day)
                reportlib.copy_xls(filename, title, data=copy_data)
                attachments = []
                attachments.append(dict(
                    filename=u"工作日报.xls",
                    data=filename,
                ))
                from_email = "*****@*****.**"
                send_email(from_email,
                           to_email,
                           "工作日报",
                           '',
                           html='',
                           attachments=attachments)

                result["data"] = works
        except Exception, e:
            result = utils.reset_response_data(0, str(e))
            self.write(result)
            self.finish()
            return

        self.finish(result)
Esempio n. 2
0
class WorkHandler(APIHandler):
    model = models.MailModel()

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        try:
            result = utils.init_response_data()
            client = tornado.httpclient.AsyncHTTPClient()
            response = yield tornado.gen.Task(
                client.fetch, "http://120.26.226.63:20000/works")
            response_body = json.loads(response.body)
            data = response_body.get("data", {})
            works = data.get("works", [])
            curr_time = str(datetime.datetime.now()).split(" ")[0]
            start_time = curr_time + " " + "00:00:00.000"
            end_time = curr_time + " " + "23:59:59.999"
            result["data"] = []
            for work in works:
                username = work.get("user_id")[1]
                obj = self.model.coll.find_one({
                    "name": username,
                    "add_time": {
                        "$gte": start_time,
                        "$lte": end_time,
                    },
                })
                if obj:
                    continue
                else:
                    obj = {}
                    obj["name"] = username
                    obj["work"] = work.get("name", "")
                    obj["work_desc"] = work.get("hr_analytic_timesheet_id")[1]
                    self.model.create(**obj)
                    result["data"].append(obj)

        except Exception, e:
            result = utils.reset_response_data(0, str(e))
            self.write(result)
            self.finish()
            return

        self.finish(result)
Esempio n. 3
0
class MailSendHandler(APIHandler):
    model = models.MailModel()

    def post(self):
        result = utils.init_response_data()
        try:
            to_mail_list = json.loads(self.get_argument("to_mail_list", "[]"))
            theme = self.get_argument("theme", "工作日报")
            template = self.get_argument("template", "default")
            template_args = json.loads(self.get_argument(
                "template_args", "{}"))
            content = self.generate(template, template_args)
            attachments = []
            request_files = self.request.files
            if request_files.has_key("files"):
                files = request_files["files"]
                for file in files:
                    filename = file.get("filename", "")
                    temp_filename_path = os.path.dirname(options.root_path).encode("utf-8") + u"/var/mail/" + filename + u"_" +\
                                         str(datetime.datetime.now()).replace(".","_").replace(":","_").replace(" ","_") + ".xls"
                    temp_mail_file = open(temp_filename_path, "w")
                    temp_mail_file.write(file.get("body", ""))
                    attachments.append(
                        dict(
                            filename=u"工作日报.xls",
                            data=temp_filename_path,
                        ))
            print attachments
            send_email('*****@*****.**',
                       to_mail_list,
                       theme,
                       '',
                       html=content,
                       attachments=attachments)

        except Exception, e:
            result = utils.reset_response_data(0, str(e))
            self.write(result)
            self.finish()
            return
        self.finish(result)
Esempio n. 4
0
class MailRetrieveUpdateDestroyHandler(RetrieveUpdateDestroyAPIHandler):
    model = models.MailModel()
Esempio n. 5
0
class MailListCreateHandler(ListCreateAPIHandler):
    model = models.MailModel()