Beispiel #1
0
    def post(self):
        data = grade_parser.parse_args()
        p = ParticipationModel.query.filter_by(action_id = data['action_id'], volunteer_id = data['volunteer_id']).first()
        v = Volunteer.query.filter_by(id = data['volunteer_id']).first()
        a = ActionModel.query.filter_by(id = data['action_id']).first()

        claims = get_jwt_claims()
        user = get_user_from_claim(claims)

        if not a or a.organisation_id != user.id:
            return {'message':'To nie jest akcja Twojej organizacji'}, 403

        if a.end_date > datetime.now():
            return {'message':'Akcja sie nie zakonczyla'}, 400

        if p and (not p.grade):
            p.grade = True
            v.points += data['points']
            v.save_to_db()
            p.save_to_db()

            return {'message':'Wolontariusz oceniony'}, 200

        else:
            return {'message':'Dany wolontariusz nie może zostać oceniony w tej akcji'}, 404
Beispiel #2
0
    def get(self):
        claims = get_jwt_claims()
        user = get_user_from_claim(claims)

        if claims['type'] == 'volunteer':
            return VolunteersSerializer(user).serialize()
        elif claims['type'] == 'organisation':
            return OrganisationSerializer(user).serialize()
        else:
            return {'message': 'Error, du not nou'}, 500
Beispiel #3
0
 def delete(self, action_id):
     a = ActionModel.query.filter_by(id=action_id).first()
     claims = get_jwt_claims()
     user = get_user_from_claim(claims)
     if a:
         if a in user.actions:
             a.delete()
             rebuild_cache.delay()
             return {'message': 'Akcje o id: {} usunieta.'.format(action_id)}, 200
         else:
             return {'message': 'To nie jest akcja twojej organizacji'}, 403
     else:
         return self.non_exists()
Beispiel #4
0
    def delete(self, action_id):
        c = get_jwt_claims()
        u = get_user_from_claim(c)
        p = ParticipationModel.query.filter_by(action_id=action_id,
                                               volunteer_id=u.id).first()

        if p and not p.grade:
            p.delete()
            return {
                'message':
                'Anulowano udział w akcji o id: {}'.format(action_id)
            }, 200
        else:
            return {'message': 'Brak mozliwosci anulowania udzialu'}, 400
Beispiel #5
0
    def get(self, action_id=None):
        a = None
        actions = []
        claims = get_jwt_claims()
        user = get_user_from_claim(claims)

        for p in ParticipationModel.query.filter_by(volunteer_id=user.id):
            a = ActionModel.query.filter_by(id=p.action_id).first()
            actions.append(ActionSerializer(a).serialize())

        if a:
            return actions, 200
        else:
            return {
                'message': 'Użytkownik nie jest zapisany do żadnej akcji'
            }, 404
Beispiel #6
0
    def get(self):
        actions = []

        claims = get_jwt_claims()
        user = get_user_from_claim(claims)

        if isinstance(user, Organisation):
            qs = ActionModel.query.filter(ActionModel.organisation_id==user.id)
            for action in qs:
                actions.append(
                    ActionSerializer(action).serialize()
                )
        else:
            qs = mongo.db[str(user.location)].find({}, {'_id': False})
            actions = json.loads(dumps(qs))

        return actions
Beispiel #7
0
    def put(self, action_id):
        args = action_update_parser.parse_args()

        a = ActionModel.query.filter_by(id=action_id).first()
        claims = get_jwt_claims()
        user = get_user_from_claim(claims)
        if a:
            if a in user.actions:
                for atr, val in args.items():
                    setattr(a, atr, val)
                a.save_to_db()
                rebuild_cache.delay()
                return {'message': 'Akcje o id: {} zmodyfikowana.'.format(action_id)}, 200
            else:
                return {'message': 'To nie jest akcja twojej organizacji'}, 403
        else:
            return self.non_exists()
Beispiel #8
0
    def post(self, action_id):
        claims = get_jwt_claims()
        user = get_user_from_claim(claims)

        a = ActionModel.query.filter_by(id=action_id).first()
        ex = ParticipationModel.query.filter_by(action_id=action_id,
                                                volunteer_id=user.id).first()

        p = ParticipationModel(action_id=action_id, volunteer_id=user.id)

        if ex or (a and a.end_date < datetime.now()):
            return {
                'message': "Uzytkownik nie moze byc zapisany do tej akcji"
            }, 400

        if a:
            p.save_to_db()
            return {
                'message': 'Dolaczono do akcji o id: {}'.format(action_id)
            }, 200
        else:
            return {'message': 'Dana akcja nie istnieje'}, 404
Beispiel #9
0
    def post(self):
        args = action_parser.parse_args()
        claims = get_jwt_claims()
        o = get_user_from_claim(claims)
        g = GeoMarkerModel(**args['geo'])
        a = ActionModel(
            name=args['name'],
            points=args['points'],
            end_date=args['end_date'],
            geo_loc=g,
        )

        if args.get('start_date'):
            a.start_date = args['start_date']

        try:
            o.actions.append(a)
            o.save_to_db()
        except Exception:
            return {'message': 'Blad serwera'}, 500

        rebuild_cache.delay()

        return {'message': 'Stowrzono akcje id: {}'.format(a.id)}, 201