コード例 #1
0
ファイル: activity.py プロジェクト: helloworldzly/smiex
def activity_admin_add():
    '''
        添加活动
        参数: title description
        startyear startmonth startday starthour startminute
        endyear endmonth endday endhour endminute
        attendtype(0 or 1)
        (teampeoplenum teamnum if attendtype=1)
        (peoplenum if attendtype=0)
        filter(0 or 1 or 2)
        bstartyear bstartmonth bstartday bstarthour bstartminute
        bendyear bendmonth bendday bendhour bendminute
        fuzeren fuzerenphone
        poster(0 or 1)
        appendproblem(num)
        appendproblemlist
        返回值: SUCCESS activityid / INVALID_OPERATION / PERMISSION_DENIED / PARAMETER_ERROR
        验证参数表是否合法,不合法则返回 INVALID_OPERATION
        将相关信息写入数据库,将活动ID返回
    '''
    cookies = request.cookies
    if not 'session' in cookies:
       return jsonify(rescode=INVALID_OPERATION)

    session = cookies['session']

    from lib import get_username_by_session
    username = get_username_by_session(session)
    if username == None:
       return jsonify(rescode=INVALID_OPERATION)

    # username = '******'

    from lib import check_authority
    if check_authority(username, 'addactivity') == False:
        return jsonify(rescode=PERMISSION_DENIED)

    form = request.form
    required = ['title', 'description', 
    'startyear', 'startmonth', 'startday', 'starthour', 'startminute',
    'endyear', 'endmonth', 'endday', 'endhour', 'endminute',
    'attendtype', 'filter',
    'bstartyear', 'bstartmonth', 'bstartday', 'bstarthour', 'bstartminute',
    'bendyear', 'bendmonth', 'bendday', 'bendhour', 'bendminute',
    'fuzeren', 'fuzerenphone', 'poster', 'appendproblem']

    datekey = ['startyear', 'startmonth', 'startday', 'starthour', 'startminute',
    'endyear', 'endmonth', 'endday', 'endhour', 'endminute',
    'bstartyear', 'bstartmonth', 'bstartday', 'bstarthour', 'bstartminute',
    'bendyear', 'bendmonth', 'bendday', 'bendhour', 'bendminute']

    data = {}
    for item in required:
        if not item in form:
            print item
            return jsonify(rescode=PARAMETER_ERROR)
        if not item in datekey:
            data[item] = form[item]

    from lib import check_time_valid

    if check_time_valid(form['startyear'], form['startmonth'], form['startday'], form['starthour'], form['startminute']) == False:
        return jsonify(rescode=PARAMETER_ERROR)
    if check_time_valid(form['endyear'], form['endmonth'], form['endday'], form['endhour'], form['endminute']) == False:
        return jsonify(rescode=PARAMETER_ERROR)
    if check_time_valid(form['bstartyear'], form['bstartmonth'], form['bstartday'], form['bstarthour'], form['bstartminute']) == False:
        return jsonify(rescode=PARAMETER_ERROR)
    if check_time_valid(form['bendyear'], form['bendmonth'], form['bendday'], form['bendhour'], form['bendminute']) == False:
        return jsonify(rescode=PARAMETER_ERROR)

    starttime = '%02d-%02d-%02d %02d:%02d'%(int(form['startyear']), int(form['startmonth']), int(form['startday']), int(form['starthour']), int(form['startminute']))
    endtime = '%02d-%02d-%02d %02d:%02d'%(int(form['endyear']), int(form['endmonth']), int(form['endday']), int(form['endhour']), int(form['endminute']))
    bstarttime = '%02d-%02d-%02d %02d:%02d'%(int(form['bstartyear']), int(form['bstartmonth']), int(form['bstartday']), int(form['bstarthour']), int(form['bstartminute']))
    bendtime = '%02d-%02d-%02d %02d:%02d'%(int(form['bendyear']), int(form['bendmonth']), int(form['bendday']), int(form['bendhour']), int(form['bendminute']))

    data['starttime'] = starttime
    data['endtime'] = endtime
    data['bstarttime'] = bstarttime
    data['bendtime'] = bendtime

    if data['attendtype'] == '1':
        if not 'teampeople' in form or not 'teamnum' in form:
            return jsonify(rescode=PARAMETER_ERROR)
        else:
            data['teampeople'] = int(form['teampeople'])
            data['teamnum'] = int(form['teamnum'])
            data['seat'] = int(form['teamnum'])
    else:
        if not 'peoplenum' in form:
            return jsonify(rescode=PARAMETER_ERROR)
        else:
            data['peoplenum'] = int(form['peoplenum'])
            data['seat'] = int(form['peoplenum'])

    if data['appendproblem'] != '0':
        if not 'appendproblemlist' in form:
            return jsonify(rescode=PARAMETER_ERROR)
        temp_problem_list = form['appendproblemlist']
        temp_problem_list = temp_problem_list.split('###')
        if len(temp_problem_list) != data['appendproblem']:
            return jsonify(rescode=PARAMETER_ERROR)
        data['appendproblemlist'] = temp_problem_list

    if data['poster'] == '1':
        files = request.files
        if not 'file' in files:
            return jsonify(rescode=PARAMETER_ERROR)
        file_data = files['file']

        from lib import save_activity_poster
        file_url = save_activity_poster(file_data)
        data['posterurl'] = file_url

    data['owner'] = username
    from lib import add_activity
    activity_id = add_activity(data)

    return jsonify(rescode=SUCCESS, activityid=activity_id)
コード例 #2
0
ファイル: activity.py プロジェクト: helloworldzly/smiex
def activity_admin_edit():
    '''
        编辑活动
        参数:activityid
        title description
        startyear startmonth startday starthour startminute
        endyear endmonth endday endhour endminute
        attendtype(0 or 1)
        (teampeoplenum teamnum if attendtype=1)
        (peoplenum if attendtype=0)
        filter(0 or 1 or 2)
        bstartyear bstartmonth bstartday bstarthour bstartminute
        bendyear bendmonth bendday bendhour bendminute
        fuzeren fuzerenphone
        poster(0 or 1)
        appendproblem(num)
        appendproblemlist
        中的一项或几项
        返回值: SUCCESS / PARAMETER_ERROR / INVALID_OPERATION / PERMISSION_DENIED 
    '''
    cookies = request.cookies
    if not 'session' in cookies:
       return jsonify(rescode=INVALID_OPERATION)

    session = cookies['session']

    from lib import get_username_by_session
    username = get_username_by_session(session)
    if username == None:
       return jsonify(rescode=INVALID_OPERATION)


    # username = '******'

    form = request.form
    if not 'activityid' in form:
        return jsonify(rescode=PARAMETER_ERROR)
    activityid = form['activityid']

    from lib import check_activity_changeable
    if check_activity_changeable(activityid, username) == False:
        return jsonify(rescode=PERMISSION_DENIED)

    required = ['title', 'description', 
    'startyear', 'startmonth', 'startday', 'starthour', 'startminute',
    'endyear', 'endmonth', 'endday', 'endhour', 'endminute',
    'attendtype', 'filter',
    'bstartyear', 'bstartmonth', 'bstartday', 'bstarthour', 'bstartminute',
    'bendyear', 'bendmonth', 'bendday', 'bendhour', 'bendminute',
    'fuzeren', 'poster', 'fuzerenphone', 'appendproblem']

    datekey = ['startyear', 'startmonth', 'startday', 'starthour', 'startminute',
    'endyear', 'endmonth', 'endday', 'endhour', 'endminute',
    'bstartyear', 'bstartmonth', 'bstartday', 'bstarthour', 'bstartminute',
    'bendyear', 'bendmonth', 'bendday', 'bendhour', 'bendminute']

    srequired = ['startyear', 'startmonth', 'startday', 'starthour', 'startminute']
    erequired = ['endyear', 'endmonth', 'endday', 'endhour', 'endminute']
    bsrequired = ['bstartyear', 'bstartmonth', 'bstartday', 'bstarthour', 'bstartminute']
    berequired = ['bendyear', 'bendmonth', 'bendday', 'bendhour', 'bendminute']

    scnt = 0
    ecnt = 0
    bscnt = 0
    becnt = 0

    data = {}
    for item in required:
        if item in form:
            if not item in datekey:
                data[item] = form[item]
            if item in srequired:
                scnt += 1
            if item in erequired:
                ecnt += 1
            if item in bsrequired:
                bscnt += 1
            if item in berequired:
                becnt += 1

    if scnt != 0 and scnt != 5:
        return jsonify(rescode=PARAMETER_ERROR)
    if ecnt != 0 and ecnt != 5:
        return jsonify(rescode=PARAMETER_ERROR)
    if bscnt != 0 and bscnt != 5:
        return jsonify(rescode=PARAMETER_ERROR)
    if becnt != 0 and becnt != 5:
        return jsonify(rescode=PARAMETER_ERROR)

    from lib import check_time_valid

    if scnt == 5:
        if check_time_valid(form['startyear'], form['startmonth'], form['startday'], form['starthour'], form['startminute']) == False:
            return jsonify(rescode=PARAMETER_ERROR)
        else:
            starttime = '%02d-%02d-%02d %02d:%02d'%(int(form['startyear']), int(form['startmonth']), int(form['startday']), int(form['starthour']), int(form['startminute']))
            data['starttime'] = starttime
    if ecnt == 5:
        if check_time_valid(form['endyear'], form['endmonth'], form['endday'], form['endhour'], form['endminute']) == False:
            return jsonify(rescode=PARAMETER_ERROR)
        else:
            endtime = '%02d-%02d-%02d %02d:%02d'%(int(form['endyear']), int(form['endmonth']), int(form['endday']), int(form['endhour']), int(form['endminute']))
            data['endtime'] = endtime
    if bscnt == 5:
        if check_time_valid(form['bstartyear'], form['bstartmonth'], form['bstartday'], form['bstarthour'], form['bstartminute']) == False:
            return jsonify(rescode=PARAMETER_ERROR)
        else:
            bstarttime = '%02d-%02d-%02d %02d:%02d'%(int(form['bstartyear']), int(form['bstartmonth']), int(form['bstartday']), int(form['bstarthour']), int(form['bstartminute']))
            data['bstarttime'] = bstarttime
    if becnt == 5:
        if check_time_valid(form['bendyear'], form['bendmonth'], form['bendday'], form['bendhour'], form['bendminute']) == False:
            return jsonify(rescode=PARAMETER_ERROR)
        else:
            bendtime = '%02d-%02d-%02d %02d:%02d'%(int(form['bendyear']), int(form['bendmonth']), int(form['bendday']), int(form['bendhour']), int(form['bendminute']))
            data['bendtime'] = bendtime

    if 'attendtype' in form:
        if form['attendtype'] == '1':
            if not 'teampeople' in form or not 'teamnum' in form:
                return jsonify(rescode=PARAMETER_ERROR)
            data['teampeople'] = int(form['teampeople'])
            data['teamnum'] = int(form['teamnum'])
        else:
            if not 'peoplenum' in form:
                return jsonify(rescode=PARAMETER_ERROR)
            data['peoplenum'] = int(form['peoplenum'])

    if 'poster' in form:
        if form['poster'] == '1':
            files = request.files
            if not 'file' in files:
                return jsonify(rescode=PARAMETER_ERROR)
            file_data = files['file']

            from lib import save_activity_poster
            file_url = save_activity_poster(file_data)
            data['posterurl'] = file_url

    from lib import update_activity
    update_activity(activityid, data)

    return jsonify(rescode=SUCCESS)