Esempio n. 1
0
def join(invite_id, user):
    try:
        invitation = db.session.query(CircleInviteModel).filter(
            CircleInviteModel.id == invite_id).first()
        if invitation is None:
            raise e_circle.InvitationNotFound
        if invitation.user_id != user.id:
            raise e_circle.UnallowedToUseInvitation
        link = UserToCircle(privilege="MEMBRE")
        link.user = invitation.user
        link.circle = invitation.circle
        db.session.delete(invitation)
        db.session.commit()
        link.circle.notify_users(p1='circle',
                                 p2={
                                     'event': 'join',
                                     'user': link.user.email
                                 })
        link.circle.notify_mobile(
            title="Cercle",
            body=("%s à rejoins le cercle %s" %
                  (link.user.first_name, link.circle.name)),
            ignore=[link.user.id])
        response = {"data": {"success": True}, "status_code": 200}
    except e_circle.CircleException as exception:
        response = {
            "data": {
                "success": False,
                "message": exception.message
            },
            "status_code": exception.status_code
        }
    return response
Esempio n. 2
0
def create(name, user):
    try:
        circle = Circle(name)
        link = UserToCircle(privilege="REGULAR")
        link.circle = circle
        link.user = user
        db.session.commit()
        response = {
            "data": {
                "success": True,
                "content": circle.get_simple_content()
            },
            "status_code": 200
        }
    except e_circle.CircleException as exception:
        response = {
            "data": {
                "success": False,
                "message": exception.message
            },
            "status_code": exception.status_code
        }
    return response