<s> from __future__ import unicode_literals <EOL> from rest_framework . permissions import BasePermission as Permission <EOL> class BasePermission ( Permission ) : <EOL> _methods_map = { <EOL> '<STR_LIT:GET>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> def has_permission ( self , request , view ) : <EOL> perms = self . _get_default_permissions ( request . method , view ) <EOL> return request . user . has_perms ( perms ) <EOL> class RelatedPermission ( BasePermission ) : <EOL> def _get_default_permissions ( self , method , view ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { <EOL> '<STR_LIT>' : view . model . _meta . app_label , <EOL> '<STR_LIT>' : view . model . _meta . model_name , <EOL> } <EOL> perms1 = [ perm % kwargs for perm in self . _methods_map [ method ] ] <EOL> kwargs = { <EOL> '<STR_LIT>' : view . relation . _related_model . _meta . app_label , <EOL> '<STR_LIT>' : view . relation . _related_model . _meta . model_name , <EOL> } <EOL> perms2 = [ perm % kwargs for perm in self . _methods_map [ method ] ] <EOL> return perms1 + perms2 <EOL> def has_permission ( self , request , view ) : <EOL> view . generate_relation ( ) <EOL> return super ( RelatedPermission , self ) . has_permission ( request , view ) <EOL> class DetailPermission ( BasePermission ) : <EOL> def _get_default_permissions ( self , method , view ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { <EOL> '<STR_LIT>' : view . model . _meta . app_label , <EOL> '<STR_LIT>' : view . model . _meta . model_name , <EOL> } <EOL> return [ perm % kwargs for perm in self . _methods_map [ method ] ] </s>
