def get_workshop_emails(workshop_id): # Well, I could use aggregation, but it is not implemented in mongomock :( data = get_db().workshops.find_one({"workshopId": workshop_id}, {"emails.emailId": 0}) if data is None: return error_response("Workshop %s not found" % workshop_id), 404 emails = [EmailMessage.from_db_dict(email).as_response() for email in data['emails']] json_data = jsonify(emails=emails) return json_data
def get_workshop_emails(workshop_id): # Well, I could use aggregation, but it is not implemented in mongomock :( data = get_db().workshops.find_one({"workshopId": workshop_id}, {"emails.emailId": 0}) if data is None: return error_response("Workshop %s not found" % workshop_id), 404 emails = [ EmailMessage.from_db_dict(email).as_response() for email in data['emails'] ] json_data = jsonify(emails=emails) return json_data
def register_new_user_for_workshop(workshop_id, attender_email): user = get_db().users.find_one({"email": attender_email}) if user is None: return error_response("User %s not found" % attender_email), 412 elif user['isConfirmed'] is not True: return error_response("User %s not confirmed" % attender_email), 412 workshop = get_db().workshops.find_and_modify( query={"workshopId": workshop_id}, update={"$addToSet": {"users": attender_email}} ) if workshop is None: return error_response("Workshop %s not found" % workshop_id), 404 if attender_email in workshop['users']: return error_response("User %s is already registered for %s" % (attender_email, workshop_id)), 304 workshop['emails'] = [EmailMessage.from_db_dict(e) for e in workshop['emails']] ensure_mails_were_sent_to_users(workshop['emails'], [attender_email], workshop) return success_response("User %s registered for %s" % (attender_email, workshop_id)), 200
def register_new_user_for_workshop(workshop_id, attender_email): user = get_db().users.find_one({"email": attender_email}) if user is None: return error_response("User %s not found" % attender_email), 412 elif user['isConfirmed'] is not True: return error_response("User %s not confirmed" % attender_email), 412 workshop = get_db().workshops.find_and_modify( query={"workshopId": workshop_id}, update={"$addToSet": { "users": attender_email }}) if workshop is None: return error_response("Workshop %s not found" % workshop_id), 404 if attender_email in workshop['users']: return error_response("User %s is already registered for %s" % (attender_email, workshop_id)), 304 workshop['emails'] = [ EmailMessage.from_db_dict(e) for e in workshop['emails'] ] ensure_mails_were_sent_to_users(workshop['emails'], [attender_email], workshop) return success_response("User %s registered for %s" % (attender_email, workshop_id)), 200