コード例 #1
0
 def getAdminById(self, aid):
     dao = AdminDAO()
     admin = dao.getAdminById(aid)
     if not admin:
         return jsonify(Error="Admin Not Found"), 404
     else:
         result = self.build_admin_dict(admin)
     return jsonify(Admin=result)
コード例 #2
0
 def getAllAdmins(self):
     dao = AdminDAO()
     admin_list = dao.getAllAdmins()
     result_list = []
     for row in admin_list:
         result = self.build_admin_dict(row)
         result_list.append(result)
     return jsonify(Admins=result_list)
コード例 #3
0
    def getAdminPasswords(self):
        dao = AdminDAO()
        admin_list = dao.getAdminPasswords()
        if not admin_list:
            return jsonify(Error="No Passwords Found"), 404
        else:
            result_list = []
            for row in admin_list:
                result = self.build_admin_dict(row)
                result_list.append(result)

        return jsonify(Passwords=result_list)
コード例 #4
0
 def getAdminIds(self):
     dao = AdminDAO()
     admin_list = dao.getAdminIds()
     if not admin_list:
         return jsonify(Error="No ids found"), 404
     else:
         result_list = []
         for row in admin_list:
             result = {}
             result['aid'] = row[0]
             result_list.append(result)
     return jsonify(Ids=result_list)
コード例 #5
0
    def getAdminNames(self):
        dao = AdminDAO()
        admin_list = dao.getAdminNames()

        if not admin_list:
            return jsonify(Error="No Admin Names Found"), 404
        else:
            result_list = []
            for row in admin_list:
                result = {}
                result['aname'] = row[0]
                result_list.append(result)

        return jsonify(Anames=result_list)
コード例 #6
0
 def insertAdmin(self, form):
     if len(form) != 2:
         return jsonify(Error="Malformed POST request"), 400
     else:
         aname = form['aname']
         apassword = form['apassword']
         if aname and apassword:
             dao = AdminDAO()
             aid = dao.insert(aname, apassword)
             result = self.build_admin_attributes(aid, aname, apassword)
             return jsonify(Admin=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in POST request"), 400
コード例 #7
0
 def searchAdmins(self, args):
     if len(args) > 2:
         return jsonify(Error="Malformed search string."), 400
     else:
         aname = args.get("aname")
         aid = args.get("aid")
         dao = AdminDAO()
         admin_list = []
         if len(args) == 1 and aname:
             admin_list = dao.getAdminByName(aname)
         elif len(args) == 1 and aid:
             admin_list = dao.getAdminById(aid)
         else:
             return jsonify(Error="Malformed query string"), 400
         result_list = []
         for row in admin_list:
             result = self.build_admin_dict(row)
             result_list.append(result)
         return jsonify(Admins=result_list)