def post(self, id=None): data = request.get_json(force=True, silent=False) if 'rewards' in data: reward_list = [] for reward in data['rewards']: reward_list.append(Reward(**reward)) data['rewards'] = reward_list if 'organization' in data: org = Organization.objects.get_or_404(id=data['organization']) data['organization'] = org if 'name' not in data: return helpers.api_error('Please enter an appropriate name for your project!', 400), 400 user = User.objects.get_or_404(id=data['creator']) for key, value in data.iteritems(): if key in ['start_date', 'end_date', 'fulfilled_date', 'published']: data[key] = datetime.strptime(value['date'], "%Y-%m-%d %H:%M:%S") else: data[key] = value data['creator'] = user proj = Project(**data) proj.updated = datetime.utcnow() try: proj.save() except ValidationError as e: return helpers.api_error(e.message, 400), 400 except NotUniqueError as e: return helpers.api_error(e.message, 409), 409 except Exception: return helpers.api_error("Something went wrong! Check your request parameters!", 500), 500 ml = MarketingList(project=proj.id, contacts=[], pledge_conversion=0, convert_conversion=0, total_donated=0) ml.save() return helpers.api_return("OK", proj.updated, proj.id, 'Project')
def post(self, ml_id, id=None): data = request.get_json(force=True, silent=False) contact = Contact(**data) email = contact.email contact.updated = datetime.utcnow() ml = 0 if email is not None: ml = MarketingList.objects(id=ml_id, contacts__email=email).update(set__contacts__S=contact) if ml == 0: contact.con_id = ObjectId() ml = MarketingList.objects(id=ml_id).update(push__contacts=contact) return helpers.api_return("OK", datetime.utcnow(), contact.con_id, "Contact")
def post(self, id=None): data = request.get_json(force=True, silent=False) proj = Project.objects.get_or_404(id=data["project"]) transaction = Transaction( fullname=data["fullname"], email=data["email"], project=proj, total_amt=data["total_amt"], giga_fee=data["giga_fee"], trans_fee=data["trans_fee"], net_amt=data["net_amt"], stripe_id=data["stripe_id"], survey_fields=data["survey_fields"], ) if "comment" in data: transaction.comment = data["comment"] if "referring_user" in data: ref = User.objects.get_or_404(id=data["referring_user"]) transaction.referring_user = ref if "organization" in data: org = Organization.objects.get_or_404(id=data["organization"]) transaction.organization = org if "user" in data: user = User.objects.get_or_404(id=data["user"]) transaction.user = user transaction.updated = datetime.utcnow() transaction.created = datetime.utcnow() try: transaction.save() except ValidationError as e: return helpers.api_error(e.message, 400), 400 except NotUniqueError as e: return helpers.api_error(e.message, 409), 409 except Exception: return helpers.api_error("Something went wrong! Check your request parameters!", 500), 500 if data["project"] == "5341f31c21391d0d902b29f1" or data["project"] == "5341f12d242f872d43ffae59": rmc_email.delay(data["email"], data["project"]) proj.update( inc__total_raised=data["total_amt"], inc__total_giga_fee=data["giga_fee"], inc__total_trans_fee=data["trans_fee"], inc__total_net_raised=data["net_amt"], add_to_set__donor_list=data["email"], ) ml = MarketingList.objects(project=proj.id, contacts__email=data["email"]).update( set__contacts__S__status="converted", set__contacts__S__donated=data["total_amt"] ) if ml > 0: ml = MarketingList.objects(project=proj.id).update( inc__convert_conversion=1, inc__total_donated=data["total_amt"] ) return helpers.api_return("OK", transaction.updated, transaction.id, "Transaction")
def post(self, id=None): data = request.get_json(force=True, silent=False) ml = MarketingList(**data) ml.updated = datetime.utcnow() try: ml.save() except ValidationError as e: return helpers.api_error(e.message, 400), 400 except NotUniqueError as e: return helpers.api_error(e.message, 409), 409 except Exception: return helpers.api_error("Something went wrong! Check your request parameters!", 500), 500 return helpers.api_return('OK', ml.updated, ml.id, 'MarketingList')
def delete(self, ml_id, id): email = request.args.get("email", None) if ml_id is None or email is None: return helpers.api_error("No Contact ID Provided!", 404), 404 else: ml = MarketingList.objects(id=ml_id).update(pull__contacts__email=email) return helpers.api_return("DELETED", datetime.utcnow(), ml_id, "Contact")
def put(self, ml_id, id): data = request.get_json(force=True, silent=False) contact = Contact(**data) contact.con_id = id contact.updated = datetime.utcnow() ml = MarketingList.objects(id=ml_id, contacts__con_id=id).update(set__contacts__S=contact) return helpers.api_return("OK", datetime.utcnow(), ml_id, "Contact")