示例#1
0
    def commprev(self, request, tl, one, two, module, extra, prog):
        from esp.users.models import PersistentQueryFilter
        from django.conf import settings

        filterid, listcount, subject, body = [request.POST['filterid'],
                                              request.POST['listcount'],
                                              request.POST['subject'],
                                              request.POST['body']    ]
        sendto_fn_name = request.POST.get('sendto_fn_name', MessageRequest.SEND_TO_SELF_REAL)

        # Set From address
        if request.POST.get('from', '').strip():
            fromemail = request.POST['from']
        else:
            # String together an address like [email protected]
            fromemail = '%s@%s' % (request.user.username, settings.SITE_INFO[1])

        # Set Reply-To address
        if request.POST.get('replyto', '').strip():
            replytoemail = request.POST['replyto']
        else:
            replytoemail = fromemail

        try:
            filterid = int(filterid)
        except:
            raise ESPError("Corrupted POST data!  Please contact us at [email protected] and tell us how you got this error, and we'll look into it.")

        userlist = PersistentQueryFilter.getFilterFromID(filterid, ESPUser).getList(ESPUser)

        try:
            firstuser = userlist[0]
        except:
            raise ESPError("You seem to be trying to email 0 people!  Please go back, edit your search, and try again.")

        MessageRequest.assert_is_valid_sendto_fn_or_ESPError(sendto_fn_name)

        #   If they were trying to use HTML, don't sanitize the content.
        if '<html>' not in body:
            htmlbody = body.replace('<', '&lt;').replace('>', '&gt;').replace('\n', '<br />')
        else:
            htmlbody = body

        contextdict = {'user'   : ActionHandler(firstuser, firstuser),
                       'program': ActionHandler(self.program, firstuser) }

        renderedtext = Template(htmlbody).render(DjangoContext(contextdict))

        return render_to_response(self.baseDir()+'preview.html', request,
                                              {'filterid': filterid,
                                               'sendto_fn_name': sendto_fn_name,
                                               'listcount': listcount,
                                               'subject': subject,
                                               'from': fromemail,
                                               'replyto': replytoemail,
                                               'body': body,
                                               'renderedtext': renderedtext})
示例#2
0
    def commpanel(self, request, tl, one, two, module, extra, prog):

        usc = UserSearchController()

        context = {}

        #   If list information was submitted, continue to prepare a message
        if request.method == 'POST':
            #   Turn multi-valued QueryDict into standard dictionary
            data = {}
            for key in request.POST:
                data[key] = request.POST[key]

            ##  Handle normal list selecting submissions
            if ('base_list' in data and 'recipient_type' in data) or ('combo_base_list' in data):


                filterObj = usc.filter_from_postdata(prog, data)
                sendto_fn_name = usc.sendto_fn_from_postdata(data)
                sendto_fn = MessageRequest.assert_is_valid_sendto_fn_or_ESPError(sendto_fn_name)

                if data['use_checklist'] == '1':
                    (response, unused) = get_user_checklist(request, ESPUser.objects.filter(filterObj.get_Q()).distinct(), filterObj.id, '/manage/%s/commpanel_old' % prog.getUrlBase())
                    return response

                context['filterid'] = filterObj.id
                context['sendto_fn_name'] = sendto_fn_name
                context['listcount'] = self.approx_num_of_recipients(filterObj, sendto_fn)
                return render_to_response(self.baseDir()+'step2.html', request, context)

            ##  Prepare a message starting from an earlier request
            elif 'msgreq_id' in data:
                msgreq = MessageRequest.objects.get(id=data['msgreq_id'])
                context['filterid'] = msgreq.recipients.id
                context['sendto_fn_name'] = msgreq.sendto_fn_name
                sendto_fn = MessageRequest.assert_is_valid_sendto_fn_or_ESPError(msgreq.sendto_fn_name)
                context['listcount'] = self.approx_num_of_recipients(msgreq.recipients, sendto_fn)
                context['from'] = msgreq.sender
                context['subject'] = msgreq.subject
                context['replyto'] = msgreq.special_headers_dict.get('Reply-To', '')
                context['body'] = msgreq.msgtext
                return render_to_response(self.baseDir()+'step2.html', request, context)

            else:
                raise ESPError('What do I do without knowing what kind of users to look for?', log=True)

        #   Otherwise, render a page that shows the list selection options
        context.update(usc.prepare_context(prog))

        return render_to_response(self.baseDir()+'commpanel_new.html', request, context)
示例#3
0
    def commfinal(self, request, tl, one, two, module, extra, prog):
        from esp.dbmail.models import MessageRequest
        from esp.users.models import PersistentQueryFilter

        filterid, fromemail, replytoemail, subject, body = [
                                    request.POST['filterid'],
                                    request.POST['from'],
                                    request.POST['replyto'],
                                    request.POST['subject'],
                                    request.POST['body']    ]
        sendto_fn_name = request.POST.get('sendto_fn_name', MessageRequest.SEND_TO_SELF_REAL)

        try:
            filterid = int(filterid)
        except:
            raise ESPError("Corrupted POST data!  Please contact us at [email protected] and tell us how you got this error, and we'll look into it.")

        filterobj = PersistentQueryFilter.getFilterFromID(filterid, ESPUser)

        sendto_fn = MessageRequest.assert_is_valid_sendto_fn_or_ESPError(sendto_fn_name)

        variable_modules = {'user': request.user, 'program': self.program}

        newmsg_request = MessageRequest.createRequest(var_dict   = variable_modules,
                                                      subject    = subject,
                                                      recipients = filterobj,
                                                      sendto_fn_name  = sendto_fn_name,
                                                      sender     = fromemail,
                                                      creator    = request.user,
                                                      msgtext    = body,
                                                      special_headers_dict
                                                                 = { 'Reply-To': replytoemail, }, )

        newmsg_request.save()

        # now we're going to process everything
        # nah, we'll do this later.
        #newmsg_request.process()

        numusers = self.approx_num_of_recipients(filterobj, sendto_fn)

        from django.conf import settings
        if hasattr(settings, 'EMAILTIMEOUT') and \
               settings.EMAILTIMEOUT is not None:
            est_time = settings.EMAILTIMEOUT * numusers
        else:
            est_time = 1.5 * numusers

        return render_to_response(self.baseDir()+'finished.html', request,
                                  {'time': est_time})
示例#4
0
def event_to_message(event):
    m = MessageRequest()
    m.subject = "Event Notification"
    m.category = GetNode('Q/Event')
    m.sender = '*****@*****.**'
    m.msgtext = 'Event Reminder: ' + event.short_description + '\n\n' + event.description
    m.save()
    return m
示例#5
0
    def commfinal(self, request, tl, one, two, module, extra, prog):
        from esp.dbmail.models import MessageRequest
        from esp.users.models import PersistentQueryFilter

        announcements = self.program_anchor_cached().tree_create(
            ['Announcements'])
        filterid, fromemail, replytoemail, subject, body = [
            request.POST['filterid'], request.POST['from'],
            request.POST['replyto'], request.POST['subject'],
            request.POST['body']
        ]

        try:
            filterid = int(filterid)
        except:
            raise ESPError(
            ), "Corrupted POST data!  Please contact us at [email protected] and tell us how you got this error, and we'll look into it."

        filterobj = PersistentQueryFilter.getFilterFromID(filterid, ESPUser)

        variable_modules = {'user': request.user, 'program': self.program}

        newmsg_request = MessageRequest.createRequest(
            var_dict=variable_modules,
            subject=subject,
            recipients=filterobj,
            sender=fromemail,
            creator=request.user,
            msgtext=body,
            special_headers_dict={
                'Reply-To': replytoemail,
            },
        )

        newmsg_request.save()

        # now we're going to process everything
        # nah, we'll do this later.
        #newmsg_request.process()

        numusers = filterobj.getList(ESPUser).distinct().count()

        from django.conf import settings
        if hasattr(settings, 'EMAILTIMEOUT') and \
               settings.EMAILTIMEOUT is not None:
            est_time = settings.EMAILTIMEOUT * numusers
        else:
            est_time = 1.5 * numusers

        #        assert False, self.baseDir()+'finished.html'
        return render_to_response(self.baseDir() + 'finished.html', request,
                                  (prog, tl), {'time': est_time})
示例#6
0
    def commpanel_old(self, request, tl, one, two, module, extra, prog):
        from esp.users.views     import get_user_list
        filterObj, found = get_user_list(request, self.program.getLists(True))

        if not found:
            return filterObj

        sendto_fn_name = request.POST.get('sendto_fn_name', MessageRequest.SEND_TO_SELF_REAL)
        sendto_fn = MessageRequest.assert_is_valid_sendto_fn_or_ESPError(sendto_fn_name)

        listcount = self.approx_num_of_recipients(filterObj, sendto_fn)

        return render_to_response(self.baseDir()+'step2.html', request,
                                              {'listcount': listcount,
                                               'filterid': filterObj.id,
                                               'sendto_fn_name': sendto_fn_name })
示例#7
0
    def verify_email(self):
        import string
        import random
        from esp.users.models import PersistentQueryFilter
        from esp.dbmail.models import MessageRequest
        from django.template import loader

        symbols = string.ascii_uppercase + string.digits
        code = "".join([random.choice(symbols) for x in range(30)])

        regProf = RegistrationProfile.getLastForProgram(
            get_current_request().user, self.program)

        if regProf.email_verified:
            return self.goToCore(tl)

        if request.method == 'POST' and request.POST.has_key('verify_me'):
            # create the variable modules
            variable_modules = {
                'program': self.program,
                'user': get_current_request().user
            }

            # get the filter object
            filterobj = PersistentQueryFilter.getFilterFromQ(
                Q(id=get_current_request().user.id), User,
                'User %s' % get_current_request().user.username)

            newmsg_request = MessageRequest.createRequest(
                var_dict=variable_modules,
                subject='[ESP] Email Verification For esp.mit.edu',
                recipients=filterobj,
                sender='"MIT Educational Studies Program" <*****@*****.**>',
                creator=self,
                msgtext=loader.find_template_source('email/verify')[0])

            newmsg_request.save()

            return render_to_response(self.baseDir() + 'emailsent.html',
                                      request, {})

        return render_to_response(self.baseDir() + 'sendemail.html', request,
                                  {})