aboutsummaryrefslogtreecommitdiffstats
path: root/src/notifier/views.py
blob: 3a85edab3e2792dc1c4badb75aa1f2efa707aa95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
##############################################################################
# Copyright (c) 2018 Sawyer Bergeron and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

from django.shortcuts import render
from notifier.models import Notification
from django.db.models import Q


def InboxView(request):
    if request.user.is_authenticated:
        user = request.user
    else:
        return render(request, "dashboard/login.html",
                      {'title': 'Authentication Required'})

    return render(request,
                  "notifier/inbox.html",
                  {'unread_notifications': Notification.objects.filter(recipients=user.userprofile).order_by('-id').filter(~Q(read_by=user.userprofile)),
                      'read_notifications': Notification.objects.filter(recipients=user.userprofile).order_by('-id').filter(read_by=user.userprofile)})


def NotificationView(request, notification_id):

    if request.user.is_authenticated:
        user = request.user
    else:
        return render(request,
                      "dashboard/login.html",
                      {'title': 'Authentication Required'})

    notification = Notification.objects.get(id=notification_id)
    if user.userprofile not in notification.recipients.all():
        return render(request,
                      "dashboard/login.html", {'title': 'Access Denied'})

    notification.read_by.add(user.userprofile)
    notification.save()
    if request.method == 'POST':
        if 'delete' in request.POST:
            # handle deleting
            notification.recipients.remove(user.userprofile)
            if not notification.recipients.exists():
                notification.delete()
            else:
                notification.save()

        if 'unread' in request.POST:
            notification.read_by.remove(user.userprofile)
            notification.save()

    return render(request,
                  "notifier/notification.html", {'notification': notification})
span>(oc); AccelState *accel = ACCEL(object_new(cname)); int ret; ms->accelerator = accel; *(acc->allowed) = true; ret = acc->init_machine(ms); if (ret < 0) { ms->accelerator = NULL; *(acc->allowed) = false; object_unref(OBJECT(accel)); } return ret; } int configure_accelerator(MachineState *ms) { const char *p; char buf[10]; int ret; bool accel_initialised = false; bool init_failed = false; AccelClass *acc = NULL; p = qemu_opt_get(qemu_get_machine_opts(), "accel"); if (p == NULL) { /* Use the default "accelerator", tcg */ p = "tcg"; } while (!accel_initialised && *p != '\0') { if (*p == ':') { p++; } p = get_opt_name(buf, sizeof(buf), p, ':'); acc = accel_find(buf); if (!acc) { fprintf(stderr, "\"%s\" accelerator not found.\n", buf); continue; } if (acc->available && !acc->available()) { printf("%s not supported for this target\n", acc->name); continue; } ret = accel_init_machine(acc, ms); if (ret < 0) { init_failed = true; fprintf(stderr, "failed to initialize %s: %s\n", acc->name, strerror(-ret)); } else { accel_initialised = true; } } if (!accel_initialised) { if (!init_failed) { fprintf(stderr, "No accelerator found!\n"); } exit(1); } if (init_failed) { fprintf(stderr, "Back to %s accelerator.\n", acc->name); } return !accel_initialised; } static void tcg_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); ac->name = "tcg"; ac->init_machine = tcg_init; ac->allowed = &tcg_allowed; } #define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") static const TypeInfo tcg_accel_type = { .name = TYPE_TCG_ACCEL, .parent = TYPE_ACCEL, .class_init = tcg_accel_class_init, }; static void register_accel_types(void) { type_register_static(&accel_type); type_register_static(&tcg_accel_type); } type_init(register_accel_types);