<s> """<STR_LIT>""" <EOL> from django import forms <EOL> from django . conf import settings <EOL> from django . contrib . sites . models import Site <EOL> from django . contrib . sites . requests import RequestSite <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . core . mail import send_mail <EOL> from django . template import RequestContext , loader <EOL> class ContactForm ( forms . Form ) : <EOL> """<STR_LIT>""" <EOL> name = forms . CharField ( max_length = <NUM_LIT:100> , <EOL> label = _ ( u'<STR_LIT>' ) ) <EOL> email = forms . EmailField ( max_length = <NUM_LIT:200> , <EOL> label = _ ( u'<STR_LIT>' ) ) <EOL> body = forms . CharField ( widget = forms . Textarea , <EOL> label = _ ( u'<STR_LIT>' ) ) <EOL> from_email = settings . DEFAULT_FROM_EMAIL <EOL> recipient_list = [ mail_tuple [ <NUM_LIT:1> ] for mail_tuple in settings . MANAGERS ] <EOL> subject_template_name = "<STR_LIT>" <EOL> template_name = '<STR_LIT>' <EOL> def __init__ ( self , data = None , files = None , request = None , <EOL> recipient_list = None , * args , ** kwargs ) : <EOL> if request is None : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . request = request <EOL> if recipient_list is not None : <EOL> self . recipient_list = recipient_list <EOL> super ( ContactForm , self ) . __init__ ( data = data , files = files , <EOL> * args , ** kwargs ) <EOL> def message ( self ) : <EOL> """<STR_LIT>""" <EOL> if callable ( self . template_name ) : <EOL> template_name = self . template_name ( ) <EOL> else : <EOL> template_name = self . template_name <EOL> return loader . render_to_string ( template_name , <EOL> self . get_context ( ) ) <EOL> def subject ( self ) : <EOL> """<STR_LIT>""" <EOL> template_name = self . subject_template_name ( ) if callable ( self . subject_template_name ) else self . subject_template_name <EOL> subject = loader . render_to_string ( template_name , <EOL> self . get_context ( ) ) <EOL> return '<STR_LIT>' . join ( subject . splitlines ( ) ) <EOL> def get_context ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . is_valid ( ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> if Site . _meta . installed : <EOL> site = Site . objects . get_current ( ) <EOL> else : <EOL> site = RequestSite ( self . request ) <EOL> return RequestContext ( self . request , <EOL> dict ( self . cleaned_data , <EOL> site = site ) ) <EOL> def get_message_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . is_valid ( ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> message_dict = { } <EOL> for message_part in ( '<STR_LIT>' , '<STR_LIT:message>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> attr = getattr ( self , message_part ) <EOL> message_dict [ message_part ] = attr ( ) if callable ( attr ) else attr <EOL> return message_dict <EOL> def save ( self , fail_silently = False ) : <EOL> """<STR_LIT>""" <EOL> send_mail ( fail_silently = fail_silently , ** self . get_message_dict ( ) ) </s>
