Пример #1
0
def _send_now(send_log):
    platform = send_log.subscription_platform.platform
    subscription = send_log.subscription_platform.subscription
    telegram = send_log.telegram
    handler = import_class(platform.handler)
    handler = handler(telegram, subscription, platform, **telegram.additional_arguments)
    handler.handle()
    send_log.sent = True
    send_log.sent_at = datetime.now()
    send_log.save()
 def handle(self, *args, **options):
     if len(args) > 3 or len(args) < 2:
         raise CommandError('Usage: python manage.py createplatform platform_name path.to.Handler ["this is my platform description"]')
     platform_name = args[0]
     platform_handler = args[1]
     try:
         import_class(platform_handler)
     except:
         raise CommandError('Not a valid platform handler or it does not exist')
     try:
         description = args[2]
     except IndexError:
         description = None
     try:
         platform = Platform.objects.get(name=platform_name)
         raise CommandError('Platform %s already exists' % platform_name)
     except Platform.DoesNotExist:
         platform = Platform(name=platform_name, handler=platform_handler, description=description)
         platform.save()
     self.stdout.write('platform %s was successfully created\n' % platform.name)
Пример #3
0
def _build_telegrams(channel, subject, message, level, add_to_queue, **kwargs):
    telegram = Telegram(
            subject=subject,
            content=message,
            level=level,
            channel=channel,
            additional_arguments=kwargs)
    telegram.save()
    if channel.handler:
        handler = import_class(channel.handler)(telegram, channel, level)
        subscriptions = handler.handle()
    else:
        subscriptions = Subscription.objects.filter(
                channel=channel, level__gte=level, disabled=False)
    for subscription in subscriptions:
        for sub_plat in subscription.subscriptionplatform_set.all():
            send_log = SendLog(
                    telegram=telegram,
                    subscription_platform=sub_plat
            )
            send_log.save()
            if not FORCE_QUEUEING:
                if not add_to_queue:
                    _send_now(send_log)