<s> """<STR_LIT>""" <EOL> from django . core . urlresolvers import reverse_lazy <EOL> from django . core . validators import validate_email <EOL> from django . core . exceptions import ValidationError <EOL> from django . http import Http404 , HttpResponse <EOL> from django . views . generic import CreateView , TemplateView , View <EOL> from open_connect . accounts . utils import generate_nologin_hash <EOL> from open_connect . accounts . models import User <EOL> from open_connect . mailer . models import Unsubscribe <EOL> from open_connect . mailer . utils import url_representation_decode , create_open <EOL> BASE64_TRANS_GIF = '<STR_LIT>' <EOL> class OpenView ( View ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> result , verification_hash = url_representation_decode ( <EOL> self . kwargs [ '<STR_LIT>' ] ) <EOL> if verification_hash != self . kwargs [ '<STR_LIT>' ] : <EOL> raise Http404 <EOL> necessary_keys = [ '<STR_LIT:e>' , '<STR_LIT:k>' , '<STR_LIT:t>' ] <EOL> if not all ( [ key in result for key in necessary_keys ] ) : <EOL> raise Http404 <EOL> create_open ( result , request . META ) <EOL> return HttpResponse ( <EOL> BASE64_TRANS_GIF . decode ( '<STR_LIT>' ) , content_type = '<STR_LIT>' <EOL> ) <EOL> class UnsubscribeView ( CreateView ) : <EOL> """<STR_LIT>""" <EOL> model = Unsubscribe <EOL> template_name = "<STR_LIT>" <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> fields = [ ] <EOL> def dispatch ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not all ( key in request . GET for key in ( '<STR_LIT:email>' , '<STR_LIT:code>' ) ) : <EOL> raise Http404 <EOL> self . email = request . GET [ '<STR_LIT:email>' ] <EOL> try : <EOL> validate_email ( self . email ) <EOL> except ValidationError : <EOL> raise Http404 <EOL> if request . GET [ '<STR_LIT:code>' ] != generate_nologin_hash ( self . email . lower ( ) ) : <EOL> raise Http404 <EOL> return super ( UnsubscribeView , self ) . dispatch ( request , * args , ** kwargs ) <EOL> def form_valid ( self , form ) : <EOL> """<STR_LIT>""" <EOL> form . instance . address = self . email <EOL> form . instance . source = '<STR_LIT:user>' <EOL> return super ( UnsubscribeView , self ) . form_valid ( form ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = super ( UnsubscribeView , self ) . get_context_data ( ** kwargs ) <EOL> try : <EOL> context [ '<STR_LIT>' ] = User . objects . get ( email = self . email ) <EOL> except User . DoesNotExist : <EOL> pass <EOL> context [ '<STR_LIT:email>' ] = self . email <EOL> return context <EOL> class UnsubscribeThanksView ( TemplateView ) : <EOL> """<STR_LIT>""" <EOL> template_name = "<STR_LIT>" </s>
