コード例 #1
0
    def handle(self, *args, **options):
        length = settings.SUNSET_CONFIG['time']
        units = settings.SUNSET_CONFIG['units']
        days_old = length
        if units == 'months':
            days_old = days_old * 30
        if units == 'years':
            days_old = days_old * 365

        days_to_wait = settings.SUNSET_CONFIG['days_to_wait_before_action']
        therequests = Request.get_all_sunsetting(days_old - days_to_wait)

        for request in therequests:
            print "SUNSET NOTIFICATION requst %s" % request.id
            user = request.author
            address = user.email
            try:
                address = settings.TASK_EMAIL_RECIPIENT
            except:
                pass

            notifcation = Notification(
                type=Notification.get_type_id('Sunset clause notification'),
                sent=datetime.now(),
                request=request)
            notifcation.save()

            data = {
                "from":
                "*****@*****.**",
                "to":
                address,
                'subject':
                'An important message regarding your request to ' +
                request.agency.name,
                'html':
                """
                    According to our records, you sent a request to %s about %s %s ago. <br />
                    It's FOIA Machine's policy to make private requests public after %s %s if you take no further action.<br/>
                    If you do nothing your request will be made public in %s days. <br/>
                    If you'd like to keep your request private, follow this link:
                    <a href="https://www.foiamachine.org/requests/privacy/%s">https://www.foiamachine.org/requests/privacy/%s</a>
                    """ % (request.agency.name, length, units, length, units,
                           days_to_wait, request.id, request.id)
            }

            if settings.MG_ROUTE:
                post_url = 'https://api.mailgun.net/v2/%s.%s/messages' % (
                    settings.MG_ROUTE, settings.MG_DOMAIN)
            else:
                post_url = 'https://api.mailgun.net/v2/%s/messages' % settings.MG_DOMAIN
            post_url = settings.MG_POST_URL

            if settings.SEND_NOTIFICATIONS:
                resp = requests.post(post_url,
                                     auth=("api", settings.MAILGUN_KEY),
                                     data=data)
                content = json.loads(resp.content)
                logging.info('SENT NOTIFICATION STATUS:%s' % content)
コード例 #2
0
    def handle(self, *args, **options):
        nargs = len(args)
        if nargs == 0:
            ndays = -1
        elif nargs > 1:
            raise CommandError("Usage: notify_overdue_requests [ndays]")
        elif nargs == 1:
            try:
                ndays = int(args[0])
            except ValueError:
                raise CommandError("%s not an integer number of days" % args[0])

        therequests = Request.get_all_overdue()

        for request in therequests:
            print 'Doing request %s response due %s' % (request.id, request.get_due_date)

            user = request.author
            address = user.email
            try:
                address = settings.TASK_EMAIL_RECIPIENT
            except:
                pass
            notifcation = Notification(type=Notification.get_type_id("Late request"), request=request)
            notifcation.save()

            data = {
                "from" : "*****@*****.**",
                "to" : address,
                'subject' : 'Response due from ' + request.agency.name,
                'html' : """
                    According to our records, you're overdue to receive a response from %s. <br />
                    If that's not the case, you can log in and update the status of your request
                    at <a href="https://www.foiamachine.org/requests/%s">https://www.foiamachine.org/requests/%s</a>
                    """ % (request.agency.name, request.pk, request.pk)
            }

            if settings.MG_ROUTE:
                post_url = 'https://api.mailgun.net/v2/%s.%s/messages' % (settings.MG_ROUTE, settings.MG_DOMAIN)
            else:
                post_url = 'https://api.mailgun.net/v2/%s/messages' % settings.MG_DOMAIN
            
            post_url = settings.MG_POST_URL

            if settings.SEND_NOTIFICATIONS:
                resp = requests.post(
                        post_url,
                        auth=("api", settings.MAILGUN_KEY),
                        data=data)
                content = json.loads(resp.content)
                logging.info('SENT NOTIFICATION STATUS:%s' % content)
コード例 #3
0
    def handle(self, *args, **options):
        nargs = len(args)
        if nargs == 0:
            ndays = -1
        elif nargs > 1:
            raise CommandError("Usage: notify_overdue_requests [ndays]")
        elif nargs == 1:
            try:
                ndays = int(args[0])
            except ValueError:
                raise CommandError("%s not an integer number of days" % args[0])

        therequests = Request.get_all_overdue()

        for request in therequests:
            print 'Doing request %s response due %s' % (request.id, request.get_due_date)

            user = request.author
            address = user.email
            try:
                address = settings.TASK_EMAIL_RECIPIENT
            except:
                pass
            notifcation = Notification(type=Notification.get_type_id("Late request"), request=request)
            notifcation.save()

            data = {
                "from" : "*****@*****.**",
                "to" : address,
                'subject' : 'Response due from ' + request.agency.name,
                'html' : """
                    According to our records, you're overdue to receive a response from %s. <br />
                    If that's not the case, you can log in and update the status of your request
                    at <a href="https://www.foiamachine.org/requests/%s">https://www.foiamachine.org/requests/%s</a>
                    """ % (request.agency.name, request.pk, request.pk)
            }

            if settings.MG_ROUTE:
                post_url = 'https://api.mailgun.net/v2/%s.foiamachine.mailgun.org/messages' % settings.MG_ROUTE
            else:
                post_url = 'https://api.mailgun.net/v2/foiamachine.mailgun.org/messages'

            if settings.SEND_NOTIFICATIONS:
                resp = requests.post(
                        post_url,
                        auth=("api", settings.MAILGUN_KEY),
                        data=data)
                content = json.loads(resp.content)
                logging.info('SENT NOTIFICATION STATUS:%s' % content)
コード例 #4
0
    def handle(self, *args, **options):
        length = settings.SUNSET_CONFIG['time']
        units = settings.SUNSET_CONFIG['units']
        days_old = length
        if units == 'months':
            days_old = days_old * 30
        if units == 'years':
            days_old = days_old * 365

        days_to_wait = settings.SUNSET_CONFIG['days_to_wait_before_action']
        therequests = Request.get_all_sunsetting(days_old - days_to_wait)

        for request in therequests:
            print "SUNSET NOTIFICATION requst %s" % request.id
            user = request.author
            address = user.email
            try:
                address = settings.TASK_EMAIL_RECIPIENT
            except:
                pass

            notifcation = Notification(type=Notification.get_type_id('Sunset clause notification'), sent=datetime.now(), request=request)
            notifcation.save()

            data = {
                "from" : "*****@*****.**",
                "to" : address,
                'subject' : 'An important message regarding your request to ' + request.agency.name,
                'html' : """
                    According to our records, you sent a request to %s about %s %s ago. <br />
                    It's FOIA Machine's policy to make private requests public after %s %s if you take no further action.<br/>
                    If you do nothing your request will be made public in %s days. <br/>
                    If you'd like to keep your request private, follow this link:
                    <a href="https://www.foiamachine.org/requests/privacy/%s">https://www.foiamachine.org/requests/privacy/%s</a>
                    """ % (request.agency.name, length, units, length, units, days_to_wait, request.id, request.id)
            }

            post_url = settings.MG_POST_URL

            if settings.SEND_NOTIFICATIONS:
                resp = requests.post(
                        post_url,
                        auth=("api", settings.MAILGUN_KEY),
                        data=data)
                content = json.loads(resp.content)
                logging.info('SENT NOTIFICATION STATUS:%s' % content)