def receiver_registeration(): user_context = get_pring_context(request) bottles = request.form.get("bottles") specificity = True if request.form.get("specificity") == "yes" else False Request.create_request({'guid': user_context["UserGUID"],'bottles': int(bottles), 'specificity': specificity}) if specificity: raise Exception("Not Implemented") #return render_template('register_user_receiver_s.html') return render_template('register_user_receiver_complete.html')
def user_matching(): user_context = get_pring_context(request) user_guid = user_context["UserGUID"] req = Request.get_request_from_user_id(user_guid) if not req: return "</p>You dont have an open request at a moment</p>" user_names = [] if not req["specificity"]: newtime = time.mktime(datetime.datetime.now().timetuple()) matchedtime = newtime - 4*31*24*3600 matched_users = User.collection.find({}) for matched_user in matched_users: if "last_donation_date" not in matched_user: continue if matched_user["last_donation_date"] < matchedtime: #This will be replaced with Pring User Name user_names.append(matched_user["name"]) req["bottles"] -= 1 matched_user["last_donation_date"] = newtime matched_user.save() req.save() if req["bottles"] <= 0: req["is_matched"] = True req.save() break if user_names: return "<p>Please message the following users on pring %s</p>"%(",".join(user_names)) else: return "<p>System unable to detect matches please try again</p>"