コード例 #1
0
ファイル: tasks.py プロジェクト: poszu/gedgo
def async_update(gedcom_id, file_name, recipient_ids, message, domain,
                 sender_id):
    start = datetime.now()
    gedcom = Gedcom.objects.get(id=gedcom_id)

    errstr = ''
    try:
        update(gedcom, file_name, verbose=False)
    except Exception:
        errstr = traceback.format_exc()

    end = datetime.now()

    send_mail(
        'Update finished!', 'Started:  %s\nFinished: %s\n\n%s' %
        (start.strftime('%B %d, %Y at %I:%M %p'),
         end.strftime('%B %d, %Y at %I:%M %p'), errstr), '*****@*****.**',
        [email for _, email in settings.ADMINS])

    # Send mass email to users on successful update only.
    recipients = [User.objects.get(id=id_).email for id_ in recipient_ids]
    recipients = [u for u in recipients if u]

    if (not errstr) and recipients and message:
        scheme = 'https' if settings.CSRF_COOKIE_SECURE else 'http'
        url = '%s://%s/gedgo/%s/' % (scheme, domain, gedcom.id)
        sender = User.objects.get(id=sender_id).email
        subject = 'Update to %s' % gedcom.title
        body = '%s\n\n%s' % (message, url)
        datatuple = ((subject, body, sender, [r]) for r in recipients)

        send_mass_mail(datatuple)
コード例 #2
0
ファイル: add_gedcom.py プロジェクト: poszu/gedgo
    def handle(self, *args, **options):

        if not len(args) == 1:
            raise CommandError('add_gedcom takes only one argument - '
                               'the path to a gedcom file.')

        file_name = args[0]
        if not path.exists(file_name):
            raise CommandError('Gedcom file "%s" not found.' % file_name)
        if (not len(file_name) > 4) or (not file_name[-4:] == '.ged'):
            raise CommandError('File "%s" does not appear to be a .ged file.' %
                               file_name)

        update(None, file_name)
コード例 #3
0
ファイル: add_gedcom.py プロジェクト: gthole/gedgo
    def handle(self, *args, **options):

        if not len(args) == 1:
            raise CommandError('add_gedcom takes only one argument - '
                               'the path to a gedcom file.')

        file_name = args[0]
        if not path.exists(file_name):
            raise CommandError('Gedcom file "%s" not found.' % file_name)
        if (not len(file_name) > 4) or (not file_name[-4:] == '.ged'):
            raise CommandError(
                'File "%s" does not appear to be a .ged file.' % file_name)

        update(None, file_name)
コード例 #4
0
ファイル: update_gedcom.py プロジェクト: gthole/gedgo
    def handle(self, *args, **options):
        # arg init
        gid = args[0]
        try:
            g = Gedcom.objects.get(pk=gid)
        except Exception:
            raise CommandError('Gedcom "%s" does not exist.' % gid)

        file_name = args[1]
        if not path.exists(file_name):
            raise CommandError('Gedcom file "%s" not found.' % file_name)
        if (not len(file_name) > 4) or (not file_name[-4:] == '.ged'):
            raise CommandError(
                'File "%s" does not appear to be a .ged file.' % file_name)

        # Check file time against gedcom last_update time.
        file_time = datetime.fromtimestamp(path.getmtime(file_name))
        last_update_time = g.last_updated.replace(tzinfo=None)
        if (options['force'] or True or (file_time > last_update_time)):
            start = datetime.now()

            errstr = ''
            try:
                update(g, file_name)
            except Exception:
                e = exc_info()[0]
                errstr = 'There was an error: %s\n%s' % (
                    e, traceback.format_exc())
                print errstr

            end = datetime.now()

            send_mail(
                'Gedcom file updated (%s)' % (
                    g.title if g.title else 'id = %' % str(g.id)),
                'Started:  %s\nFinished: %s\n\n%s' % (
                    start.strftime('%B %d, %Y at %I:%M %p'),
                    end.strftime('%B %d, %Y at %I:%M %p'),
                    errstr
                ),
                '*****@*****.**',
                [email for _, email in settings.ADMINS]
            )
コード例 #5
0
ファイル: update_gedcom.py プロジェクト: poszu/gedgo
    def handle(self, *args, **options):
        # arg init
        gid = args[0]
        try:
            g = Gedcom.objects.get(pk=gid)
        except Exception:
            raise CommandError('Gedcom "%s" does not exist.' % gid)

        file_name = args[1]
        if not path.exists(file_name):
            raise CommandError('Gedcom file "%s" not found.' % file_name)
        if (not len(file_name) > 4) or (not file_name[-4:] == '.ged'):
            raise CommandError('File "%s" does not appear to be a .ged file.' %
                               file_name)

        # Check file time against gedcom last_update time.
        file_time = datetime.fromtimestamp(path.getmtime(file_name))
        last_update_time = g.last_updated.replace(tzinfo=None)
        if (options['force'] or True or (file_time > last_update_time)):
            start = datetime.now()

            errstr = ''
            try:
                update(g, file_name)
            except Exception:
                e = exc_info()[0]
                errstr = 'There was an error: %s\n%s' % (
                    e, traceback.format_exc())
                print errstr

            end = datetime.now()

            send_mail(
                'Gedcom file updated (%s)' %
                (g.title if g.title else 'id = %' % str(g.id)),
                'Started:  %s\nFinished: %s\n\n%s' %
                (start.strftime('%B %d, %Y at %I:%M %p'),
                 end.strftime('%B %d, %Y at %I:%M %p'), errstr),
                '*****@*****.**', [email for _, email in settings.ADMINS])
コード例 #6
0
def async_update(gedcom_id, file_name, recipient_ids,
                 message, domain, sender_id):
    start = datetime.now()
    gedcom = Gedcom.objects.get(id=gedcom_id)

    errstr = ''
    try:
        update(gedcom, file_name, verbose=False)
    except:
        errstr = traceback.format_exc()

    end = datetime.now()

    send_mail(
        'Update finished!',
        'Started:  %s\nFinished: %s\n\n%s' % (
            start.strftime('%B %d, %Y at %I:%M %p'),
            end.strftime('%B %d, %Y at %I:%M %p'),
            errstr
        ),
        '*****@*****.**',
        [email for _, email in settings.ADMINS]
    )

    # Send mass email to users on successful update only.
    recipients = [User.objects.get(id=id_).email for id_ in recipient_ids]
    recipients = [u for u in recipients if u]

    if (not errstr) and recipients and message:
        scheme = 'https' if settings.CSRF_COOKIE_SECURE else 'http'
        url = '%s://%s/gedgo/%s/' % (scheme, domain, gedcom.id)
        sender = User.objects.get(id=sender_id).email
        subject = 'Update to %s' % gedcom.title
        body = '%s\n\n%s' % (message, url)
        datatuple = ((subject, body, sender, [r]) for r in recipients)

        send_mass_mail(datatuple)
コード例 #7
0
ファイル: tests.py プロジェクト: poszu/gedgo
 def setUp(self):
     self.file_ = 'gedgo/static/test/test.ged'
     update(None, self.file_, verbose=False)
     self.gedcom = Gedcom.objects.get()
コード例 #8
0
ファイル: tests.py プロジェクト: poszu/gedgo
 def test_update_from_gedcom(self):
     g = Gedcom.objects.get()
     update(g, self.file_, verbose=False)
     self.assertEqual(Person.objects.count(), 6)
     self.assertEqual(Family.objects.count(), 2)
コード例 #9
0
ファイル: tests.py プロジェクト: poszu/gedgo
 def setUp(self):
     self.file_ = 'gedgo/static/test/test.ged'
     update(None, self.file_, verbose=False)