# Path: QueueDB/models.py
# class Profile(models.Model):
#     from uuid import uuid4
#     user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="%(app_label)s_%(class)s_related")
#     delegate = models.ForeignKey(User, on_delete=models.CASCADE, related_name="%(app_label)s_delegate_related")
#     api_key = models.CharField(default=uuid4, max_length=64, unique=True)
#     api_secret = models.CharField(default=uuid4, max_length=64)
#     upload_folder = models.CharField(default="", blank=True, max_length=1024)
#     archive_folder = models.CharField(default="", blank=True, max_length=1024)
#     notification_enabled = models.SmallIntegerField(choices=((0, "No"), (1, "Yes")), default=0)
# 
#     def __str__(self):
#         return self.user.username
# 
#     def check_owner(self, user, read_only=True):
#         """
#         Check whether the requesting user has the permission to read/change the record
# 
#         :param user: int or User
#             either or int (id of the user) or a User object
#         :param read_only: bool
#             If the ongoing operation only requires for read permission
#         :return:
#         has_perm : bool
#             True for having permission to access the record
#         """
#         if not isinstance(user, User):
#             if type(user) is int:
#                 user = User.objects.get(id=user)
#             else:
#                 raise AssertionError("user should be a User object or an integer")
#         if self.user is None:
#             if read_only:  # public
#                 return True
#             else:
#                 if user.is_staff:
#                     return True
#                 else:
#                     return False
#         elif int(self.user.id) == user.id:  # owner
#             return True
#         elif user.is_staff:  # administrators
#             return True
#         else:
#             return False


from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.apps import apps
from QueueDB.models import Profile
import json
import hashlib
#!/usr/bin/env python
# coding=utf-8
# Created by: Li Yao
# Created on: 8/2/20


class Api(object):
    @staticmethod
    def ret_info(valid, results):
        json_data = dict()
        json_data['valid'] = valid
        json_data['results'] = results
        return JsonResponse(json_data)

    def _valid(self):
        """
        Validate API request

        :return: bool
        """
        try:

# Path: QueueDB/models.py
# class Profile(models.Model):
#     from uuid import uuid4
#     user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="%(app_label)s_%(class)s_related")
#     delegate = models.ForeignKey(User, on_delete=models.CASCADE, related_name="%(app_label)s_delegate_related")
#     api_key = models.CharField(default=uuid4, max_length=64, unique=True)
#     api_secret = models.CharField(default=uuid4, max_length=64)
#     upload_folder = models.CharField(default="", blank=True, max_length=1024)
#     archive_folder = models.CharField(default="", blank=True, max_length=1024)
#     notification_enabled = models.SmallIntegerField(choices=((0, "No"), (1, "Yes")), default=0)
# 
#     def __str__(self):
#         return self.user.username
# 
#     def check_owner(self, user, read_only=True):
#         """
#         Check whether the requesting user has the permission to read/change the record
# 
#         :param user: int or User
#             either or int (id of the user) or a User object
#         :param read_only: bool
#             If the ongoing operation only requires for read permission
#         :return:
#         has_perm : bool
#             True for having permission to access the record
#         """
#         if not isinstance(user, User):
#             if type(user) is int:
#                 user = User.objects.get(id=user)
#             else:
#                 raise AssertionError("user should be a User object or an integer")
#         if self.user is None:
#             if read_only:  # public
#                 return True
#             else:
#                 if user.is_staff:
#                     return True
#                 else:
#                     return False
#         elif int(self.user.id) == user.id:  # owner
#             return True
#         elif user.is_staff:  # administrators
#             return True
#         else:
#             return False


# Path: ui/views/Plugins.py
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.apps import apps
from QueueDB.models import Profile
import json
import hashlib

#!/usr/bin/env python
# coding=utf-8
# Created by: Li Yao
# Created on: 8/2/20


class Api(object):
    @staticmethod
    def ret_info(valid, results):
        json_data = dict()
        json_data['valid'] = valid
        json_data['results'] = results
        return JsonResponse(json_data)

    def _valid(self):
        """
        Validate API request

        :return: bool
        """
        try:

            user_profile = Profile.objects.get(api_key=self.api_key)