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")
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")