<s> """<STR_LIT>""" <EOL> from datetime import datetime <EOL> from flask import json , request , g , make_response <EOL> from flask . views import MethodView <EOL> from mongoengine import ValidationError <EOL> from tentd . lib . flask import EntityBlueprint , jsonify <EOL> from tentd . utils . exceptions import APIBadRequest <EOL> from tentd . utils . auth import require_authorization <EOL> from tentd . documents import Notification <EOL> from tentd . documents . profiles import Profile , CoreProfile <EOL> entity = EntityBlueprint ( '<STR_LIT>' , __name__ ) <EOL> @ entity . route_class ( '<STR_LIT>' , endpoint = '<STR_LIT>' ) <EOL> class ProfilesView ( MethodView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> return jsonify ( { p . schema : p . to_json ( ) <EOL> for p in g . entity . profiles <EOL> if '<STR_LIT>' in p . permissions <EOL> and p . permissions [ '<STR_LIT>' ] } ) <EOL> @ require_authorization <EOL> def post ( self ) : <EOL> """<STR_LIT>""" <EOL> if not '<STR_LIT>' in request . json ( ) : <EOL> raise APIBadRequest ( "<STR_LIT>" ) <EOL> return jsonify ( Profile ( entity = g . entity , ** request . json ( ) ) . save ( ) ) <EOL> @ entity . route_class ( '<STR_LIT>' , endpoint = '<STR_LIT>' ) <EOL> class ProfileView ( MethodView ) : <EOL> """<STR_LIT>""" <EOL> @ require_authorization <EOL> def get ( self , schema ) : <EOL> """<STR_LIT>""" <EOL> return jsonify ( g . entity . profiles . get_or_404 ( schema = schema ) ) <EOL> def put ( self , schema ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> profile = g . entity . profiles . get ( schema = schema ) <EOL> profile . update_values ( request . json ( ) ) <EOL> except Profile . DoesNotExist : <EOL> profile = Profile ( <EOL> entity = g . entity , schema = schema , ** request . json ( ) ) <EOL> return jsonify ( profile . save ( ) ) <EOL> def delete ( self , schema ) : <EOL> """<STR_LIT>""" <EOL> if schema == CoreProfile . __schema__ : <EOL> raise APIBadRequest ( '<STR_LIT>' ) <EOL> profile = g . entity . profiles . get_or_404 ( schema = schema ) <EOL> profile . delete ( ) <EOL> return make_response ( ) , <NUM_LIT:200> <EOL> @ entity . route_class ( '<STR_LIT>' , endpoint = '<STR_LIT>' ) <EOL> class NotificationView ( MethodView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> return make_response ( ) , <NUM_LIT:200> <EOL> def post ( self ) : <EOL> """<STR_LIT>""" <EOL> post_data = request . json ( ) <EOL> notification = Notification ( ) <EOL> notification . entity = g . entity <EOL> notification . post_id = post_data [ '<STR_LIT:id>' ] <EOL> notification . received_at = datetime . utcnow ( ) <EOL> notification . save ( ) <EOL> return make_response ( ) , <NUM_LIT:200> </s>
