<s> from django . contrib . admin . views . decorators import staff_member_required <EOL> from django . contrib . auth . forms import UserCreationForm , AdminPasswordChangeForm <EOL> from django . contrib . auth . models import User <EOL> from django . core . exceptions import PermissionDenied <EOL> from django import oldforms , template <EOL> from django . shortcuts import render_to_response , get_object_or_404 <EOL> from django . http import HttpResponseRedirect <EOL> from django . utils . html import escape <EOL> def user_add_stage ( request ) : <EOL> if not request . user . has_perm ( '<STR_LIT>' ) : <EOL> raise PermissionDenied <EOL> manipulator = UserCreationForm ( ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> new_data = request . POST . copy ( ) <EOL> errors = manipulator . get_validation_errors ( new_data ) <EOL> if not errors : <EOL> new_user = manipulator . save ( new_data ) <EOL> msg = _ ( '<STR_LIT>' ) % { '<STR_LIT:name>' : '<STR_LIT:user>' , '<STR_LIT>' : new_user } <EOL> if request . POST . has_key ( "<STR_LIT>" ) : <EOL> request . user . message_set . create ( message = msg ) <EOL> return HttpResponseRedirect ( request . path ) <EOL> else : <EOL> request . user . message_set . create ( message = msg + '<STR_LIT:U+0020>' + _ ( "<STR_LIT>" ) ) <EOL> return HttpResponseRedirect ( '<STR_LIT>' % new_user . id ) <EOL> else : <EOL> errors = new_data = { } <EOL> form = oldforms . FormWrapper ( manipulator , new_data , errors ) <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT:title>' : _ ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : request . REQUEST . has_key ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : ( ) , <EOL> '<STR_LIT>' : ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : User . _meta , <EOL> '<STR_LIT>' : User . _meta . get_field ( '<STR_LIT:username>' ) . help_text , <EOL> } , context_instance = template . RequestContext ( request ) ) <EOL> user_add_stage = staff_member_required ( user_add_stage ) <EOL> def user_change_password ( request , id ) : <EOL> if not request . user . has_perm ( '<STR_LIT>' ) : <EOL> raise PermissionDenied <EOL> user = get_object_or_404 ( User , pk = id ) <EOL> manipulator = AdminPasswordChangeForm ( user ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> new_data = request . POST . copy ( ) <EOL> errors = manipulator . get_validation_errors ( new_data ) <EOL> if not errors : <EOL> new_user = manipulator . save ( new_data ) <EOL> msg = _ ( '<STR_LIT>' ) <EOL> request . user . message_set . create ( message = msg ) <EOL> return HttpResponseRedirect ( '<STR_LIT:..>' ) <EOL> else : <EOL> errors = new_data = { } <EOL> form = oldforms . FormWrapper ( manipulator , new_data , errors ) <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT:title>' : _ ( '<STR_LIT>' ) % escape ( user . username ) , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : request . REQUEST . has_key ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : User . _meta , <EOL> '<STR_LIT>' : user , <EOL> '<STR_LIT>' : True , <EOL> } , context_instance = template . RequestContext ( request ) ) <EOL> user_change_password = staff_member_required ( user_change_password ) </s>
