<s> from __future__ import absolute_import <EOL> from django . contrib import admin <EOL> from django . contrib . admin . models import DELETION <EOL> from django . contrib . auth . admin import UserAdmin <EOL> from django . contrib . auth . forms import PasswordResetForm <EOL> from django . contrib . auth . models import Permission <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . html import escape <EOL> from admin . common_auth . logs import OSFLogEntry <EOL> from admin . common_auth . forms import CustomUserRegistrationForm <EOL> from admin . common_auth . models import MyUser <EOL> class PermissionAdmin ( admin . ModelAdmin ) : <EOL> search_fields = [ '<STR_LIT:name>' , '<STR_LIT>' ] <EOL> class CustomUserAdmin ( UserAdmin ) : <EOL> add_form = CustomUserRegistrationForm <EOL> list_display = [ '<STR_LIT:email>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> fieldsets = ( <EOL> ( None , { '<STR_LIT>' : ( '<STR_LIT:email>' , '<STR_LIT:password>' , ) } ) , <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:email>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) } ) , <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) } ) , <EOL> ) <EOL> add_fieldsets = ( <EOL> ( None , { '<STR_LIT>' : <EOL> ( '<STR_LIT:email>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } ) , ) <EOL> search_fields = ( '<STR_LIT:email>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> ordering = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> actions = [ '<STR_LIT>' ] <EOL> def send_email_invitation ( self , request , queryset ) : <EOL> for user in queryset : <EOL> reset_form = PasswordResetForm ( { '<STR_LIT:email>' : user . email } , request . POST ) <EOL> assert reset_form . is_valid ( ) <EOL> reset_form . save ( <EOL> request = request <EOL> ) <EOL> self . message_user ( request , '<STR_LIT>' ) <EOL> send_email_invitation . short_description = '<STR_LIT>' <EOL> def save_model ( self , request , obj , form , change ) : <EOL> if change : <EOL> pass <EOL> else : <EOL> obj . is_active = False <EOL> obj . save ( ) <EOL> admin . site . register ( MyUser , CustomUserAdmin ) <EOL> admin . site . register ( Permission , PermissionAdmin ) <EOL> class LogEntryAdmin ( admin . ModelAdmin ) : <EOL> date_hierarchy = '<STR_LIT>' <EOL> readonly_fields = [ f . name for f in OSFLogEntry . _meta . get_fields ( ) ] <EOL> list_filter = [ <EOL> '<STR_LIT:user>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> search_fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> list_display = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:user>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:message>' , <EOL> ] <EOL> def has_add_permission ( self , request ) : <EOL> return False <EOL> def has_change_permission ( self , request , obj = None ) : <EOL> return request . user . is_superuser and request . method != '<STR_LIT:POST>' <EOL> def has_delete_permission ( self , request , obj = None ) : <EOL> return False <EOL> def object_link ( self , obj ) : <EOL> if obj . action_flag == DELETION : <EOL> link = escape ( obj . object_repr ) <EOL> elif obj . content_type is None : <EOL> link = escape ( obj . object_repr ) <EOL> else : <EOL> ct = obj . content_type <EOL> link = u'<STR_LIT>' % ( <EOL> reverse ( '<STR_LIT>' % ( ct . app_label , ct . model ) , args = [ obj . object_id ] ) , <EOL> escape ( obj . object_repr ) , <EOL> ) <EOL> return link <EOL> object_link . allow_tags = True <EOL> object_link . admin_order_field = '<STR_LIT>' <EOL> object_link . short_description = u'<STR_LIT:object>' <EOL> def queryset ( self , request ) : <EOL> return super ( LogEntryAdmin , self ) . queryset ( request ) . prefetch_related ( '<STR_LIT>' ) <EOL> admin . site . register ( OSFLogEntry , LogEntryAdmin ) </s>
