<s> from braces . views import LoginRequiredMixin <EOL> from django . contrib . auth import authenticate , login <EOL> from django . conf import settings <EOL> from django . core . mail import send_mail <EOL> from django . core . urlresolvers import reverse <EOL> from django . http import Http404 <EOL> from django . shortcuts import render , redirect <EOL> from django . utils import timezone <EOL> from django . utils . decorators import method_decorator <EOL> from django . views . generic import ( <EOL> CreateView , DetailView , ListView , TemplateView , UpdateView <EOL> ) <EOL> from honeypot . decorators import check_honeypot <EOL> from . forms import ( <EOL> UserProfileForm , MembershipForm , MembershipUpdateForm , <EOL> ) <EOL> from . models import User , Membership <EOL> class MembershipCreate ( LoginRequiredMixin , CreateView ) : <EOL> model = Membership <EOL> form_class = MembershipForm <EOL> template_name = '<STR_LIT>' <EOL> @ method_decorator ( check_honeypot ) <EOL> def dispatch ( self , * args , ** kwargs ) : <EOL> if not self . request . user . is_authenticated ( ) : <EOL> return redirect ( '<STR_LIT>' ) <EOL> if self . request . user . has_membership : <EOL> return redirect ( '<STR_LIT>' ) <EOL> return super ( ) . dispatch ( * args , ** kwargs ) <EOL> def get_form_kwargs ( self ) : <EOL> kwargs = super ( ) . get_form_kwargs ( ) <EOL> if self . request . user . email : <EOL> kwargs [ '<STR_LIT>' ] = { '<STR_LIT>' : self . request . user . email } <EOL> return kwargs <EOL> def form_valid ( self , form ) : <EOL> self . object = form . save ( commit = False ) <EOL> if self . request . user . is_authenticated ( ) : <EOL> self . object . creator = self . request . user <EOL> self . object . save ( ) <EOL> if settings . MAILING_LIST_PSF_MEMBERS and self . object . psf_announcements : <EOL> send_mail ( <EOL> subject = '<STR_LIT>' , <EOL> message = '<STR_LIT>' , <EOL> from_email = self . object . creator . email , <EOL> recipient_list = [ settings . MAILING_LIST_PSF_MEMBERS ] , <EOL> ) <EOL> return super ( ) . form_valid ( form ) <EOL> def get_success_url ( self ) : <EOL> return reverse ( '<STR_LIT>' ) <EOL> class MembershipUpdate ( LoginRequiredMixin , UpdateView ) : <EOL> form_class = MembershipUpdateForm <EOL> model = Membership <EOL> template_name = '<STR_LIT>' <EOL> @ method_decorator ( check_honeypot ) <EOL> def dispatch ( self , * args , ** kwargs ) : <EOL> return super ( ) . dispatch ( * args , ** kwargs ) <EOL> def get_object ( self ) : <EOL> if self . request . user . has_membership : <EOL> return self . request . user . membership <EOL> else : <EOL> raise Http404 ( ) <EOL> def form_valid ( self , form ) : <EOL> self . object = form . save ( commit = False ) <EOL> if self . request . user . is_authenticated ( ) : <EOL> self . object . creator = self . request . user <EOL> self . object . save ( ) <EOL> return super ( ) . form_valid ( form ) <EOL> def get_success_url ( self ) : <EOL> return reverse ( '<STR_LIT>' ) <EOL> class MembershipThanks ( TemplateView ) : <EOL> template_name = '<STR_LIT>' <EOL> class MembershipVoteAffirm ( TemplateView ) : <EOL> template_name = '<STR_LIT>' <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . request . user . membership . votes = True <EOL> self . request . user . membership . last_vote_affirmation = timezone . now ( ) <EOL> self . request . user . membership . save ( ) <EOL> return redirect ( '<STR_LIT>' ) <EOL> class MembershipVoteAffirmDone ( TemplateView ) : <EOL> template_name = '<STR_LIT>' <EOL> class UserUpdate ( LoginRequiredMixin , UpdateView ) : <EOL> form_class = UserProfileForm <EOL> model = User <EOL> slug_field = '<STR_LIT:username>' <EOL> template_name = '<STR_LIT>' <EOL> @ method_decorator ( check_honeypot ) <EOL> def dispatch ( self , * args , ** kwargs ) : <EOL> return super ( ) . dispatch ( * args , ** kwargs ) <EOL> def get_object ( self , queryset = None ) : <EOL> return User . objects . get ( username = self . request . user ) <EOL> class UserDetail ( DetailView ) : <EOL> model = User <EOL> slug_field = '<STR_LIT:username>' <EOL> def get_queryset ( self ) : <EOL> queryset = super ( ) . get_queryset ( ) <EOL> if self . request . user . username == self . kwargs [ '<STR_LIT>' ] : <EOL> return queryset . select_related ( ) <EOL> return queryset . searchable ( ) <EOL> class UserList ( ListView ) : <EOL> model = User <EOL> paginate_by = <NUM_LIT> <EOL> def get_queryset ( self ) : <EOL> return super ( ) . get_queryset ( ) . searchable ( ) </s>
