def handle(self, options, global_options, *args): from uliweb.orm import get_model from uliweb.core.SimpleFrame import get_app_dir if not options.test: if not options.skip_warning: message = """This command will delete all workflow specs, are you sure to do?""" get_answer(message) self.get_application(global_options) if not options.test: clear() print "" apps_list = self.get_apps(global_options) tasks, workflows = loadspec(apps_list, global_options) from uliweb.orm import get_model from uliweb.utils.common import Serial WorkflowSpec = get_model('workflow_spec') TaskSpec = get_model('task_spec') if not options.test: for name in tasks: task, file = tasks[name] spec = TaskSpec(name=name, content=Serial.dump(task), source=file) spec.save() for name in workflows: workflow, file = workflows[name] spec = WorkflowSpec(name=name, content=Serial.dump(workflow), source=file) spec.save()
def serialize(self): from uliweb.orm import get_model from uliweb.utils.common import Serial WF = get_model('workflow') data = { 'spec_name' : self.spec.name, 'state' : self.state, 'data' : Serial.dump(self.data), 'desc' : self.spec.desc, 'ref_unique_id' : self.ref_unique_id, } #DEBUG ------------------------- if __DEBUG__: print 'workflow serialize -----------------------------(1)' for i in data: print (i, data[i]) print 'spec_name: %s' % self.spec.name print 'state: %s' % self.state print 'workflow serialize -----------------------------(2)' #DEBUG if self.obj: if self.operator: data.update({'modified_user': self.operator}) self.obj.update(**data) else: if self.operator: data.update({'modified_user': self.operator}) data.update({'created_user': self.operator}) self.obj = WF(**data) self.obj.save()
def get_menu(cls, parent): from uliweb import functions, settings from uliweb.utils.common import Serial def _f(_p): menus = [] for row in cls.filter(cls.c.parent == _p, cls.c.type == 'M0000', cls.c.deploy_type == 'F', cls.c.status == '00001').order_by( cls.c.order): item = row.to_dict() item['link'] = row.value item['permissions'] = [x.name for x in row.permissions] menus.append(item) if row.has_children: item['subs'] = _f(item.id) else: item['subs'] = [] return menus menus = [] use_redis = settings.get_var('RESOURCE/USE_REDIS') key = 'MENU:{}'.format(parent) if use_redis: redis = functions.get_redis() v = redis.get(key) if v: menus = Serial.load(v) if not menus: p = cls.get(cls.c.name == parent) menus = _f(p.id) if menus and use_redis: redis.set(key, Serial.dump(menus)) return menus
def post_save(obj, data): from uliweb import functions from uliweb.utils.common import Serial from uliweb.mail import Mail Topic.filter(Topic.c.id==int(topic_id)).update(num_replies=Topic.c.num_replies+1, last_post_user=request.user.id, last_reply_on=date.now()) Forum.filter(Forum.c.id==int(forum_id)).update(num_posts=Forum.c.num_posts+1, last_post_user=request.user.id, last_reply_on=date.now()) self._clear_files(obj.slug, data['content']) #増加发送邮件的处理 emails = [] for u_id in Post.filter((Post.c.topic==int(topic_id)) & (Post.c.reply_email==True) & (Post.c.floor<obj.floor)).values(Post.c.posted_by): user = User.get(u_id[0]) if user and user.email and (user.email not in emails) and (user.email!=request.user.email): emails.append(user.email) if not emails: return _type = settings.get_var('PARA/FORUM_REPLY_PROCESS', 'print') url = '%s/forum/%s/%s' % (settings.get_var('PARA/DOMAIN'), forum_id, topic_id) d = {'url':str(url)} mail = {'from_':settings.get_var('PARA/EMAIL_SENDER'), 'to_':emails, 'subject':settings.get_var('FORUM_EMAIL/FORUM_EMAIL_TITLE'), 'message':settings.get_var('FORUM_EMAIL/FORUM_EMAIL_TEXT') % d, 'html':True} if _type == 'mail': Mail().send_mail(**mail) elif _type == 'print': print mail elif _type == 'redis': redis = functions.get_redis() _t = Serial.dump(mail) redis.lpush('send_mails', _t)
def serialize(self): from uliweb.orm import get_model from uliweb.utils.common import Serial WF = get_model("workflow") data = { "spec_name": self.spec.name, "state": self.state, "data": Serial.dump(self.data), "desc": self.spec.desc, "ref_unique_id": self.ref_unique_id, } # DEBUG ------------------------- if __DEBUG__: print "workflow serialize -----------------------------(1)" for i in data: print (i, data[i]) print "spec_name: %s" % self.spec.name print "state: %s" % self.state print "workflow serialize -----------------------------(2)" # DEBUG if self.obj: if self.operator: data.update({"modified_user": self.operator}) self.obj.update(**data) else: if self.operator: data.update({"modified_user": self.operator}) data.update({"created_user": self.operator}) self.obj = WF(**data) self.obj.save()
def serialize(self): from uliweb.orm import get_model from uliweb.utils.common import Serial WF = get_model('workflow') data = { 'spec_name' : self.spec.name, 'state' : self.state, 'data' : Serial.dump(self.data), 'desc' : self.spec.desc, } #DEBUG ------------------------- if __DEBUG__: for i in data: print (i, data[i]) print 'spec_name: %s' % self.spec.name print 'state: %s' % self.state #DEBUG if self.obj: if self.operator: data.update({'modified_user': self.operator}) self.obj.update(**data) else: if self.operator: data.update({'modified_user': self.operator}) data.update({'created_user': self.operator}) self.obj = WF(**data) self.obj.save()
def process_exception(self, request, e): from uliweb import settings import traceback from uliweb.mail import Mail from uliweb.utils.common import Serial from uliweb.core.SimpleFrame import HTTPError, HTTPException, NotFound if isinstance(e, (HTTPError, NotFound, HTTPException)): return type, value, tb = sys.exc_info() txt = "".join(traceback.format_exception(type, value, tb)) if settings.GLOBAL.EXCEPTION_PROCESS_TYPE == "mail": Mail().send_mail( settings.get_var("PARA/EMAIL_SENDER"), settings.get_var("PARA/DEV_TEAM"), u"程序运行出错:" + request.path, txt ) elif settings.GLOBAL.EXCEPTION_PROCESS_TYPE == "print": print txt elif settings.GLOBAL.EXCEPTION_PROCESS_TYPE == "redis": mail = { "from": settings.get_var("PARA/EMAIL_SENDER"), "to": settings.get_var("PARA/DEV_TEAM"), "title": u"程序运行出错" + request.url, "message": txt, } _t = Serial.dump(mail) self.redis.lpush("send_mails", _t)
def handle(self, options, global_options, *args): apps_list = self.get_apps(global_options) self.get_application(global_options) tasks, workflows = loadspec(apps_list, global_options) print "\n" from uliweb.orm import get_model from uliweb.utils.common import Serial WorkflowSpec = get_model('workflow_spec') TaskSpec = get_model('task_spec') for name in tasks: find = TaskSpec.get(TaskSpec.c.name == name) task, file = tasks[name] if not find: spec = TaskSpec(name=name, content=Serial.dump(task), source=file) spec.save() else: if global_options.verbose: print "[WARNING] Task Spec %s is existed, will be udated." % name find.update(content=Serial.dump(task), source=file) find.save() for name in workflows: find = WorkflowSpec.get(WorkflowSpec.c.name == name) workflow, file = workflows[name] if not find: spec = WorkflowSpec(name=name, content=Serial.dump(workflow), source=file) spec.save() else: if global_options.verbose: print "[WARNING] Workflow Spec %s is existed, will be updated." % name find.update(content=Serial.dump(workflow), source=file) find.save()
def post_save(obj, data): from uliweb import functions from uliweb.utils.common import Serial from uliweb.mail import Mail Post.filter(Post.c.id == int(parent_id)).update( num_replies=Post.c.num_replies + 1, last_post_user=request.user.id, last_reply_on=date.now()) self._clear_files(obj.slug, data['content']) Topic.filter(Topic.c.id == int(topic_id)).update( num_replies=Topic.c.num_replies + 1, last_post_user=request.user.id, last_reply_on=date.now(), last_post=obj.id) Forum.filter(Forum.c.id == int(forum_id)).update( num_posts=Forum.c.num_posts + 1, last_post_user=request.user.id, last_reply_on=date.now(), last_post=obj.id) #増加发送邮件的处理 emails = [] for u_id in Post.filter((Post.c.topic == int(topic_id)) & (Post.c.reply_email == True) & (Post.c.id == parent_id)).values( Post.c.posted_by): user = User.get(u_id[0]) if user and user.email and (user.email not in emails) and ( user.email != request.user.email): emails.append(user.email) if not emails: return _type = settings.get_var('PARA/FORUM_REPLY_PROCESS', 'print') url = '%s/forum/%s/%s' % (settings.get_var('PARA/DOMAIN'), forum_id, topic_id) d = {'url': str(url)} mail = { 'from_': settings.get_var('PARA/EMAIL_SENDER'), 'to_': emails, 'subject': settings.get_var('FORUM_EMAIL/FORUM_EMAIL_TITLE'), 'message': settings.get_var('FORUM_EMAIL/FORUM_EMAIL_TEXT') % d, 'html': True } if _type == 'mail': Mail().send_mail(**mail) elif _type == 'print': print mail elif _type == 'redis': redis = functions.get_redis() _t = Serial.dump(mail) redis.lpush('send_mails', _t)
def post_save(obj, data): from uliweb import functions from uliweb.utils.common import Serial from uliweb.mail import Mail Post.filter(Post.c.id == int(parent_id)).update( num_replies=Post.c.num_replies + 1, last_post_user=request.user.id, last_reply_on=date.now() ) self._clear_files(obj.slug, data["content"]) Topic.filter(Topic.c.id == int(topic_id)).update( num_replies=Topic.c.num_replies + 1, last_post_user=request.user.id, last_reply_on=date.now(), last_post=obj.id, ) Forum.filter(Forum.c.id == int(forum_id)).update( num_posts=Forum.c.num_posts + 1, last_post_user=request.user.id, last_reply_on=date.now(), last_post=obj.id, ) # 増加发送邮件的处理 emails = [] for u_id in Post.filter( (Post.c.topic == int(topic_id)) & (Post.c.reply_email == True) & (Post.c.id == parent_id) ).values(Post.c.posted_by): user = User.get(u_id[0]) if user and user.email and (user.email not in emails) and (user.email != request.user.email): emails.append(user.email) if not emails: return _type = settings.get_var("PARA/FORUM_REPLY_PROCESS", "print") url = "%s/forum/%s/%s" % (settings.get_var("PARA/DOMAIN"), forum_id, topic_id) d = {"url": str(url)} mail = { "from_": settings.get_var("PARA/EMAIL_SENDER"), "to_": emails, "subject": settings.get_var("FORUM_EMAIL/FORUM_EMAIL_TITLE"), "message": settings.get_var("FORUM_EMAIL/FORUM_EMAIL_TEXT") % d, "html": True, } if _type == "mail": Mail().send_mail(**mail) elif _type == "print": print mail elif _type == "redis": redis = functions.get_redis() _t = Serial.dump(mail) redis.lpush("send_mails", _t)
def handle(self, options, global_options, *args): apps_list = self.get_apps(global_options) self.get_application(global_options) tasks, workflows = loadspec(apps_list, global_options) print "\n" from uliweb.orm import get_model from uliweb.utils.common import Serial WorkflowSpec = get_model('workflow_spec') TaskSpec = get_model('task_spec') for name in tasks: find = TaskSpec.get(TaskSpec.c.name==name) task, file = tasks[name] if not find: spec = TaskSpec(name=name, content=Serial.dump(task), source=file) spec.save() else: if global_options.verbose: print "[WARNING] Task Spec %s is existed, will be udated." % name find.update(content=Serial.dump(task), source=file) find.save() for name in workflows: find = WorkflowSpec.get(WorkflowSpec.c.name==name) workflow, file = workflows[name] if not find: spec = WorkflowSpec(name=name, content=Serial.dump(workflow), source=file) spec.save() else: if global_options.verbose: print "[WARNING] Workflow Spec %s is existed, will be updated." % name find.update(content=Serial.dump(workflow), source=file) find.save()
def process(): from datetime import timedelta, datetime from uliweb.utils.common import Serial Request = functions.get_model('eventrequest') Event = functions.get_model('event') User = functions.get_model('user') #day = date.today() - timedelta(days=2) day = datetime(year=2013, month=3, day=24) redis = functions.get_redis() for obj in Request.filter((Request.c.event==Event.c.id) & (Event.c.begin_date==day) & (Request.c.user==User.c.id)).values(User.c.username, User.c.email, Event.c.title) : email = {} email['from_'] = 'codepark' email['to_'] = obj.email email['subject'] = u'活动通知' email['message'] = u'用户:%s 活动"%s"将于%s开始' % (obj.username, obj.title, date.today()) message = Serial.dump(email) print 'xxxxxxxxxxxxx', message redis.lpush('sendmail', message)
def process_exception(self, request, e): from uliweb import settings import traceback from uliweb.mail import Mail from uliweb.utils.common import Serial from uliweb.core.SimpleFrame import HTTPError, HTTPException, NotFound if isinstance(e, (HTTPError, NotFound, HTTPException)): return type, value, tb = sys.exc_info() txt = ''.join(traceback.format_exception(type, value, tb)) if settings.GLOBAL.EXCEPTION_PROCESS_TYPE == 'mail': Mail().send_mail(settings.get_var('PARA/EMAIL_SENDER'), settings.get_var('PARA/DEV_TEAM'), u'程序运行出错:' + request.path, txt) elif settings.GLOBAL.EXCEPTION_PROCESS_TYPE == 'print': print txt elif settings.GLOBAL.EXCEPTION_PROCESS_TYPE == 'redis': mail = {'from':settings.get_var('PARA/EMAIL_SENDER'), 'to':settings.get_var('PARA/DEV_TEAM'), 'title':u'程序运行出错' + request.url, 'message':txt} _t = Serial.dump(mail) self.redis.lpush('send_mails', _t)
def serialize(self): if not self.killed: from uliweb.orm import get_model from uliweb.utils.common import Serial import datetime WFTask = get_model('workflow_task') #data for deliver self.set_data('deliver_msg', self.deliver_msg) self.set_data('operator', self.operator) self.set_data('next_tasks', self.next_tasks) data = { 'workflow' : self.workflow.obj.id, 'state' : self.state, 'spec_name' : self.get_spec_name(), 'alias_name' : self.get_name(), 'desc' : self.get_desc(), 'uuid' : self.uuid, 'data' : Serial.dump(self.data), } now = datetime.datetime.now() if self.obj: if self.operator: data.update({'modified_user': self.operator}) data.update({'modified_date': now}) self.obj.update(**data) else: if self.operator: data.update({'modified_user': self.operator}) data.update({'modified_date': now}) data.update({'created_user': self.operator}) self.obj = WFTask(**data) self.obj.save()
def serialize(self): if not self.killed: from uliweb.orm import get_model from uliweb.utils.common import Serial import datetime WFTask = get_model("workflow_task") # data for deliver self.set_data("deliver_msg", self.deliver_msg) self.set_data("operator", self.operator) self.set_data("next_tasks", self.next_tasks) data = { "workflow": self.workflow.obj.id, "state": self.state, "spec_name": self.get_spec_name(), "alias_name": self.get_name(), "desc": self.get_desc(), "uuid": self.uuid, "data": Serial.dump(self.data), } now = datetime.datetime.now() if self.obj: if self.operator: data.update({"modified_user": self.operator}) data.update({"modified_date": now}) self.obj.update(**data) else: if self.operator: data.update({"modified_user": self.operator}) data.update({"modified_date": now}) data.update({"created_user": self.operator}) self.obj = WFTask(**data) self.obj.save()