def addCity(): CityCollections.insert({"city" :"Vancouver" ,"countryid" : 647010771 ,"stateid" : 719887913 ,"cityid" : CommonUtils.generateRandomNo(CityCollections ,"cityid"), "active" : True ,"createddatetime" : datetime.now(), "updateddatetime" : datetime.now() ,"gpsJSON" : {"lat" : 49.246292 ,"lng" : -123.116226 ,"lnglat" : [-123.116226 ,49.246292] ,"radius" : ""}}) return "success"
def get_user_address_json(cls, city_id): if city_id: from jobwork.models.city import CityCollections citydetail = CityCollections.find_one({"cityid": city_id}, {"_id": 0}) # statedetail = StateCollections.find_one({"stateid": citydetail['stateid']}, {"_id": 0}) from jobwork.models.country import CountryCollections countrydetail = CountryCollections.find_one( {"countryid": citydetail['countryid']}, {"_id": 0}) return { "address1": "", "address2": "", "city": city_id, "state": citydetail['stateid'], "country": countrydetail['countryid'], "pincode": "" } else: return { "address1": "", "address2": "", "city": "", "state": "", "country": "", "pincode": "" }
def profile(): if authenticatedUser(): city = list(CityCollections.find({} ,{"_id" :0 ,"cityid" :1 ,"city" :1})) locationData = list(Locations.find({} ,{"_id" :0})) return render_template("front_saveonjobs/profile.html" ,cities=city ,location=locationData) else: return unauthorizedUser()
def mytask(): if authenticatedUser(): city = list(CityCollections.find({} ,{"_id" :0 ,"cityid" :1 ,"city" :1})) locationData = list(Locations.find({} ,{"_id" :0})) return render_template("front_saveonjobs/my-tasks.html" ,cities=city ,location=locationData ,message='') else: return unauthorizedUser()
def findjobs(): city = list( CityCollections.find({}, { "_id": 0, "cityid": 1, "city": 1 }).sort('city', 1)) locationData = list(Locations.find({}, {"_id": 0}).sort('locationname', 1)) return render_template("front_saveonjobs/findjobs.html", cities=city, location=locationData)
def notification_list(): URL = Constants.URL imagePath = Constants.IMAGE_PATH userid = int(request.json['userid']) token = request.json['token'] notificationArray = [] notificationData = list( Notifications.find({ "notificationtouserid": userid }, { "_id": 0 }).sort("createddatetime", -1)) notificationUnread = list( Notifications.find({ "notificationtouserid": userid, "isread": False }, {"_id": 0})) print(notificationData) if len(notificationData) > 0: for collections in notificationData: jobber = {} if collections['notificationfromuserid'] != -1: jobber = Jobs.find_one({"jobid": int(collections['jobid'])}, { "_id": 0, "creatinguserid": 1 }) userData = User.find_one( {"userid": int(collections['notificationfromuserid'])}, {"_id": 0}) if userData is not None: fullname = userData['firstname'] + " " + userData[ 'lastname'] if userData['picurl'] != "": picurl = URL + imagePath + userData['picurl'] else: picurl = URL + imagePath + "user-no-image.jpg" if userData['addressJSON']['city'] != "": cityNamedata = CityCollections.find_one( {"cityid": userData['addressJSON']['city']}, { "_id": 0, "city": 1 }) cityName = cityNamedata['city'] else: cityName = "" else: fullname = "" picurl = URL + imagePath + "user-no-image.jpg" cityName = "" else: fullname = "SAVEonJOBS" picurl = URL + "static/front_end/images/logo1.png" cityName = "" userDataCollection = { "fullname": fullname, "cityname": cityName, "picurl": picurl, "jobber": jobber } collections.update(userDataCollection) notificationArray.append(collections) return jsonify({ "status": 200, "message": "Notification Data.", "notificationArray": notificationArray, "notificationUnread": len(notificationUnread) }) else: return jsonify({ "status": 200, "message": "No Notification data Found.", "notificationArray": [], "notificationUnread": notificationUnread })
def conversations_list(): userid = int(request.json['userid']) token = request.json['token'] allconversationListData = [] URL = Constants.URL imagePath = Constants.IMAGE_PATH conversationData = list( Conversations.find( { "$or": [{ "userid1": userid }, { "userid2": userid }], "active": True }, { "_id": 0 }).sort("lastdatetime", -1)) if len(conversationData) > 0: for conversationListData in conversationData: messageUnreadCount = Messages.find( { "conversationid": conversationListData['conversationid'], "isread": False }, { "_id": 0 }).count() conversationListData.update( {"messageUnreadCount": messageUnreadCount}) # Users Detail userData1 = User.find_one( {"userid": int(conversationListData['userid1'])}, {"_id": 0}) if userData1 is not None: fullname1 = userData1['firstname'] + " " + userData1['lastname'] cityName1 = {} if userData1['picurl'] != "": picurl1 = URL + imagePath + userData1['picurl'] else: picurl1 = URL + imagePath + "user-no-image.jpg" if userData1['addressJSON']['city'] != "": cityName1 = CityCollections.find_one( {"cityid": userData1['addressJSON']['city']}, { "_id": 0, "city": 1 }) else: cityName1['city'] = "" if conversationListData['userid1'] != userid: lastMessageDetail = { "lastuserfullname": fullname1, "lastusercityname": cityName1['city'], "lastuserpicurl": picurl1 } conversationListData.update(lastMessageDetail) userDataCollection1 = { "fullname1": fullname1, "cityname1": cityName1['city'], "picurl1": picurl1 } conversationListData.update(userDataCollection1) userData2 = User.find_one( {"userid": int(conversationListData['userid2'])}, {"_id": 0}) if userData2 is not None: fullname2 = userData2['firstname'] + " " + userData2['lastname'] cityName2 = {} if userData2['picurl'] != "": picurl2 = URL + imagePath + userData2['picurl'] else: picurl2 = URL + imagePath + "user-no-image.jpg" if userData2['addressJSON']['city'] != "": cityName2 = CityCollections.find_one( {"cityid": userData2['addressJSON']['city']}, { "_id": 0, "city": 1 }) else: cityName2['city'] = "" if conversationListData['userid2'] != userid: lastMessageDetail = { "lastuserfullname": fullname2, "lastusercityname": cityName2['city'], "lastuserpicurl": picurl2 } conversationListData.update(lastMessageDetail) userDataCollection2 = { "fullname2": fullname2, "cityname2": cityName2['city'], "picurl2": picurl2 } conversationListData.update(userDataCollection2) allconversationListData.append(conversationListData) return jsonify({ "status": 200, "message": "Conversation Data.", "conversationListData": allconversationListData }) else: return jsonify({ "status": 200, "message": "No Conversation data Found.", "conversationListData": [] })
def conversation_messages_list(): #return jsonify({"ok": 1}) URL = Constants.URL imagePath = Constants.IMAGE_PATH userid = int(request.json['userid']) allMessageData = [] converstaionCollection = Conversations.find_one({ "conversationid": int(request.json['conversationid']), "active": True }) displayuserCollection = { "displayfullname": "", "displaycityname": "", "displaypicurl": "", "displayuserid": "", "conversationid": int(request.json['conversationid']) } userDisplayData = Conversations.find_one( { "conversationid": int(request.json['conversationid']), "active": True }, { "_id": 0, "userid1": 1, "userid2": 1 }) if userDisplayData is not None: # messages.update({"conversationid":request.json['conversationid']},{"$set":{"isread" : True}}, True, True) messageData = list( Messages.find( { "conversationid": request.json['conversationid'], "isread": False }, {"_id": 0})) if len(messageData) > 0: for messageCollection in messageData: Messages.update( { "createdatetimeinseconds": messageCollection['createdatetimeinseconds'] }, {"$set": { "isread": True }}) else: print("No unread Message.") if userDisplayData['userid1'] != userid: userData = User.find_one({"userid": userDisplayData['userid1']}, {"_id": 0}) if userData is not None: cityName = {} fullname = userData['firstname'] + " " + userData['lastname'] if userData['picurl'] != "": picurl = URL + imagePath + userData['picurl'] else: picurl = URL + imagePath + "user-no-image.jpg" if userData['addressJSON']['city'] != "": cityName = CityCollections.find_one( {"cityid": userData['addressJSON']['city']}, { "_id": 0, "city": 1 }) else: cityName['city'] = "" displayuserCollection = { "displayfullname": fullname, "displaycityname": cityName['city'], "displaypicurl": picurl, "displayuserid": userDisplayData['userid1'], "conversationid": int(request.json['conversationid']) } if userDisplayData['userid2'] != userid: userData = User.find_one({"userid": userDisplayData['userid2']}, {"_id": 0}) if userData is not None: fullname = userData['firstname'] + " " + userData['lastname'] if userData['picurl'] != "": picurl = URL + imagePath + userData['picurl'] else: picurl = URL + imagePath + "user-no-image.jpg" cityName = CityCollections.find_one( {"cityid": userData['addressJSON']['city']}, { "_id": 0, "city": 1 }) displayuserCollection = { "displayfullname": fullname, "displaycityname": cityName['city'], "displaypicurl": picurl, "displayuserid": userDisplayData['userid2'], "conversationid": int(request.json['conversationid']) } else: return jsonify({"status": 402, "message": "No Data."}) if converstaionCollection is not None: messageData = list( Messages.find( { "conversationid": int(request.json['conversationid']) }, { "_id": 0 }).sort("createddatetime", 1)) if len(messageData) > 0: for messageListData in messageData: userData = User.find_one( {"userid": int(messageListData['userid'])}, {"_id": 0}) if userData is not None: fullname = userData['firstname'] + " " + userData[ 'lastname'] if userData['picurl'] != "": picurl = URL + imagePath + userData['picurl'] else: picurl = URL + imagePath + "user-no-image.jpg" cityName = CityCollections.find_one( {"cityid": userData['addressJSON']['city']}, { "_id": 0, "city": 1 }) userDataCollection = { "fullname": fullname, "cityname": cityName['city'], "picurl": picurl } messageListData.update(userDataCollection) allMessageData.append(messageListData) return jsonify({ "status": 200, "message": "Message Data.", "messageListData": allMessageData, "displayuserCollection": displayuserCollection }) else: return jsonify({ "status": 200, "message": "No Message data Found.", "messageListData": [], "displayuserCollection": displayuserCollection }) else: return jsonify({ "status": 200, "message": "No Message data Found.", "messageListData": [], "displayuserCollection": displayuserCollection })
def user_profile_fetch(): URL = Constants.URL imagePath = Constants.IMAGE_PATH try: # Check Authentication Key. userid = int(request.json['userid']) token = request.json['token'] otherUserId = int(request.json['messageUserid']) userdata_array = list( User.find({ "userid": otherUserId, "active": True }, {"_id": 0})) resultArray = {} responseArr = [] temp = [] reportStatus = False if len(userdata_array) > 0: for collectionInfo in userdata_array: reportedJSONdata = collectionInfo['reportedJSON'] if len(reportedJSONdata) > 0: for reportStatusData in reportedJSONdata: # print reportStatusData['byuserid'] if reportStatusData['byuserid'] == userid: reportStatus = True else: reportStatus = False reviewsDataList = list \ (JobReviews.find({"touserid" :otherUserId, "adminaction" :True, "active" : True} ,{"_id" :0})) reviewsData = [] if len(reviewsDataList) > 0: for collectionInfoReview in reviewsDataList: userdata = User.find_one( { "userid": collectionInfoReview['userid'], "active": True }, {"_id": 0}) if userdata is not None: fullname = userdata['firstname'] + ' ' + userdata[ 'lastname'] if userdata['picurl'] != "": picurl = URL + imagePath + userdata['picurl'] else: picurl = URL + imagePath + "user-no-image.jpg" if collectionInfoReview.has_key('jobid'): jobData = Jobs.find_one( { "jobid": collectionInfoReview['jobid'], "active": True }, {"_id": 0}) if jobData is not None: title = jobData['title'] else: title = "" editionData = { "fullname": fullname, "jobtitle": title, "picurl": picurl } collectionInfoReview.update(editionData) reviewsData.append(collectionInfoReview) else: reviewsData = [] locationName = "" cityName = "" if collectionInfo['addressJSON']['city'] != "": citynamedata = CityCollections.find_one( {"cityid": int(collectionInfo['addressJSON']['city'])}, {"_id": 0}) cityName = citynamedata['city'] countrynamedata = CityCollections.find_one( {"countryid": int(citynamedata['countryid'])}, {"_id": 0}) print(countrynamedata) #return jsonify({"ok": 1}) countryName = countrynamedata['countryid'] else: cityName = "" countryName = "" if collectionInfo['locationid'] != "": locationNameData = Locations.find_one( {"locationid": int(collectionInfo['locationid'])}, { "_id": 0, "locationname": 1, "under": 1 }) if locationNameData is not None: if locationNameData['under'] != "": locationName = str(locationNameData['under'] ) +" - " +str \ (locationNameData['locationname']) else: locationName = str( locationNameData['locationname']) else: locationName = "" allCityData = list( CityCollections.find({}, { "_id": 0, "cityid": 1, "city": 1 })) # allcity = [] # if len(allCityData) > 0: # for getAllCityData in allCityData: # allcity.append({"cityid" : getAllCityData['cityid'], "city" : getAllCityData['city']}) skillData = collectionInfo['skillsJSON'] skillNameData = [] if len(skillData) > 0: for skillDataCollections in skillData: skillNameData.append(skillDataCollections['skillname']) rating = 0 # Rating Initially 0 userReview = list( JobReviews.find( { "touserid": int(collectionInfo['userid']), "active": True }, { "_id": 0, "rating": 1 })) if len(userReview) > 0: totalUserReview = len(userReview) if userReview is not None: for userRating in userReview: rating = rating + userRating['rating'] tatalRating = int(rating / totalUserReview) else: tatalRating = 0 portfolioData = list( UserPortfolio.find( { "userid": otherUserId, "active": True, }, {"_id": 0})) picurlPath = URL + imagePath + collectionInfo['picurl'] documentsPath = URL + Constants.DOC_PATH portfolioDataPath = URL + Constants.PORTFOLIO_PATH updateJSON = { "cityname": cityName, "locationName": locationName, "countryname": countryName, "allcity": allCityData, "skillName": skillNameData, "reviewsData": reviewsData, "portfolioData": portfolioData, "reportStatus": reportStatus, "picurlPath": picurlPath, "userrating": tatalRating, "documentsPath": documentsPath, "portfolioDataPath": portfolioDataPath } collectionInfo.update(updateJSON) responseArr.append(collectionInfo) resultArray['data'] = responseArr resultArray['status'] = "200" resultArray['message'] = "Userdata List." else: resultArray['data'] = responseArr resultArray['status'] = "400" resultArray['message'] = "No data in List." return jsonify(resultArray) except Exception as e: print(e) return jsonify({"status": 500})
def jobadd(): if request.method == 'POST': try: #return "ok" # Check authentications keys ''' if request.form['userid'] == "" or request.form['token'] =="": return jsonify({"status": 401, "message": "Authentication keys are missing."}) ''' userid = request.form['userid'] #return userid token = request.form['token'] # Authenticate credentials userInfo = User.find_one({"userid": int(userid)}, {"_id": 0}) if userInfo is not None: if userInfo['emailverified'] is False: return jsonify({ "status": 202, "message": "Email not verified. Please verify your email to enable this feature" }) jobid = request.form['jobid'] originaljobid = None if (jobid != ""): originaljobid = jobid draft = request.form['draft'] title = request.form['title'] description = request.form['description'] duedate = request.form['duedate'] #return jsonify({"ok": 1}) jobOnline = request.form['jobonline'] #return "ok" print("1") city = int(request.form['city']) print("2") location = int(request.form['location']) print("3") if duedate == "today": duedate = "" duedate = datetime.now() if duedate == "week": duedate = "" duedate = datetime.now() + timedelta(days=7) if duedate == "certain_day": duedate = "" format = '%d-%m-%Y %H:%M:%S' certaindatetime = request.form['certaindatetime'] duedate = datetime.strptime(certaindatetime, format) citydetail = CityCollections.find_one({"cityid": city}, {"_id": 0}) statedetail = StateCollections.find_one( {"stateid": citydetail['stateid']}, {"_id": 0}) countrydetail = CountryCollections.find_one( {"countryid": citydetail['countryid']}, {"_id": 0}) addressJSON = { "address1": "", "address2": "", "city": city, "state": citydetail['stateid'], "country": countrydetail['countryid'], "pincode": "" } person = request.form['person'] print("5") budgettype = request.form['budgettype'] print("6") budget = float(request.form['budget']) print("7") if budgettype == "hourly": totalhours = int(request.form['hours']) totalbudget = int(budget * totalhours) else: totalhours = -1 totalbudget = budget print("8") if draft == False: publisheddatetime = datetime.now() else: publisheddatetime = None target = os.path.join(Constants.APP_ROOT, 'static/jobdocument/') index = 0 filelist = [] thumblist = [] print("9") jobidno = CommonUtils.generateRandomNo(Jobs, "jobid") for file in request.files.getlist("file"): index = index + 1 try: filename = str(jobidno) + "_" + str(index) + ".jpg" destination = "original/".join([target, filename]) file.save(destination) im = Image.open(file) size = 45, 45 im.thumbnail(size, Image.ANTIALIAS) background = Image.new('RGBA', size, (255, 255, 255, 0)) background.paste(im, (int((size[0] - im.size[0]) / 2), int((size[1] - im.size[1]) / 2))) tname = target + "/thumbnail/" + str(jobidno) + "_" + str( index) + ".png" background.save(tname) thumblist.append(tname) except Exception as e: fname = str(jobidno) + "_" + str(index) + file.filename destination = "original/".join([target, fname]) file.save(destination) tname = target + "/thumbnail/pdf.png" thumblist.append(tname) #thumblist.append(tpath) filelist.append(destination) #return jsonify({"t":thumblist,"l":filelist}) print("10") jobdocs = {} jobdocs.update({"thumbnails": thumblist}) jobdocs.update({"doc": filelist}) print("11") if (request.form['draft_data'] == "false"): jobid = jobidno result = Jobs.insert({ "jobid": jobid, "title": title, "description": description, "creatinguserid": userid, "duedate": duedate, "budget": budget, "budgettype": budgettype, "totalbudget": totalbudget, "totalhours": totalhours, "jobstatus": "pending", "draft": draft, "publisheddatetime": publisheddatetime, "personsrequired": int(person), "reportedJSON": [], "active": True, "cancellationreason": None, "cityid": city, "online": jobOnline, "addressJSON": addressJSON, "locationid": location, "personsselected": 0, "originaljobid": originaljobid, "adminapprovalforcancellation": None, "skillid": None, "tags": None, "jobdocs": jobdocs, "updatedatetime": datetime.now(), "createdatetime": datetime.now(), "expired": False }) return jsonify({ 'status': 200, 'message': 'Job Created.', 'jobid': jobid }) else: Jobs.update({"jobid": jobid}, { "$set": { "title": title, "description": description, "creatinguserid": userid, "duedate": duedate, "budget": budget, "budgettype": budgettype, "totalbudget": totalbudget, "totalhours": totalhours, "jobstatus": "pending", "draft": draft, "publisheddatetime": publisheddatetime, "personsrequired": int(person), "reportedJSON": [], "active": True, "cancellationreason": None, "cityid": city, "online": jobOnline, "addressJSON": addressJSON, "locationid": location, "personsselected": 0, "originaljobid": originaljobid, "adminapprovalforcancellation": None, "skillid": None, "tags": None, "jobdocs": jobdocs, "updatedatetime": datetime.now(), "expired": False } }) return jsonify({ 'status': 200, 'message': 'Job Updated.', 'jobid': jobid }) except Exception as e: print(e) return "error"
def user_update(): try: userid = int(request.json['userid']) token = request.json['token'] location = request.json['location'] if location != "": location = int(location) find_user = User.find_one({"userid": userid, "active": True}) if find_user is not None: skills = request.json['skills'] print(skills) print(type(skills)) if request.json['dob'] != "": birth = request.json['dob'] print(birth) format = '%d-%m-%Y' dob = datetime.datetime.strptime(birth, format) else: dob = "" if request.json['city'] != "": citydetail = CityCollections.find_one( {"cityid": int(request.json['city'])}, {"_id": 0}) addressJSON = { "address1": request.json['address1'], "address2": request.json['address2'], "city": int(request.json['city']), "state": citydetail['stateid'], "country": citydetail['countryid'], "pincode": request.json['pincode'] } else: addressJSON = { "address1": request.json['address1'], "address2": request.json['address2'], "city": "", "state": "", "country": "", "pincode": request.json['pincode'] } if request.json['isdcode'] != "" and request.json[ 'isdcode'] is not None: isdcode = int(request.json['isdcode']) else: isdcode = "" # locationData = location.find_one({"cityid" : int(request.json['city'])},{"_id":0,"locationid":1}) # skillsJSON = [] # for skillDataJSON in skills: # stringData = '.*'+skillDataJSON+'.*' # skillsData = skills.find_one({"skillname" : { "$regex" : skillDataJSON, "$options" : 'i' }},{"_id":0,"skillid":1,"skillname":1}) # if skillsData is not None: # for skillsCollections in skillsData : # skillDict = {"skillid" : skillsCollections['skillid'], # "skillname" : skillsCollections['skillname']} # skillsJSON.append(skillDict) randomNameForFile = "" # if request.json['imageFlag']: # randomNameForFile = "image_"+str(int(time.time()))+".jpg" # fh = open("static/images/profile/"+randomNameForFile, "wb") # fh.write(request.json['picurl'].decode('base64')) # fh.close() # languagesJSON = request.json['languagesJSON'] # educationCSV = request.json['educationCSV'] # workplaceCSV = request.json['workplaceCSV'] # certificateJSON = request.json['certificateJSON'] # reportedJSON = list(report.find({ "userid" : userid, "token" : token }, {"_id":0})) if find_user['mobile'] != str(request.json['mobile']): User.update({"userid": userid}, { "$set": { "signupJSON.mobile": str(request.json['mobile']), "mobile": str(request.json['mobile']), "mobileverified": False, "proJSON.mobileverified": False } }) if find_user['email'] != str(request.json['email']): User.update({"userid": userid}, { "$set": { "signupJSON.email": str(request.json['email']), "email": str(request.json['email']), "emailverified": False } }) result = User.update({"userid": userid}, { "$set": { "firstname": request.json['firstname'], "lastname": request.json['lastname'], "aboutme": request.json['aboutme'], "languagesJSON": [], "educationCSV": [], "workplaceCSV": [], "updateddatetime": datetime.datetime.now(), "isdcode": isdcode, "addressJSON": addressJSON, "skillsJSON": skills, "gender": request.json['gender'], "dob": dob, "locationid": location } }) userdata_array = list( User.find({ "userid": userid, "active": True }, {"_id": 0})) resultArray = {} responseArr = [] if len(userdata_array) > 0: for collectionInfo in userdata_array: # cityname = citycollections.find_one({"cityid":collectionInfo['addressJSON']['city']},{"_id":0}) # allCityData = list(CityCollections.find({}, {"_id": 0, "cityid": 1, "city": 1})) # allcity = [] # if len(allCityData) > 0: # for getAllCityData in allCityData: # allcity.append({"cityid" : getAllCityData['cityid'], "city" : getAllCityData['city']}) location_name = "" if collectionInfo['addressJSON']['city'] != "": citynamedata = CityCollections.find_one( {"cityid": collectionInfo['addressJSON']['city']}, {"_id": 0}) city_name = citynamedata['city'] countrynamedata = CountryCollections.find_one( { "countryid": collectionInfo['addressJSON']['country'] }, {"_id": 0}) country_name = countrynamedata['country'] else: city_name = "" country_name = "" if collectionInfo['locationid'] != "": location_name_data = Locations.find_one( {"locationid": int(collectionInfo['locationid'])}, { "_id": 0, "locationname": 1, "under": 1 }) if location_name_data is not None: if location_name_data['under'] != "": location_name = str( location_name_data['under']) + " - " + str( location_name_data['locationname']) else: location_name = str( location_name_data['locationname']) else: location_name = "" skill_data = collectionInfo['skillsJSON'] skillNameData = [] if len(skill_data) > 0: for skillDataCollections in skill_data: skillNameData.append( skillDataCollections['skillname']) rating = 0 # Rating Initially 0 userReview = list( JobReviews.find( { "touserid": collectionInfo['userid'], "active": True }, { "_id": 0, "rating": 1 })) if len(userReview) > 0: totalUserReview = len(userReview) if userReview is not None: for userRating in userReview: rating = rating + userRating['rating'] tatalRating = int(rating / totalUserReview) else: tatalRating = 0 allCityData = list( CityCollections.find({}, { "_id": 0, "cityid": 1, "city": 1 })) picurlPath = Constants.PROFIL_PIC_STATIC_PATH + collectionInfo[ 'picurl'] portfolioData = list( UserPortfolio.find({ "userid": userid, "active": True, }, {"_id": 0})) documentsPath = Constants.URL + Constants.DOC_PATH portfolioDataPath = Constants.URL + Constants.PORTFOLIO_PATH updateJSON = { "cityname": city_name, "locationName": location_name, "countryname": country_name, "allcity": allCityData, "skillName": skillNameData, "portfolioData": portfolioData, "picurlPath": picurlPath, "userrating": tatalRating, "documentsPath": documentsPath, "portfolioDataPath": portfolioDataPath } collectionInfo.update(updateJSON) responseArr.append(collectionInfo) resultArray['data'] = responseArr else: resultArray['data'] = responseArr return make_response( jsonify({ 'status': 200, 'message': 'Successfull Updated', 'userid': userid, 'token': token, 'updateData': responseArr }), 200) else: return make_response( jsonify({ 'status': 402, 'message': 'No User Found.', 'userid': userid, 'token': token, 'updateData': [] }), 400) except Exception as e: CommonUtils.print_exception() return make_response(jsonify({"status": 500, "message": str(e)}), 500)
def job_all_list(): try: allDataCollections = [] sortDataAccording = request.json['sortDataAccording'] city = request.json.get('city', "") location = request.json.get('location', "") radius = request.json.get('radius', "") jobType = request.json.get('jobType', "") budgetMin = request.json.get('budgetMin', "") budgetMax = request.json.get('budgetMax', '') searchstring = request.json.get('searchstring', '') page_offset = request.json.get('page_offset', 0) result = [] lat = 0 lng = 0 job_location = [] filterstring = { "active": True, "draft": False, "jobstatus": { "$in": ["pending", "reversebid"] } } sort_filter = [] distance_filter_string = { "active": True, "draft": False, "jobstatus": { "$in": ["pending", "reversebid"] } } distance_job = [] startCity = "252347228" if len(searchstring) != 0: stringData = '.*' + searchstring + '.*' getall = [] # for OR conditionOR = { '$options': 'i', '$regex': stringData } # regex condition serchdatainarray = {'title': conditionOR} # for title singleget = {"description": conditionOR} # for description getall.append(serchdatainarray) getall.append(singleget) filterstring['$or'] = getall filterstring['expired'] = False distance_filter_string['expired'] = False mapCoordinate = {} cityResult = CityCollections.find_one({"cityid": int(startCity)}, {"_id": 0}) if cityResult is not None: lat = cityResult['gpsJSON']['lat'] lng = cityResult['gpsJSON']['lng'] mapCoordinate = {"lat": lat, "lng": lng} if radius != "": if location != "": location_result = Locations.find_one( {"locationid": int(location)}, {"_id": 0}) if location_result is not None: lat = location_result['gpsJSON']['lat'] lng = location_result['gpsJSON']['lng'] mapCoordinate = {"lat": lat, "lng": lng} print(mapCoordinate) location_gps_result = Locations.find({ "gpsJSON.lnglat": { "$near": { "$geometry": { "type": "Point", "coordinates": [lng, lat] }, "$maxDistance": int(radius) * 1000 } } }) if location_gps_result is not None: for location_gps in location_gps_result: job_location.append(int(location_gps['locationid'])) elif city != "": city_result = CityCollections.find_one({"cityid": int(city)}, {"_id": 0}) if city_result is not None: lat = city_result['gpsJSON']['lat'] lng = city_result['gpsJSON']['lng'] mapCoordinate = {"lat": lat, "lng": lng} print(mapCoordinate) city_gps_result = Locations.find({ "gpsJSON.lnglat": { "$near": { "$geometry": { "type": "Point", "coordinates": [lng, lat] }, "$maxDistance": int(radius) * 1000 } } }) if city_gps_result is not None: for city_gps in city_gps_result: job_location.append(int(city_gps['locationid'])) elif mapCoordinate: city_gps_result = Locations.find({ "gpsJSON.lnglat": { "$near": { "$geometry": { "type": "Point", "coordinates": [ mapCoordinate.get("lng"), mapCoordinate.get("lat") ] }, "$maxDistance": int(radius) * 1000 } } }) if city_gps_result is not None: for city_gps in city_gps_result: job_location.append(int(city_gps['locationid'])) print(job_location) if jobType != "allJobs": filterstring.update({"online": jobType}) distance_filter_string.update({"online": jobType}) if budgetMin or budgetMax: budget_filter = {"budget": {}} if budgetMin: budget_filter['budget']['$gte'] = int(budgetMin) if budgetMax: budget_filter['budget']['$lte'] = int(budgetMax) filterstring.update(budget_filter) distance_filter_string.update(budget_filter) if job_location: if city: filterstring.update({ "cityid": int(city), "locationid": { "$in": job_location } }) else: filterstring.update({ "cityid": int(startCity), "locationid": { "$in": job_location } }) else: if location: filterstring.update({"locationid": int(location)}) if city: filterstring.update({"cityid": int(city)}) else: filterstring.update({"cityid": int(startCity)}) print(type(location)) print(filterstring) if sortDataAccording == "" or sortDataAccording == "recent": sort_filter.append(("publisheddatetime", -1)) elif sortDataAccording == "price_asc": sort_filter.append(("budget", 1)) elif sortDataAccording == "distance": dist_centre = location if location else city if city else "252347228" dist_city_result = Locations.find_one( {"locationid": int(dist_centre)}, {"_id": 0}) if dist_city_result: dist_lat = dist_city_result['gpsJSON']['lat'] dist_lng = dist_city_result['gpsJSON']['lng'] mapCoordinate = {"lat": dist_lat, "lng": dist_lng} print(mapCoordinate) radius = radius if radius else 50000 distance_gps_result = Locations.aggregate([{ "$geoNear": { "near": { "type": "Point", "coordinates": [dist_lng, dist_lat] }, "maxDistance": radius * 1000, "spherical": True, "distanceField": "distance" } }]) if distance_gps_result is not None: for distance_job_location in distance_gps_result: distance_job.append({ "locationid": distance_job_location['locationid'], "distance": distance_job_location['distance'] }) distance_job = sorted(distance_job, key=lambda k: k['distance']) if city: distance_filter_string.update({ "cityid": int(city), "locationid": int(dist_centre) }) distance_result = Jobs.find(distance_filter_string, { "_id": 0 }).skip(page_offset).limit(Constants.PAGE_LIMIT) if distance_result: for distance in distance_result: result.append(distance) else: for distance in distance_job: distance_filter_string.update({ "cityid": int(dist_centre), "locationid": distance['locationid'] }) print(distance_filter_string) distance_result = Jobs.find(distance_filter_string, { "_id": 0 }).skip(page_offset).limit(Constants.PAGE_LIMIT) if distance_result: for dist in distance_result: result.append(dist) else: sort_filter.append(("budget", -1)) if sortDataAccording != "distance": result = Jobs.find(filterstring, { "_id": 0 }).sort(sort_filter).skip(page_offset).limit(Constants.PAGE_LIMIT) print(result.count()) if result: for resultData in result: # Job bidding Detail jobBids = list( JobBids.find({"jobid": resultData['jobid']}, {"_id": 0})) if resultData.get('creatinguserid', None): if resultData['creatinguserid']: userData = User.find_one( {"userid": int(resultData['creatinguserid'])}, {"_id": 0}) if userData: fullname = userData['firstname'] + " " + userData[ 'lastname'] if resultData['cityid']: cityName = CityCollections.find_one( {"cityid": resultData['cityid']}, { "_id": 0, "city": 1 }) cityName = cityName['city'] else: cityName = "" if userData.get('picurl', ""): picurl = Constants.PROFIL_PIC_STATIC_PATH + userData[ 'picurl'] else: picurl = Constants.PROFIL_PIC_STATIC_PATH + "user-no-image.jpg" location_name = "" if resultData['cityid'] and resultData[ 'locationid']: jobMapResult = Locations.find_one( { "locationid": int( resultData['locationid']) }, {"_id": 0}) location_name = jobMapResult[ 'locationname'] + " - " + jobMapResult[ 'under'] else: if not resultData['cityid']: jobMapCity = 252347228 else: jobMapCity = int(resultData['cityid']) jobMapResult = CityCollections.find_one( {"cityid": jobMapCity}, {"_id": 0}) jobMapCoordinate = {} if jobMapResult is not None: lat = jobMapResult['gpsJSON']['lat'] lng = jobMapResult['gpsJSON']['lng'] jobMapCoordinate = {"lat": lat, "lng": lng} MapResult = CityCollections.find_one( {"cityid": int(resultData['cityid'])}, {"_id": 0}) if MapResult is not None: city_lat = MapResult['gpsJSON']['lat'] city_lng = MapResult['gpsJSON']['lng'] mapCoordinate = { "lat": city_lat, "lng": city_lng } userDataCollection = { "fullname": fullname, "cityname": cityName, "locationname": location_name, "picurl": picurl, "totalJobBids": len(jobBids), "jobMapCoordinate": jobMapCoordinate, "mapCoordinate": mapCoordinate } resultData.update(userDataCollection) allDataCollections.append(resultData) return jsonify({ "status": 200, "message": "Job List.", "allTask": allDataCollections, "countData": len(allDataCollections) }) else: return jsonify({ "status": 200, "message": "No data.", "allTask": result, "countData": len(allDataCollections) }) except Exception as e: CommonUtils.print_exception() return jsonify({"status": 500, "message": str(e)})
def createJob(): try: userid = int(request.json['userid']) token = request.json['token'] userInfo = User.find_one({"userid": int(userid)}, {"_id": 0}) if userInfo is not None: if userInfo['emailverified'] is False: return jsonify({ "status": 202, "message": "Email not verified. Please verify your email to enable this feature" }) jobid = request.json['jobid'] originaljobid = None if (jobid != ""): originaljobid = jobid draft = request.json['draft'] title = request.json['title'] description = request.json['description'] duedate = request.json['duedate'] jobOnline = request.json['jobOnline'] city = int(request.json['city']) location = int(request.json['location']) if duedate == "today": duedate = "" duedate = datetime.now() if duedate == "week": duedate = "" duedate = datetime.now() + timedelta(days=7) if duedate == "certain_day": duedate = "" format = '%d-%m-%Y %H:%M:%S' certaindatetime = request.json['certaindatetime'] duedate = datetime.strptime(certaindatetime, format) citydetail = CityCollections.find_one({"cityid": city}, {"_id": 0}) statedetail = StateCollections.find_one( {"stateid": citydetail['stateid']}, {"_id": 0}) countrydetail = CountryCollections.find_one( {"countryid": citydetail['countryid']}, {"_id": 0}) addressJSON = { "address1": "", "address2": "", "city": city, "state": citydetail['stateid'], "country": countrydetail['countryid'], "pincode": "" } person = request.json['person'] budgettype = request.json['budgettype'] budget = float(request.json['budget']) if budgettype == "hourly": totalhours = int(request.json['hours']) totalbudget = int(budget * totalhours) else: totalhours = -1 totalbudget = budget if draft == False: publisheddatetime = datetime.now() else: publisheddatetime = None if (request.json['draft_data'] == False): jobid = CommonUtils.generateRandomNo(Jobs, "jobid") result = Jobs.insert({ "jobid": jobid, "title": title, "description": description, "creatinguserid": userid, "duedate": duedate, "budget": budget, "budgettype": budgettype, "totalbudget": totalbudget, "totalhours": totalhours, "jobstatus": "pending", "draft": draft, "publisheddatetime": publisheddatetime, "personsrequired": int(person), "reportedJSON": [], "active": True, "cancellationreason": None, "cityid": city, "online": jobOnline, "addressJSON": addressJSON, "locationid": location, "personsselected": 0, "originaljobid": originaljobid, "adminapprovalforcancellation": None, "skillid": None, "tags": None, "updatedatetime": datetime.now(), "createdatetime": datetime.now(), "expired": False }) return jsonify({ 'status': 200, 'message': 'Job Created.', 'jobid': jobid }) else: Jobs.update({"jobid": jobid}, { "$set": { "title": title, "description": description, "creatinguserid": userid, "duedate": duedate, "budget": budget, "budgettype": budgettype, "totalbudget": totalbudget, "totalhours": totalhours, "jobstatus": "pending", "draft": draft, "publisheddatetime": publisheddatetime, "personsrequired": int(person), "reportedJSON": [], "active": True, "cancellationreason": None, "cityid": city, "online": jobOnline, "addressJSON": addressJSON, "locationid": location, "personsselected": 0, "originaljobid": originaljobid, "adminapprovalforcancellation": None, "skillid": None, "tags": None, "updatedatetime": datetime.now(), "expired": False } }) return jsonify({ 'status': 200, 'message': 'Job Updated.', 'jobid': jobid }) except Exception as e: return jsonify({'status': 500, 'message': "error"})
def invoice_list(): userid = int(request.json['userid']) token = request.json['token'] invoiceid = request.json['invoiceid'] if invoiceid == 1: invoiceData = list( Invoice.find({"invoiceid": int(request.json['invoiceid'])}, {"_id": 0})) else: invoiceData = list(Invoice.find({"userid": userid}, {"_id": 0})) invoiceAllData = {} invoiceArray = [] if len(invoiceData) > 0: for invoiceDataArray in invoiceData: # jobsDetail Data jobsDetail = Jobs.find_one( { "jobid": int(invoiceDataArray['jobid']), "active": True }, {"_id": 0}) # Job Created By User createdUserDetail = User.find_one( { "userid": jobsDetail['creatinguserid'], "active": True }, {"_id": 0}) # For job Bid and Comments (How many user bid on this job.) job_biding_count = JobBids.find( { "jobid": invoiceDataArray['jobid'] }, { "_id": 0 }).count() job_comment_count = JobComments.find( { "jobid": invoiceDataArray['jobid'] }, { "_id": 0 }).count() # For User who post this job (How many jobs bid by this user.) if createdUserDetail is not None: user_biding_count = JobBids.find( { "userid": createdUserDetail['userid'] }, { "_id": 0 }).count() user_comment_count = JobComments.find( { "userid": createdUserDetail['userid'] }, { "_id": 0 }).count() # Address Detail for created User citydetail = CityCollections.find_one( {"cityid": createdUserDetail['addressJSON']['city']}, {"_id": 0}) statedetail = StateCollections.find_one( {"stateid": citydetail['stateid']}, {"_id": 0}) countrydetail = CountryCollections.find_one( {"countryid": citydetail['countryid']}, {"_id": 0}) address2 = createdUserDetail['addressJSON']['address2'] address1 = createdUserDetail['addressJSON']['address1'] if address2 == "": fullAddress = address1 + "," else: fullAddress = address1 + ", " + address2 + "," else: fullAddress = "" user_biding_count = 0 user_comment_count = 0 # Billing to User billingUserDetail = User.find_one( { "userid": invoiceDataArray['userid'], "active": True }, {"_id": 0}) # Address Detail for created User billingcitydetail = CountryCollections.find_one( {"cityid": billingUserDetail['addressJSON']['city']}, {"_id": 0}) billingstatedetail = StateCollections.find_one( {"stateid": billingcitydetail['stateid']}, {"_id": 0}) billingcountrydetail = CountryCollections.find_one( {"countryid": billingcitydetail['countryid']}, {"_id": 0}) billingaddress2 = billingUserDetail['addressJSON']['address2'] billingaddress1 = billingUserDetail['addressJSON']['address1'] if billingaddress2 == "": billingfullAddress = billingaddress1 + "," else: billingfullAddress = billingaddress1 + ", " + billingaddress2 + "," createdInfoCollection = { "createdByuserid": createdUserDetail['userid'], "createdByaddressJSON": createdUserDetail['addressJSON'], "createdByemail": createdUserDetail['email'], "createdByfirstname": createdUserDetail['firstname'], "createdBylastname": createdUserDetail['lastname'], "createdBymobile": createdUserDetail['mobile'], "createdByaddress": fullAddress, "createdBycity": citydetail['city'], "createdBystate": statedetail['state'], "createdBycountry": countrydetail['country'], "createdBypincode": createdUserDetail['addressJSON']['pincode'], "createdByactive": createdUserDetail['active'], "createdByuser_biding_count": user_biding_count, "createdByuser_comment_count": user_comment_count, "job_biding_count": job_biding_count, "user_comment_count": user_comment_count, "jobsDetail": jobsDetail, "billinguserid": billingUserDetail['userid'], "billingaddressJSON": billingUserDetail['addressJSON'], "billingemail": billingUserDetail['email'], "billingfirstname": billingUserDetail['firstname'], "billinglastname": billingUserDetail['lastname'], "billingmobile": billingUserDetail['mobile'], "billingaddress": billingfullAddress, "billingcity": billingcitydetail['city'], "billingstate": billingstatedetail['state'], "billingcountry": billingcountrydetail['country'], "billingpincode": billingUserDetail['addressJSON']['pincode'], "billingactive": billingUserDetail['active'], } invoiceDataArray.update(createdInfoCollection) invoiceArray.append(invoiceDataArray) return jsonify({ "status": 200, "message": "Invoice List.", "invoiceAllData": invoiceArray }) else: return jsonify({ "status": 200, "message": "No Data.", "invoiceAllData": invoiceArray })