Example #1
0
 def get_marshaller():
     return {
         'id':
         fields.Integer,
         'time_created':
         fields.DateTime,
         'time_updated':
         fields.DateTime,
         'start_time':
         fields.DateTime,
         'end_time':
         fields.DateTime,
         'owner':
         fields.Nested(UserModel.get_marshaller()),
         'community':
         fields.Nested(CommunityModel.get_marshaller()),
         'start_km':
         fields.String,
         'end_km':
         fields.String,
         'parking_position':
         fields.String,
         'comment':
         fields.String,
         'is_force_finished':
         fields.Boolean,
         'force_finished_by':
         fields.Nested(UserModel.get_marshaller(), allow_null=True),
         'is_open':
         fields.Boolean,
         'passengers':
         fields.Nested(UserModel.get_marshaller())
     }
Example #2
0
class SingleCommunity(Resource):
    @jwt_required
    @marshal_with(CommunityModel.get_detailed_marshaller())
    def get(self, id):

        user = UserModel.find_by_username(get_jwt_identity())

        community = CommunityModel.find_by_id(id)
        if not community:
            abort(404, message=COMMUNIY_DOESNT_EXIST)

        if user not in community.users:
            abort(401, message=UNAUTHORIZED)

        is_owner = CommunityUserLinkModel.find_by_user_and_community(
            user.id, community.id).is_owner
        community.is_deletable = is_owner
        community.is_editable = is_owner

        return community, 200

    @jwt_required
    @marshal_with(CommunityModel.get_marshaller())
    def put(self, id):
        data = put_parser.parse_args()

        community = CommunityModel.find_by_id(id)

        if not community:
            abort(404, message=COMMUNIY_DOESNT_EXIST)

        community.name = data['name']
        community.persist()

        return community, 200

    @jwt_required
    @marshal_with(SimpleMessage.get_marshaller())
    def delete(self, id):
        user = UserModel.find_by_username(get_jwt_identity())

        try:
            link = CommunityUserLinkModel.find_by_user_and_community(
                user.id, id)
            if not link or not link.is_owner:
                abort(401, message=UNAUTHORIZED)
        except NoData:
            abort(404, message=COMMUNIY_DOESNT_EXIST)

        all_links = CommunityUserLinkModel.find_by_community(id)
        for link in all_links:
            link.delete()

        try:
            CommunityModel.delete_by_id(id)
        except NoData:
            abort(404, message=COMMUNIY_DOESNT_EXIST)

        return SimpleMessage(COMMUNIY_DELETED), 200
Example #3
0
 def get_marshaller():
     return {
         'community': fields.Nested(CommunityModel.get_marshaller()),
         'statistic_start': fields.DateTime,
         'statistic_end': fields.DateTime,
         'km_per_user': fields.Nested(KmPerUserModel.get_marshaller()),
         'costs_per_user': fields.Nested(CostsPerUserModel.get_marshaller())
     }
Example #4
0
class FavouriteCommunity(Resource):
    @jwt_required
    @marshal_with(CommunityModel.get_marshaller())
    def get(self):
        user = UserModel.find_by_username(get_jwt_identity())
        cul = CommunityUserLinkModel.find_favourite_by_user(user.id)

        if not cul:
            abort(404, message=NO_FAVOURITE_COMMUNITY_FOUND)

        return cul.community, 200
Example #5
0
 def get_marshaller():
     return {
         'id': fields.Integer,
         'time_created': fields.DateTime,
         'time_updated': fields.DateTime,
         'time_next_instance': fields.DateTime,
         'time_interval': TimedeltaDays,
         'owner': fields.Nested(UserModel.get_marshaller()),
         'community': fields.Nested(CommunityModel.get_marshaller()),
         'name': fields.String,
         'description': fields.String,
         'km_interval': fields.Integer,
         'km_next_instance': fields.Float,
         'km_to_next_instance': fields.Float,
         'is_reocurrent': fields.Boolean
     }
Example #6
0
 def get_marshaller():
     return {
         'community': fields.Nested(CommunityModel.get_marshaller()),
         'time_created': fields.DateTime,
         'time_updated': fields.DateTime,
     }