def post(self, quiz_id, contact_group=None):
        session = authorize(request.headers["Authorization"])

        if contact_group is None: contact_group = "default"

        contacts = self.get_contacts(contact_group, session.get("user").get("login"))

        if contacts is None:
            return {"message": "no contact to send"}, 400

        criteria = {"createdBy": session.get('user').get('login'), "_id": int(quiz_id)}
        quiz = Quiz.quiz_from_dict(mongo.db.quiz.find_one_or_404(criteria))

        for contact in contacts:
            c = Contact.contact_from_dict(contact)
            p = Publication()
            p._id = get_id("publication")
            p.creationDate = datetime.now()
            p.hash = hashlib.sha256("%d.%s" % (p._id, str(p.creationDate))).hexdigest()
            p.by = session.get('user').get('login')
            p.quiz = quiz
            p.to = c
            mongo.db.publications.insert(p.format())
            self.send_email(quiz.title, p.hash, c.email, c.language)

        return {"message": "quiz %s published to %d contacts" % (quiz.title, len(contacts))}, 200
    def post(self, group_name=None):
        session = authorize(request.headers["Authorization"])
        print session

        contacts = post_parser.parse_args().get("contacts")
        if contacts is None:
            abort(403)

        if group_name is None: group_name = "default"

        new_contacts = 0
        existing_contact = 0
        for contact in contacts:
            print contact
            contact = Contact.contact_from_dict(contact)
            existing = mongo.db.contacts.find_one({"email": contact.email})

            if existing is None:
                contact._id = get_id("contacts")
                contact.creationDate = datetime.now()
                contact.createdBy = session.get("user").get("login")
                if contact.language is None:
                    contact.language = "fr"

                mongo.db.contacts.insert(contact.format())

                self.update_group(group_name, contact.createdBy, contact)

                new_contacts += 1
            else:
                existing_contact += 1
                contact = Contact.contact_from_dict(existing)
                self.update_group(group_name, contact.createdBy, contact)

        return {"inserted": new_contacts, "existing": existing_contact}, 200
    def post(self):
        session = authorize(request.headers["Authorization"])

        quiz_input = creation_parser.parse_args()
        quiz = Quiz.quiz_from_dict(quiz_input)
        quiz.creationDate = datetime.now()
        quiz.createdBy = session.get('user').get('login')
        """ we create the quiz first """
        quiz._id = int(get_id("quiz"))
        print "\n", quiz.format()
        mongo.db.quiz.insert(quiz.format())
        """ we create questions as objects and we embbed them into the quiz"""
        for qst in quiz.questions:
            self.add_question(qst, quiz)

        return {"quiz_id": "%s" % (quiz._id)}, 201
    def post(self, group_name=None):
        session = authorize(request.headers["Authorization"])
        print session

        contacts = post_parser.parse_args().get("contacts")
        if contacts is None:
            abort(403)

        if group_name is None: group_name = "default"

        new_contacts = 0
        existing_contact = 0
        for contact in contacts:
            print contact
            contact = Contact.contact_from_dict(contact)
            existing = mongo.db.contacts.find_one({"email": contact.email})

            if existing is None:
                contact._id = get_id("contacts")
                contact.creationDate = datetime.now()
                contact.createdBy = session.get("user").get("login")
                if contact.language is None:
                    contact.language = "fr"

                mongo.db.contacts.insert(contact.format())

                self.update_group(group_name, contact.createdBy, contact)

                new_contacts += 1
            else:
                existing_contact += 1
                contact = Contact.contact_from_dict(existing)
                self.update_group(group_name, contact.createdBy, contact)



        return {"inserted": new_contacts, "existing": existing_contact}, 200