Пример #1
0
    def save(self, commit=True):
        # Create nomination
        nomination = super(NominateNewPersonForm, self).save(commit=False)
        nominator_email = self.cleaned_data.get('nominator_email', None)
        candidate_email = self.cleaned_data['candidate_email']
        candidate_name = self.cleaned_data['candidate_name']
        position = self.cleaned_data['position']
        qualifications = self.cleaned_data['qualifications']
        confirmation = self.cleaned_data.get('confirmation', False)
        share_nominator = self.cleaned_data['share_nominator']
        nomcom_template_path = '/nomcom/%s/' % self.nomcom.group.acronym


        author = None
        if self.public:
            author = get_user_email(self.user)
        else:
            if nominator_email:
                emails = Email.objects.filter(address=nominator_email)
                author = emails and emails[0] or None
        ## This is where it should change - validation of the email field should fail if the email exists
        ## The function should become make_nominee_from_newperson)
        nominee = make_nomineeposition_for_newperson(self.nomcom, candidate_name, candidate_email, position, author)

        # Complete nomination data
        feedback = Feedback.objects.create(nomcom=self.nomcom,
                                           comments=qualifications,
                                           type=FeedbackTypeName.objects.get(slug='nomina'),
                                           user=self.user)
        feedback.positions.add(position)
        feedback.nominees.add(nominee)

        if author:
            nomination.nominator_email = author.address
            feedback.author = author.address
            feedback.save()

        nomination.nominee = nominee
        nomination.comments = feedback
        nomination.share_nominator = share_nominator
        nomination.user = self.user

        if commit:
            nomination.save()

        # send receipt email to nominator
        if confirmation:
            if author:
                subject = 'Nomination receipt'
                from_email = settings.NOMCOM_FROM_EMAIL.format(year=self.nomcom.year())
                (to_email, cc) = gather_address_lists('nomination_receipt_requested',nominator=author.address)
                context = {'nominee': nominee.email.person.name,
                          'comments': qualifications,
                          'position': position.name,
                          'year': self.nomcom.year(),
                      }
                path = nomcom_template_path + NOMINATION_RECEIPT_TEMPLATE
                send_mail(None, to_email, from_email, subject, path, context, cc=cc)

        return nomination
Пример #2
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)

        super(NominateForm, self).__init__(*args, **kwargs)

        fieldset = ['position',
                    'candidate_name',
                    'candidate_email', 'candidate_phone',
                    'comments']

        if self.nomcom:
            self.fields['position'].queryset = Position.objects.get_by_nomcom(self.nomcom).opened()
            self.fields['comments'].help_text = self.nomcom.initial_text

        if not self.public:
            fieldset = ['nominator_email'] + fieldset
            author = get_user_email(self.user)
            if author:
                self.fields['nominator_email'].initial = author.address
                help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                               nomination wishes to be anonymous. The confirmation email will be sent to the address given here,
                               and the address will also be captured as part of the registered nomination.)"""
                self.fields['nominator_email'].help_text = help_text
        else:
            fieldset.append('confirmation')

        self.fieldsets = [('Candidate Nomination', fieldset)]
Пример #3
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)

        super(NominateForm, self).__init__(*args, **kwargs)

        new_person_url_name = 'ietf.nomcom.views.%s_nominate_newperson' % ('public' if self.public else 'private' )
        self.fields['searched_email'].label = 'Candidate email'
        self.fields['searched_email'].help_text = 'Search by name or email address. Click <a href="%s">here</a> if the search does not find the candidate you want to nominate.' % reverse(new_person_url_name,kwargs={'year':self.nomcom.year()})
        self.fields['nominator_email'].label = 'Nominator email'
        if self.nomcom:
            self.fields['position'].queryset = Position.objects.get_by_nomcom(self.nomcom).filter(is_open=True)
            if self.public:
                self.fields['position'].queryset = self.fields['position'].queryset.filter(accepting_nominations=True)
            self.fields['qualifications'].help_text = self.nomcom.initial_text

        if not self.public:
            self.fields.pop('confirmation')
            author = get_user_email(self.user)
            if author:
                self.fields['nominator_email'].initial = author.address
                help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                               nomination wishes to be anonymous. The confirmation email will be sent to the address given here,
                               and the address will also be captured as part of the registered nomination.)"""
                self.fields['nominator_email'].help_text = help_text
                self.fields['share_nominator'].help_text = """(Nomcom Chair/Member: Check this box if the person providing this nomination
                                                              has indicated they will allow NomCom to share their name as one of the people
                                                              nominating this candidate."""
        else:
            self.fields.pop('nominator_email')
Пример #4
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)

        super(NominateNewPersonForm, self).__init__(*args, **kwargs)

        self.fields['nominator_email'].label = 'Nominator email'
        if self.nomcom:
            self.fields['position'].queryset = Position.objects.get_by_nomcom(self.nomcom).filter(is_open=True)
            if self.public:
                self.fields['position'].queryset = self.fields['position'].queryset.filter(accepting_nominations=True)  
            self.fields['qualifications'].help_text = self.nomcom.initial_text

        if not self.public:
            self.fields.pop('confirmation')
            author = get_user_email(self.user)
            if author:
                self.fields['nominator_email'].initial = author.address
                help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                               nomination wishes to be anonymous. The confirmation email will be sent to the address given here,
                               and the address will also be captured as part of the registered nomination.)"""
                self.fields['nominator_email'].help_text = help_text
                self.fields['share_nominator'].help_text = """(Nomcom Chair/Member: Check this box if the person providing this nomination
                                                              has indicated they will allow NomCom to share their name as one of the people
                                                              nominating this candidate."""
        else:
            self.fields.pop('nominator_email')
Пример #5
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)

        super(NominateForm, self).__init__(*args, **kwargs)

        fieldset = [
            'position', 'candidate_name', 'candidate_email', 'candidate_phone',
            'comments'
        ]

        if self.nomcom:
            self.fields['position'].queryset = Position.objects.get_by_nomcom(
                self.nomcom).opened()
            self.fields['comments'].help_text = self.nomcom.initial_text

        if not self.public:
            fieldset = ['nominator_email'] + fieldset
            author = get_user_email(self.user)
            if author:
                self.fields['nominator_email'].initial = author.address
                help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                               nomination wishes to be anonymous. The confirmation email will be sent to the address given here,
                               and the address will also be captured as part of the registered nomination.)"""
                self.fields['nominator_email'].help_text = help_text
        else:
            fieldset.append('confirmation')

        self.fieldsets = [('Candidate Nomination', fieldset)]
Пример #6
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)

        super(NominateNewPersonForm, self).__init__(*args, **kwargs)

        self.fields['nominator_email'].label = 'Nominator email'
        if self.nomcom:
            self.fields['position'].queryset = Position.objects.get_by_nomcom(self.nomcom).opened()
            self.fields['qualifications'].help_text = self.nomcom.initial_text

        if not self.public:
            self.fields.pop('confirmation')
            author = get_user_email(self.user)
            if author:
                self.fields['nominator_email'].initial = author.address
                help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                               nomination wishes to be anonymous. The confirmation email will be sent to the address given here,
                               and the address will also be captured as part of the registered nomination.)"""
                self.fields['nominator_email'].help_text = help_text
                self.fields['share_nominator'].help_text = """(Nomcom Chair/Member: Check this box if the person providing this nomination
                                                              has indicated they will allow NomCom to share their name as one of the people
                                                              nominating this candidate."""
        else:
            self.fields.pop('nominator_email')
Пример #7
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)

        super(NominateForm, self).__init__(*args, **kwargs)

        new_person_url_name = 'nomcom_%s_nominate_newperson' % ('public' if self.public else 'private' )
        self.fields['searched_email'].label = 'Candidate email'
        self.fields['searched_email'].help_text = 'Search by name or email address. Click <a href="%s">here</a> if the search does not find the candidate you want to nominate.' % reverse(new_person_url_name,kwargs={'year':self.nomcom.year()})
        self.fields['nominator_email'].label = 'Nominator email'
        if self.nomcom:
            self.fields['position'].queryset = Position.objects.get_by_nomcom(self.nomcom).opened()
            self.fields['qualifications'].help_text = self.nomcom.initial_text

        if not self.public:
            self.fields.pop('confirmation')
            author = get_user_email(self.user)
            if author:
                self.fields['nominator_email'].initial = author.address
                help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                               nomination wishes to be anonymous. The confirmation email will be sent to the address given here,
                               and the address will also be captured as part of the registered nomination.)"""
                self.fields['nominator_email'].help_text = help_text
                self.fields['share_nominator'].help_text = """(Nomcom Chair/Member: Check this box if the person providing this nomination
                                                              has indicated they will allow NomCom to share their name as one of the people
                                                              nominating this candidate."""
        else:
            self.fields.pop('nominator_email')
Пример #8
0
    def save(self, commit=True):
        # Create nomination
        nomination = super(NominateNewPersonForm, self).save(commit=False)
        nominator_email = self.cleaned_data.get('nominator_email', None)
        candidate_email = self.cleaned_data['candidate_email']
        candidate_name = self.cleaned_data['candidate_name']
        position = self.cleaned_data['position']
        qualifications = self.cleaned_data['qualifications']
        confirmation = self.cleaned_data.get('confirmation', False)
        share_nominator = self.cleaned_data['share_nominator']
        nomcom_template_path = '/nomcom/%s/' % self.nomcom.group.acronym


        author = None
        if self.public:
            author = get_user_email(self.user)
        else:
            if nominator_email:
                emails = Email.objects.filter(address=nominator_email)
                author = emails and emails[0] or None
        ## This is where it should change - validation of the email field should fail if the email exists
        ## The function should become make_nominee_from_newperson)
        nominee = make_nomineeposition_for_newperson(self.nomcom, candidate_name, candidate_email, position, author)

        # Complete nomination data
        feedback = Feedback.objects.create(nomcom=self.nomcom,
                                           comments=qualifications,
                                           type=FeedbackTypeName.objects.get(slug='nomina'),
                                           user=self.user)
        feedback.positions.add(position)
        feedback.nominees.add(nominee)

        if author:
            nomination.nominator_email = author.address
            feedback.author = author.address
            feedback.save()

        nomination.nominee = nominee
        nomination.comments = feedback
        nomination.share_nominator = share_nominator
        nomination.user = self.user

        if commit:
            nomination.save()

        # send receipt email to nominator
        if confirmation:
            if author:
                subject = 'Nomination receipt'
                from_email = settings.NOMCOM_FROM_EMAIL
                (to_email, cc) = gather_address_lists('nomination_receipt_requested',nominator=author.address)
                context = {'nominee': nominee.email.person.name,
                          'comments': qualifications,
                          'position': position.name}
                path = nomcom_template_path + NOMINATION_RECEIPT_TEMPLATE
                send_mail(None, to_email, from_email, subject, path, context, cc=cc)

        return nomination
Пример #9
0
    def save(self, commit=True):
        # Create nomination
        nomination = super(NominateForm, self).save(commit=False)
        nominator_email = self.cleaned_data.get('nominator_email', None)
        candidate_email = self.cleaned_data['candidate_email']
        candidate_name = self.cleaned_data['candidate_name']
        position = self.cleaned_data['position']
        comments = self.cleaned_data['comments']
        confirmation = self.cleaned_data['confirmation']
        nomcom_template_path = '/nomcom/%s/' % self.nomcom.group.acronym

        author = None
        if self.public:
            author = get_user_email(self.user)
        else:
            if nominator_email:
                emails = Email.objects.filter(address=nominator_email)
                author = emails and emails[0] or None
        nominee = get_or_create_nominee(self.nomcom, candidate_name,
                                        candidate_email, position, author)

        # Complete nomination data
        feedback = Feedback.objects.create(
            nomcom=self.nomcom,
            comments=comments,
            type=FeedbackType.objects.get(slug='nomina'),
            user=self.user)
        feedback.positions.add(position)
        feedback.nominees.add(nominee)

        if author:
            nomination.nominator_email = author.address
            feedback.author = author
            feedback.save()

        nomination.nominee = nominee
        nomination.comments = feedback
        nomination.user = self.user

        if commit:
            nomination.save()

        # send receipt email to nominator
        if confirmation:
            if author:
                subject = 'Nomination Receipt'
                from_email = settings.NOMCOM_FROM_EMAIL
                to_email = author.address
                context = {
                    'nominee': nominee.email.person.name,
                    'comments': comments,
                    'position': position.name
                }
                path = nomcom_template_path + NOMINATION_RECEIPT_TEMPLATE
                send_mail(None, to_email, from_email, subject, path, context)

        return nomination
Пример #10
0
    def save(self, commit=True):
        # Create nomination
        nomination = super(NominateForm, self).save(commit=False)
        nominator_email = self.cleaned_data.get('nominator_email', None)
        candidate_email = self.cleaned_data['candidate_email']
        candidate_name = self.cleaned_data['candidate_name']
        position = self.cleaned_data['position']
        comments = self.cleaned_data['comments']
        confirmation = self.cleaned_data['confirmation']
        nomcom_template_path = '/nomcom/%s/' % self.nomcom.group.acronym

        author = None
        if self.public:
            author = get_user_email(self.user)
        else:
            if nominator_email:
                emails = Email.objects.filter(address=nominator_email)
                author = emails and emails[0] or None
        nominee = get_or_create_nominee(self.nomcom, candidate_name, candidate_email, position, author)

        # Complete nomination data
        feedback = Feedback.objects.create(nomcom=self.nomcom,
                                           comments=comments,
                                           type=FeedbackType.objects.get(slug='nomina'),
                                           user=self.user)
        feedback.positions.add(position)
        feedback.nominees.add(nominee)

        if author:
            nomination.nominator_email = author.address
            feedback.author = author
            feedback.save()

        nomination.nominee = nominee
        nomination.comments = feedback
        nomination.user = self.user

        if commit:
            nomination.save()

        # send receipt email to nominator
        if confirmation:
            if author:
                subject = 'Nomination Receipt'
                from_email = settings.NOMCOM_FROM_EMAIL
                to_email = author.address
                context = {'nominee': nominee.email.person.name,
                          'comments': comments,
                          'position': position.name}
                path = nomcom_template_path + NOMINATION_RECEIPT_TEMPLATE
                send_mail(None, to_email, from_email, subject, path, context)

        return nomination
Пример #11
0
def add_num_nominations(user, position, nominee):
    author = get_user_email(user)

    count = Feedback.objects.filter(positions__in=[position],
                                    nominees__in=[nominee],
                                    author=author,
                                    type='comment').count()
    if count:
        mark = """<span style="white-space: pre; color: red;">*</span>"""
    else:
        mark = """<span style="white-space: pre;"> </span> """

    return '<span title="%d earlier comments from you on %s as %s">%s</span>&nbsp;' % (count, nominee.email.address, position, mark)
Пример #12
0
def add_num_nominations(user, position, nominee):
    author = get_user_email(user)

    count = Feedback.objects.filter(positions__in=[position],
                                    nominees__in=[nominee],
                                    author=author,
                                    type='comment').count()
    if count:
        mark = """<span style="white-space: pre; color: red;">*</span>"""
    else:
        mark = """<span style="white-space: pre;"> </span> """

    return '<span title="%d earlier comments from you on %s as %s">%s</span>&nbsp;' % (
        count, nominee.email.address, position, mark)
Пример #13
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)
        self.position = kwargs.pop('position', None)
        self.nominee = kwargs.pop('nominee', None)

        super(FeedbackForm, self).__init__(*args, **kwargs)

        readonly_fields = ['position_name',
                           'nominee_name',
                           'nominee_email']

        fieldset = ['position_name',
                    'nominee_name',
                    'nominee_email',
                    'nominator_email',
                    'comments']

        if self.public:
            readonly_fields += ['nominator_email']
            fieldset.append('confirmation')
        else:
            help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                            comments wishes to be anonymous. The confirmation email will be sent to the address given here,
                            and the address will also be captured as part of the registered nomination.)"""
            self.fields['nominator_email'].help_text = help_text
            self.fields['nominator_email'].required = False

        author = get_user_email(self.user)
        if author:
            self.fields['nominator_email'].initial = author.address

        if self.position and self.nominee:
            self.fields['position_name'].initial = self.position.name
            self.fields['nominee_name'].initial = self.nominee.email.person.name
            self.fields['nominee_email'].initial = self.nominee.email.address
        else:
            help_text = "Please pick a name on the nominees list"
            self.fields['position_name'].initial = help_text
            self.fields['nominee_name'].initial = help_text
            self.fields['nominee_email'].initial = help_text
            self.fields['comments'].initial = help_text
            readonly_fields += ['comments']
            self.fields['confirmation'].widget.attrs['disabled'] = "disabled"

        for field in readonly_fields:
            self.fields[field].widget.attrs['readonly'] = True

        self.fieldsets = [('Provide comments', fieldset)]
Пример #14
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)
        self.position = kwargs.pop('position', None)
        self.nominee = kwargs.pop('nominee', None)

        super(FeedbackForm, self).__init__(*args, **kwargs)

        readonly_fields = ['position_name', 'nominee_name', 'nominee_email']

        fieldset = [
            'position_name', 'nominee_name', 'nominee_email',
            'nominator_email', 'comments'
        ]

        if self.public:
            readonly_fields += ['nominator_email']
            fieldset.append('confirmation')
        else:
            help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                            comments wishes to be anonymous. The confirmation email will be sent to the address given here,
                            and the address will also be captured as part of the registered nomination.)"""
            self.fields['nominator_email'].help_text = help_text
            self.fields['nominator_email'].required = False

        author = get_user_email(self.user)
        if author:
            self.fields['nominator_email'].initial = author.address

        if self.position and self.nominee:
            self.fields['position_name'].initial = self.position.name
            self.fields[
                'nominee_name'].initial = self.nominee.email.person.name
            self.fields['nominee_email'].initial = self.nominee.email.address
        else:
            help_text = "Please pick a name on the nominees list"
            self.fields['position_name'].initial = help_text
            self.fields['nominee_name'].initial = help_text
            self.fields['nominee_email'].initial = help_text
            self.fields['comments'].initial = help_text
            readonly_fields += ['comments']
            self.fields['confirmation'].widget.attrs['disabled'] = "disabled"

        for field in readonly_fields:
            self.fields[field].widget.attrs['readonly'] = True

        self.fieldsets = [('Provide comments', fieldset)]
Пример #15
0
    def save(self, commit=True):
        feedback = super(QuestionnaireForm, self).save(commit=False)
        (position, nominee) = self.cleaned_data['nominee']

        author = get_user_email(self.user)

        if author:
            feedback.author = author

        feedback.nomcom = self.nomcom
        feedback.user = self.user
        feedback.type = FeedbackType.objects.get(slug='questio')
        feedback.save()
        self.save_m2m()
        feedback.nominees.add(nominee)
        feedback.positions.add(position)
Пример #16
0
    def save(self, commit=True):
        feedback = super(QuestionnaireForm, self).save(commit=False)
        (position, nominee) = self.cleaned_data['nominee']

        author = get_user_email(self.user)

        if author:
            feedback.author = author

        feedback.nomcom = self.nomcom
        feedback.user = self.user
        feedback.type = FeedbackType.objects.get(slug='questio')
        feedback.save()
        self.save_m2m()
        feedback.nominees.add(nominee)
        feedback.positions.add(position)
Пример #17
0
    def save(self, commit=True):
        feedback = super(FeedbackForm, self).save(commit=False)
        confirmation = self.cleaned_data['confirmation']
        comments = self.cleaned_data['comments']
        nomcom_template_path = '/nomcom/%s/' % self.nomcom.group.acronym

        author = None
        if self.public:
            author = get_user_email(self.user)
        else:
            nominator_email = self.cleaned_data['nominator_email']
            if nominator_email:
                emails = Email.objects.filter(address=nominator_email)
                author = emails and emails[0] or None

        if author:
            feedback.author = author.address

        feedback.nomcom = self.nomcom
        feedback.user = self.user
        feedback.type = FeedbackTypeName.objects.get(slug='comment')
        feedback.save()
        if self.nominee and self.position:
            feedback.positions.add(self.position)
            feedback.nominees.add(self.nominee)
        if self.topic:
            feedback.topics.add(self.topic)

        # send receipt email to feedback author
        if confirmation:
            if author:
                subject = "NomCom comment confirmation"
                from_email = settings.NOMCOM_FROM_EMAIL.format(year=self.nomcom.year())
                (to_email, cc) = gather_address_lists('nomcom_comment_receipt_requested',commenter=author.address)
                if self.nominee and self.position:
                    about = '%s for the position of\n%s'%(self.nominee.email.person.name, self.position.name)
                elif self.topic:
                    about = self.topic.subject
                context = {'about': about,
                           'comments': comments,
                           'year': self.nomcom.year(),
                       }
                path = nomcom_template_path + FEEDBACK_RECEIPT_TEMPLATE
                # TODO - make the thing above more generic
                send_mail(None, to_email, from_email, subject, path, context, cc=cc)
Пример #18
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)
        self.position = kwargs.pop('position', None)
        self.nominee = kwargs.pop('nominee', None)

        super(FeedbackForm, self).__init__(*args, **kwargs)

        author = get_user_email(self.user)

        if self.public:
            self.fields.pop('nominator_email')
        else:
            help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                            comments wishes to be anonymous. The confirmation email will be sent to the address given here,
                            and the address will also be captured as part of the registered nomination.)"""
            self.fields['nominator_email'].help_text = help_text
            self.fields['confirmation'].label = 'Email these comments in cleartext to the provided commenter email address' 
            if author:
                self.fields['nominator_email'].initial = author.address
Пример #19
0
    def __init__(self, *args, **kwargs):
        self.nomcom = kwargs.pop('nomcom', None)
        self.user = kwargs.pop('user', None)
        self.public = kwargs.pop('public', None)
        self.position = kwargs.pop('position', None)
        self.nominee = kwargs.pop('nominee', None)
        self.topic = kwargs.pop('topic', None)

        super(FeedbackForm, self).__init__(*args, **kwargs)

        author = get_user_email(self.user)

        if self.public:
            self.fields.pop('nominator_email')
        else:
            help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
                            comments wishes to be anonymous. The confirmation email will be sent to the address given here,
                            and the address will also be captured as part of the registered nomination.)"""
            self.fields['nominator_email'].help_text = help_text
            self.fields['confirmation'].label = 'Email these comments in cleartext to the provided commenter email address' 
            if author:
                self.fields['nominator_email'].initial = author.address
Пример #20
0
    def save(self, commit=True):
        feedback = super(FeedbackForm, self).save(commit=False)
        confirmation = self.cleaned_data['confirmation']
        comments = self.cleaned_data['comments']
        nominator_email = self.cleaned_data['nominator_email']
        nomcom_template_path = '/nomcom/%s/' % self.nomcom.group.acronym

        author = None
        if self.public:
            author = get_user_email(self.user)
        else:
            if nominator_email:
                emails = Email.objects.filter(address=nominator_email)
                author = emails and emails[0] or None

        if author:
            feedback.author = author

        feedback.nomcom = self.nomcom
        feedback.user = self.user
        feedback.type = FeedbackType.objects.get(slug='comment')
        feedback.save()
        feedback.positions.add(self.position)
        feedback.nominees.add(self.nominee)

        # send receipt email to feedback author
        if confirmation:
            if author:
                subject = "NomCom comment confirmation"
                from_email = settings.NOMCOM_FROM_EMAIL
                to_email = author.address
                context = {
                    'nominee': self.nominee.email.person.name,
                    'comments': comments,
                    'position': self.position.name
                }
                path = nomcom_template_path + FEEDBACK_RECEIPT_TEMPLATE
                send_mail(None, to_email, from_email, subject, path, context)
Пример #21
0
    def save(self, commit=True):
        feedback = super(FeedbackForm, self).save(commit=False)
        confirmation = self.cleaned_data['confirmation']
        comments = self.cleaned_data['comments']
        nominator_email = self.cleaned_data['nominator_email']
        nomcom_template_path = '/nomcom/%s/' % self.nomcom.group.acronym

        author = None
        if self.public:
            author = get_user_email(self.user)
        else:
            if nominator_email:
                emails = Email.objects.filter(address=nominator_email)
                author = emails and emails[0] or None

        if author:
            feedback.author = author

        feedback.nomcom = self.nomcom
        feedback.user = self.user
        feedback.type = FeedbackType.objects.get(slug='comment')
        feedback.save()
        feedback.positions.add(self.position)
        feedback.nominees.add(self.nominee)

        # send receipt email to feedback author
        if confirmation:
            if author:
                subject = "NomCom comment confirmation"
                from_email = settings.NOMCOM_FROM_EMAIL
                to_email = author.address
                context = {'nominee': self.nominee.email.person.name,
                           'comments': comments,
                           'position': self.position.name}
                path = nomcom_template_path + FEEDBACK_RECEIPT_TEMPLATE
                send_mail(None, to_email, from_email, subject, path, context)