Ejemplo n.º 1
0
def approve_entity_function():
    data = request.get_data()
    json_data = json.loads(data)
    print(json_data)
    eId = json_data['eId']
    uId = json_data['vuId']
    en = entityInfoDB.search_entity(eId)
    print(uId)
    u = userInfoDB.search_user(uId)
    if u is None:
        return jsonify('uId Error')
    if en is None:
        return jsonify('eId Error')
    if en.eStatus == '8':
        return jsonify('false')
    print(u.role)
    if u.role == 'Manager':
        if en.eStatus == '7':
            return jsonify('false')
    if u.role == 'Curator':
        if en.eStatus == '4' or en.eStatus == '7':
            return jsonify('false')
    date = time.strftime('%Y-%m-%d',
                         time.localtime(time.time()))  # Approved date
    en.eSubDate = date
    print(u.role)
    if u.role == 'Manager':
        print('en.status')
        en.eStatus = '7'
    if u.role == 'Curator':
        en.eStatus = '4'
    fd = feedbackDB.search_feedback_eId(eId)
    if fd is not None:
        feedbackDB.dele_feedbackFdb(eId)
    fnum = feedbackDB.search_feedback_num() + 1
    fId = 'FB_' + str(fnum)
    date = time.strftime('%Y-%m-%d', time.localtime(time.time()))
    fb = Model.Feedback(fId, json_data['eId'], uId,
                        json.dumps(json_data['feedback']), date)
    feedbackDB.add_feedback2db(fb)
    entityInfoDB.update_entity2db(en)
    user = userInfoDB.search_user(en.euId)
    if user is not None:
        url = ''  #json_data['url']
        if user.uvs == '0':
            if u.role == 'Manager':
                SendEmail.releaseEntityEmail(user, url)
            else:
                SendEmail.approveEntityEmail(user, url)
    return jsonify('true')
Ejemplo n.º 2
0
def give_feedback_function():
    data = request.get_data()
    json_data = json.loads(data)
    eId = json_data['eId']
    uId = json_data['uId']
    check_f = feedbackDB.search_feedback_eId(eId)
    if check_f is None:
        fnum = feedbackDB.search_feedback_num() + 1
        fId = 'FB_' + str(fnum)
        date = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        feedback = Model.Feedback(fId, json_data['eId'], json_data['feedback'], date)
        feedbackDB.add_feedback(feedback)
        return jsonify('true')
    else:
        return jsonify('false')
Ejemplo n.º 3
0
def check_feedback_function():
    data = request.get_data()
    json_data = json.loads(data)
    feedback = feedbackDB.search_feedback_eId(json_data.eId)
    if feedback is not None:
        customers = []
        for e in feedback:
            u = e.__dict__
            result = json.dumps(u)
            customers.append(result)
        # print(result)
        result1 = str(customers).replace('\'', '')
        # print(result1)
        r = json.loads(result1)
        return jsonify(r)
    else:
        return jsonify('false')
Ejemplo n.º 4
0
def send_message_function():
    data = request.get_data()
    print(request)
    json_data = json.loads(data)
    uId = json_data['uId']
    #tuId = json_data['tuId']
    eId = json_data['eId']
    msg = json_data['message']
    fb = feedbackDB.search_feedback_eId(eId)
    if fb is None:
        return jsonify('No feedback.')
    print(fb)
    date = time.strftime('%Y-%m-%d: %H:%M:%S', time.localtime(time.time()))
    mnum = messageDB.search_message_num() + 1
    mId = 'MSG_' + str(mnum)
    message = Model.Message(mId,uId,fb.uId,eId,msg,date,None)
    messageDB.add_message2db(message)
    return jsonify('true')
Ejemplo n.º 5
0
def check_entity_function():
    eId = request.values.get("eId")
    role = request.values.get("role")
    en = entityInfoDB.search_entity(eId)
    if en is None:
        return jsonify('eId Error!')
    if role == 'Manager':
        en.eStatus = 6
    if role == 'Curator':
        en.eStatus = 2

    result = dict()
    if en is None:
        return jsonify('No such Entity!')
    result['eId'] = en.eId
    result['uId'] = en.euId
    result['eType'] = en.eType
    result['eName'] = en.eName
    result['eTitle'] = en.eSubName
    result['sDate'] = en.eStartDate
    result['eDate'] = en.eEndDate
    result['bPlace'] = en.eBirthPlace
    result['dPlace'] = en.eDeathPlace
    result['sumNote'] = en.eSumNote
    result['ePrepared'] = en.ePrepared
    result['resources'] = en.eImgResource

    if en.eLocation is not None:
        dn = jsonEntity.read_entity(en.eLocation)
        result['fullNote'] = dn.fullNote

    if en.eImage is None:
        result['image'] = 'static/images/default.png'
    result['image'] = 'static/images/' + en.eId + '.png'

    als = alternationDB.search_alternation_eId_Fdb(
        en.eId)  # just for one relationship
    result['alternation'] = []
    if als is not None:
        for al in als:
            aa = Models.Objects.alternationforen(al.aType, al.alternate)
            result['alternation'].append(aa.__dict__)

    pr = publicResourceDB.search_publicResource_eId_Fdb(
        en.eId)  # just for one relationship
    result['publish'] = []
    if pr is not None:
        for r in pr:
            pp = Models.Objects.publicResourceforen(r.pId, r.pTitle, r.pType,
                                                    r.pUrl)
            result['publish'].append(pp.__dict__)

    dr = digitalResourceDB.search_digitalResource_eId_Fdb(
        en.eId)  # just for one relationship
    result['digital'] = []
    if dr is not None:
        for r in dr:
            dd = Models.Objects.digitalResourceforen(r.dId, r.dTitle, r.dType,
                                                     r.dUrl)
            result['digital'].append(dd.__dict__)

    rela = relationshipDB.search_relationship_eId(en.eId)
    result['relationship'] = []
    if rela is not None:
        for r in rela:
            ren = entityInfoDB.search_entity(r.reId)
            if ren is not None:  #rId, eId, relPairs, reId, eName, sDate, eType
                rr = Models.Objects.relationshipsforen(r.rId, r.eId,
                                                       r.relationship, r.reId,
                                                       ren.eName, ren.eType)
            else:
                rr = Models.Objects.relationshipsforen(r.rId, r.eId,
                                                       r.relationship, r.reId,
                                                       None, None)
            result['relationship'].append(rr.__dict__)
            # print(r.reId)

    occ = occupationDB.search_occupation_eId_Fdb(en.eId)
    result['function'] = []
    if occ is not None:
        for o in occ:
            ff = Models.Objects.functions(o.oId, o.occupation, o.oEvent)
            result['function'].append(ff.__dict__)

    fb = feedbackDB.search_feedback_eId(eId)
    if fb is not None:
        print(fb.feedback)
        result['feedback'] = json.loads(fb.feedback)
    print(result)
    return jsonify(result)