Exemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        if 'apply' in request.POST:
            push_form = AdminPushForm(request.POST)
            if push_form.is_valid():
                header = push_form.cleaned_data['header']
                text = push_form.cleaned_data['text']

                payload = {
                    'head': header,
                    'body': text,
                    'icon': static('main/img/logo-square.png'),
                    'url': reverse('main:schedules')
                }
                send_group_notification(group_name='all',
                                        payload=payload,
                                        ttl=1000)

                messages.add_message(request,
                                     messages.INFO,
                                     'Уведомление отправлено',
                                     extra_tags='',
                                     fail_silently=False)
                return HttpResponseRedirect(
                    reverse('admin:main_schedulegroup_changelist'))

        push_form = AdminPushForm(initial={'path': request.get_full_path()})
        return render(request, 'admin/push.html', context={'form': push_form})
Exemplo n.º 2
0
    def push(self, request, queryset):
        if 'apply' in request.POST:
            push_form = AdminPushForm(request.POST)
            if push_form.is_valid():
                header = push_form.cleaned_data['header']
                text = push_form.cleaned_data['text']

                payload = {
                    'head': header,
                    'body': text,
                    'icon': static('main/img/logo-square.png'),
                    'url': reverse('main:schedules')
                }
                send_group_notification(group_name='all',
                                        payload=payload,
                                        ttl=1000)

                self.message_user(request, 'Уведомление отправлено')
                return HttpResponseRedirect(
                    reverse('admin:main_schedulegroup_changelist'))

        push_form = AdminPushForm(initial={'path': request.get_full_path()})
        return render(request,
                      'admin/push.html',
                      context={
                          'form': push_form,
                          'groups': queryset
                      })
Exemplo n.º 3
0
    def send_all(self, request, message_id, *args, **kwargs):
        message = self.get_object(request, message_id)
        message.sent = True
        message.save()

        for push_information in PushInformation.objects.filter(
                group=message.group):
            notification = Notification(user=push_information.user,
                                        message=message)
            notification.save()

        url = message.action_url if message.action_url else reverse('alerts')
        url += '?from_push={}'.format(message.id)

        payload = {
            "head": message.title,
            "body": message.description,
            "url": url
        }
        send_group_notification(group_name=str(message.group),
                                payload=payload,
                                ttl=1000)

        messages.success(request, 'Message %s sent to all users' % message_id)
        return redirect('admin:evacuation_message_changelist')
Exemplo n.º 4
0
def income_create(request):
    if request.method == 'POST':
        form = IncomeForm(request.POST, request.FILES)

        if form.is_valid():
            item = form.save(commit=False)
            item.user = request.user
            item.save()
            messages.success(request, _('Income was successfully Created!'))
            return redirect('income:income_list')
        else:
            messages.error(request, _('Please correct the error below.'))
    else:
        form = IncomeForm()

    context = {'form': form}

    payload = {
        'head': 'Welcome!',
        'body': 'Hello World',
        'icon': 'https://i.imgur.com/dRDxiCQ.png',
        'url': 'https://www.example.com'
    }

    send_group_notification(user='******', payload=payload, ttl=1000)

    return render(request, 'income/income_form.html', context)
Exemplo n.º 5
0
def send_broadcast_push_notification(title: str, body: str, url=None, **other_info):
    payload = {"title": title, "body": body}
    if url:
        payload["url"] = url
    if other_info:
        payload.update(other_info)
    send_group_notification(group_name="group_name", payload=payload, ttl=3600)
Exemplo n.º 6
0
 def handle(self, *args, **options):
     payload = {
         'head': 'Тест сообщения',
         'body': 'Тест сообщения, текст',
         # 'icon': 'https://i.imgur.com/dRDxiCQ.png',
         # 'url': 'https://www.example.com'
     }
     send_group_notification(group_name='grp001', payload=payload, ttl=1000)
Exemplo n.º 7
0
def test(sender, instance, created, **kwargs):
    if not created or not instance.receive_emails:
        return False

    message_text = " ".join(
        map(
            str,
            [
                _("Nova oportunidade!"),
                instance.title,
                " - ",
                instance.company_name,
                _("em"),
                instance.workplace,
                "\n",
                f"{settings.WEBSITE_HOME_URL}/job/{instance.pk}/",
            ],
        ))
    post_telegram_channel(message_text)

    msg = get_email_with_template(
        "published_job",
        {"vaga": instance},
        " ".join(
            map(str, [
                _("Sua oportunidade está disponível no"), settings.WEBSITE_NAME
            ])),
        [instance.company_email],
    )

    payload = {
        "head": " ".join(map(str, [_("Nova Vaga!"), instance.title])),
        "body": instance.description,
        "url": f"{settings.WEBSITE_HOME_URL}/job/{instance.pk}/",
    }

    msg.send()
    if not instance.issue_number:
        try:
            send_job_to_github_issues(instance)
        except:
            pass

    try:
        send_group_notification(group_name="general",
                                payload=payload,
                                ttl=1000)
    except:
        pass

    try:
        send_offer_email_template(instance)
    except:
        client.captureException()

    return True
Exemplo n.º 8
0
def send_push_message(sender, instance, **kwargs):
    if not instance.id:
        return

    payload = {
        "head": instance.head,
        "body": instance.body,
        "url": instance.url,
    }
    send_group_notification(group_name="general", payload=payload, ttl=1000)
Exemplo n.º 9
0
def send_pn(head, body):
    payload = {
        "head": head,
        "body": body,
        "icon": "/static/images/notification.png",
        "url": "http://127.0.0.1:8000/home"
    }
    try:
        send_group_notification(group_name="all", payload=payload, ttl=1000)
    except Exception as e:
        print(e)
Exemplo n.º 10
0
def send_webpush_notification(game_id):
    game = Game.objects.get(id=game_id)
    try:
        send_group_notification(
            group_name=settings.WEBPUSH_GROUP,
            payload={
                "head": "New Academy game started",
                "body":
                f"A game between {game.pretty_players_str()} just started!",
                "icon": get_absolute_url(static("favicon.ico")),
                "url": game.get_absolute_url(),
            },
            ttl=24 * 60 * 60,
        )
    except:
        pass
Exemplo n.º 11
0
def new_job_was_created(sender, instance, created, **kwargs):
    if not created or not instance.receive_emails:
        return

    # post to telegram
    message_base = "Nova oportunidade! {} - {} em {}\n {}/job/{}/"
    message_text = message_base.format(
        instance.title,
        instance.company_name,
        instance.workplace,
        settings.WEBSITE_HOME_URL,
        instance.pk,
    )
    post_telegram_channel(message_text)

    msg = get_email_with_template(
        "published_job",
        {"vaga": instance},
        "Sua oportunidade está disponível no {}".format(settings.WEBSITE_NAME),
        [instance.company_email],
    )

    payload = {
        "head": f"Nova Vaga! {instance.title}",
        "body": instance.description,
        "url": f"{settings.WEBSITE_HOME_URL}/job/{instance.pk}/",
    }

    msg.send()
    if not instance.issue_number:
        try:
            send_job_to_github_issues(instance)
        except:
            pass

    try:
        send_group_notification(group_name="general",
                                payload=payload,
                                ttl=1000)
    except:
        pass

    try:
        send_offer_email_template(instance)
    except:
        client.captureException()
Exemplo n.º 12
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context["queue_position"] = context["student_ticket"].position_in_queue
     webpush = {"group": context["student_ticket"].user.principal_name}
     context["webpush"] = webpush
     if context["queue_position"] == 0:
         try:
             payload = {
                 "head":
                 "Twoja kolej!",
                 "body":
                 "Za moment pan Walczyński zadzwoni na Teamsach.",
                 "icon":
                 "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/black-telephone_260e.png",
             }
             send_group_notification(
                 group_name=context["student_ticket"].user.principal_name,
                 payload=payload,
                 ttl=1000,
             )
         except:
             pass
         if QueueTicket.objects.count() == 1:
             try:
                 payload = {
                     "head":
                     "Nowy oczekujÄ…cy",
                     "body":
                     "{} prosi o połączenie.".format(
                         context["student_ticket"].user.display_name),
                     "icon":
                     "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/black-telephone_260e.png",
                 }
                 send_group_notification(
                     group_name="*****@*****.**",
                     payload=payload,
                     ttl=1000,
                 )
             except:
                 pass
     context["estimated_time"] = (
         context["student_ticket"].position_in_queue *
         average_meeting_time())
     return context
Exemplo n.º 13
0
def push_notification(request):
    if 'notification' in request.GET:
        payload = {
            "head": request.user.username,
            "body": request.GET['notification']
        }
    else:
        payload = {"head": request.user.username, "body": "有東西出錯了"}

    notification_count = NotificationCount.objects.get(user=request.user)
    if int(notification_count.count) > 0:
        notification_count.count = int(notification_count.count) - 1
        notification_count.save()

        send_group_notification(group_name='all', payload=payload, ttl=1000)
        return redirect(reverse('chatdemo:home_page'))
    else:
        payload = {"head": "Error", "body": "尬廣次數不足"}
        send_user_notification(user=request.user, payload=payload, ttl=1000)
        return redirect(reverse('chatdemo:home_page'))
Exemplo n.º 14
0
def send_push(request):
    try:
        body = request.body
        data = json.loads(body)

        if 'head' not in data or 'body' not in data or 'id' not in data:
            return JsonResponse(status=400,
                                data={"message": "Invalid data format"})

        user_id = data['id']
        user = get_object_or_404(User, pk=user_id)
        payload = {
            "head": data['head'],
            "body": data['body'],
            "icon": data['icon'],
            "url": data['url']
        }
        send_group_notification(group_name='g1', payload=payload, ttl=1000)
        return JsonResponse(status=200,
                            data={"message": "Web push successful"})
    except TypeError:
        return JsonResponse(status=500, data={"message": "An error occurred"})
Exemplo n.º 15
0
def send_notification_to_group(group, message):
    payload = {"head": "WEB PUSH", "body": message}
    send_group_notification(group_name=group, payload=payload, ttl=1000)
Exemplo n.º 16
0
from webpush.models import Group, PushInformation, SubscriptionInfo
from webpush import send_user_notification
from webpush import send_group_notification
from django.contrib.auth import get_user_model

User = get_user_model()
admin = User.objects.first()
g = Group.objects.create(name="gg")

payload = {
    "head": "Welcome!",
    "body": "Hello World",
    "icon": "https://i.imgur.com/dRDxiCQ.png",
    "url": "https://www.example.com",
}

send_group_notification(group_name="gg", payload=payload, ttl=1000)
Exemplo n.º 17
0
def sendsixalert(request):
    payload = {"head": "SIX Notifier", "body": "Its a 6. Order within next 6 mins"}
    send_group_notification(group_name="sixers", payload=payload, ttl=1000)
    return HttpResponse("")