コード例 #1
0
ファイル: views.py プロジェクト: Kevin-Sun/codepark
 def add(self):
     from forms import AddForm
     from uliweb.utils import date
     
     def pre_save(data):
         data['creator'] = request.user.id
         
     d = {}
     d['begin_date'] = date.today()
     d['begin_time'] = date.to_time('9:00')
     d['end_date'] = date.today()
         
     view = functions.AddView(self.model, form_cls=AddForm, data=d,
         ok_url=url_for(self.__class__.index), pre_save=pre_save)
     return view.run()
コード例 #2
0
ファイル: views.py プロジェクト: chu888chu888/uliweb-codepark
 def add(self):
     from uliweb.utils import date
     from forms import AddForm
     
     form = AddForm()
     if request.method == 'GET':
         today = date.today()
         form.bind({'begin_date':today})
         return {'form':form}
     elif request.method == 'POST':
         #对提交的数据进行校验
         if form.validate(request.POST):
             obj = self.model(**form.data)
             obj.save()
             return redirect(url_for(self.__class__.index))
         else:
             return {'form':form}
コード例 #3
0
ファイル: prepare.py プロジェクト: Kevin-Sun/codepark
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)
コード例 #4
0
ファイル: daemon.py プロジェクト: limodou/uliweb-apps
def parse_command(row):
    """
    解析命令格式,支持函数式 a.b() 和 普通的shell命令行
    :param row:
    :return:
    """
    from uliweb.utils import date

    def f(*args, **kwargs):
        return args, kwargs

    d = {
        'status':'0',
        'message':'',
        'command':row.command,
        'parameters':{},
    }
    b = r_function.match(row.command)
    if b:
        env = {'TODAY':date.today(), 'NOW':date.now(), 'f':f}
        d['command'] = b.group(1)
        para = b.group(2)
        para = os.path.expandvars(para)
        try:
            d['parameters'] = {}
            v = eval('f({})'.format(para), env)
            d['parameters']['_args'] = v[0]
            d['parameters'].update(v[1])
        except Exception as e:
            log.exception(e)
            d['status'] = 'F'
            d['message'] = 'Eval parameter {} error'.format(b.group(2))
    else:
        d['command'] = 'shell'
        d['parameters'] = {'cmd':row.command, 'cwd':row.work_directory}
    return d
コード例 #5
0
def parse_command(row):
    """
    解析命令格式,支持函数式 a.b() 和 普通的shell命令行
    :param row:
    :return:
    """
    from uliweb.utils import date

    def f(*args, **kwargs):
        return args, kwargs

    d = {
        'status': '0',
        'message': '',
        'command': row.command,
        'parameters': {},
    }
    b = r_function.match(row.command)
    if b:
        env = {'TODAY': date.today(), 'NOW': date.now(), 'f': f}
        d['command'] = b.group(1)
        para = b.group(2)
        para = os.path.expandvars(para)
        try:
            d['parameters'] = {}
            v = eval('f({})'.format(para), env)
            d['parameters']['_args'] = v[0]
            d['parameters'].update(v[1])
        except Exception as e:
            log.exception(e)
            d['status'] = 'F'
            d['message'] = 'Eval parameter {} error'.format(b.group(2))
    else:
        d['command'] = 'shell'
        d['parameters'] = {'cmd': row.command, 'cwd': row.work_directory}
    return d