def edit_group(): """ get followers for users """ # import ipdb # ipdb.set_trace() db = mongo.db apikey = request.values.get("apikey") image_data_binary = request.values.get('image') category = request.values.get("category") description = request.values.get("description") token = request.values.get("token") _id = request.values.get("_id") uid = request.values.get("uid") group = db.groups.find_one({'_id': ObjectId(_id)}) group_id = _id category_dict = db.categories.find_one({'_id': ObjectId(category)}, {'category': 1}) # category_name = category_dict.get('category') if request.values.get('image'): #and request.values.get('filedata'): from utils import validatephoto # validatefile = {'error': error, 'img_type': img_type, 'file_like': file_like} validatefile = validatephoto(request) if not validatefile['error']: # gid = db.groups.find_one({'groupurl': groupurl}, {'_id': 1}) if group_id: from config_data import GROUP_IMAGES, APP_PATH # str_gid = str(gid['_id']) img_type = validatefile['img_type'] ext_type = validatefile['img_type'].split('/')[-1] # if img_type == 'jpeg': # img_type = 'jpg' img_path_name = GROUP_IMAGES + group_id + '.' + ext_type local_img_path_name = APP_PATH + '/' + img_path_name from utils import uploadImage file_like = validatefile['file_like'] # import ipdb # ipdb.set_trace() fp = open(local_img_path_name, 'wb') file_like.seek(0) fp.write(file_like.read()) fp.close() uploadImageStatus = uploadImage(file_like, img_path_name, img_type) if uploadImageStatus: pass query_js = None result = {"status": True, "msg": "list of following", "data": query_js} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'}
def add_group(): """ get followers for users (refactoring must done)""" db = mongo.db scope = request.values.get("scope") group = request.values.get("group") groupurl = request.values.get("groupurl") token = request.values.get("token") uid = request.values.get("uid") cid = request.values.get("cid") apikey = request.values.get("apikey") status = "active" isDisplay = True result = {"status": True, "msg": "list of following", "data": None} if not status: result['msg'] = {"status": "You must select a status."} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'} if not scope: result['msg'] = {"scope": "You must select a scope."} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'} if not (group or groupurl): result['msg'] = { "group": ["You must enter a group name."], "groupurl": ["You must enter a groupurl."] } format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'} if not cid: result['msg'] = {"cid": ["You must enter a cid"]} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'} if not uid: result['msg'] = {"uid": ["You must enter a uid"]} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'} # import ipdb # ipdb.set_trace() groupurl_found = bool(db.companies.find_one({"urlname": groupurl}) or\ db.groups.find_one({"groupurl": groupurl}) or\ db.users.find_one({"username": groupurl})) if groupurl_found: result['msg'] = {"groupurl": "This groupurl already taken."} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'} # import ipdb # ipdb.set_trace() notsupported = ('about', 'undefined', 'login', 'contact', 'faq', 'terms', 'privacy', 'invite', 'logout') shouldnotstartwith = "emp-" if groupurl in notsupported or groupurl.startswith(shouldnotstartwith): result['msg'] = {"groupurl": "Group URL already exists."} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'} # import ipdb # ipdb.set_trace() coverphoto = 'files/coverphoto/group/groupdefault_1.jpg' if request.values.get('image') and request.values.get('filedata'): from utils import validatephoto # validatefile = {'error': error, 'img_type': img_type, 'file_like': file_like} validatefile = validatephoto(request) if not validatefile['error']: gid = db.groups.find_one({'groupurl': groupurl}, {'_id': 1}) if gid: from config_data import GROUP_IMAGES, APP_PATH str_gid = str(gid['_id']) img_type = validatefile['img_type'] img_path_name = APP_PATH + GROUP_IMAGES + str_gid + '.' + img_type from utils import uploadImage file_like = validatefile['file_like'] uploadImageStatus = uploadImage(file_like) else: groupsort = group.lower() post_data = {'scope': scope, 'group': group, 'groupurl': groupurl, 'uid': uid, 'cid': cid, 'status': status, 'isDisplay': isDisplay, 'coverphoto': coverphoto, 'groupsort': groupsort, 'token': token, 'apikey': apikey} try: group_insert = db.groups.insert(post_data) group_id = str(group_insert) post_data['group_id'] = group_id result = {"status": True, "msg": "Group Added Successfully", "data": post_data} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'} except: logging.error("error in inserting into the db for add group api call") result = {"status": False, "msg": "error in inserting into the db for add group api call", "data": post_data} format_result = {"result": result} json_results = json.dumps(format_result, default=json_util.default) return json_results, 200, {'Content-Type': 'application/json'}