コード例 #1
0
ファイル: deck.py プロジェクト: GenkoStoykov/AngularRepo
def unlinkdeck():
    result = {}
    json_data = request.json
    if (is_admin()):
        link = Link.query.filter_by(userid=json_data['userid'],
                                    deckid=json_data['deckid']).first()
        if (link == None):
            result['msg'] = 'This user is not linked with this deck.'
            result['status'] = 0
        else:
            try:
                profiles = Profile.query.filter_by(linkid=link.id).all()
                for profile in profiles:
                    if (profile.run_status == 1):
                        jobid = 'retweet_%s' % (profile.id)
                        if (is_running(jobid)):
                            scheduler.remove_job(jobid)
                    db.session.delete(profile)
                approves = Approve.query.filter_by(linkid=link.id).all()
                for approve in approves:
                    db.session.delete(approve)
                db.session.delete(link)
                db.session.commit()
                result['status'] = 1
                result['msg'] = 'Sucessfully unlinked.'
            except:
                result['msg'] = 'Occured error in db session.'
                result['status'] = 0
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    return jsonify({'result': result})
コード例 #2
0
def delUser():
    result = {}
    json_data = request.json
    if (is_admin()):
        try:
            user = User.query.filter_by(id=json_data['userid']).first()
            links = Link.query.filter_by(userid=user.id).all()
            for link in links:
                profiles = Profile.query.filter_by(linkid=link.id).all()
                for profile in profiles:
                    if (profile.run_status == 1):
                        jobid = 'retweet_%s' % (profile.id)
                        if (is_running(jobid)):
                            scheduler.remove_job(jobid)
                    db.session.delete(profile)
                approves = Approve.query.filter_by(linkid=link.id).all()
                for approve in approves:
                    db.session.delete(approve)
                db.session.delete(link)
            db.session.delete(user)
            db.session.commit()
            result['status'] = 1
            result['msg'] = 'Succefully deleted user.'
        except:
            result['status'] = -1
            result['msg'] = 'Occured error in delete user.'
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    db.session.close()
    return jsonify({'result': result})
コード例 #3
0
ファイル: deck.py プロジェクト: GenkoStoykov/AngularRepo
def listDecks():
    result = {}
    if (is_admin()):
        decks = Deck.query.all()
        result['decks'] = [deck.to_dict(show_all=True) for deck in decks]
        result['status'] = 1
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    return jsonify({'result': result})
コード例 #4
0
def checkEmail():
    result = {}
    if (is_admin()):
        mail = Adminmail.query.first()
        if (mail != None):
            result['status'] = 1
            result['msg'] = 'Email Address is setted.'
        else:
            result['status'] = 0
            result['msg'] = 'Email Address is not setted now.'
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    return jsonify({'result': result})
コード例 #5
0
ファイル: deck.py プロジェクト: GenkoStoykov/AngularRepo
def linkdeck():
    result = {}
    json_data = request.json
    if (is_admin()):
        link = Link(userid=json_data['userid'], deckid=json_data['deckid'])
        try:
            db.session.add(link)
            db.session.commit()
            result['status'] = 1
            result['msg'] = 'Sucessfully linked.'
        except:
            result['msg'] = 'This user is already linked with this deck.'
            result['status'] = 0
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    return jsonify({'result': result})
コード例 #6
0
def setEmail():
    result = {}
    json_data = request.json
    if (is_admin()):
        num_rows_deleted = db.session.query(Adminmail).delete()
        mail = Adminmail(
            email_address=json_data['email'],
            username=json_data['username'],
            password=json_data['password'],
            smtpserver=json_data['smtpserver'],
        )
        db.session.add(mail)
        db.session.commit()
        result['status'] = 1
        result['msg'] = 'Succefully set email address.'
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    return jsonify({'result': result})
コード例 #7
0
ファイル: profile.py プロジェクト: GenkoStoykov/AngularRepo
def listProfiles():
    result = {}
    if (is_admin()):
        profiles = (
            db.session.query(Profile.id, Profile.keyword, Profile.run_status,
                             Profile.minutes, Profile.created_at,
                             Profile.last_retweeted, Link.deckid,
                             Deck.name, User.username)
                .join(Link).join(Deck).join(User)).all()
        ret_data = []
        for profile in profiles:
            profile_data = {}
            for key in profile._fields:
                profile_data[key] = getattr(profile, key)
            ret_data.append(profile_data)
        result['status'] = 1
        result['profiles'] = ret_data
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    return jsonify({'result': result})
コード例 #8
0
def listUsers():
    result = {}
    if (is_admin()):
        users = User.query.filter_by(admin=False, deck=False).all()
        ret_data = []
        for user in users:
            linked_decks = Link.query.filter_by(userid=user.id).all()
            user_data = {}
            user_data['id'] = user.id
            user_data['username'] = user.username
            user_data['registered_on'] = user.registered_on
            if (len(linked_decks) > 0):
                user_data['linked_decks'] = [
                    link.deckid for link in linked_decks
                ]
            else:
                user_data['linked_decks'] = []
            ret_data.append(user_data)
        result['status'] = 1
        result['users'] = ret_data
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    return jsonify({'result': result})