# Path: labshare/models.py
# class Device(models.Model):
#     name = models.CharField(max_length=255)
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
# 
#     class Meta:
#         permissions = (
#             ('use_device', 'User/Group is allowed to use that device'),
#         )
# 
#     def __str__(self):
#         return self.name
# 
#     def can_be_used_by(self, user):
#         content_type = ContentType.objects.get_for_model(self)
#         permission_name = "{app}.use_{model}".format(app=content_type.app_label, model=content_type.model)
#         return user.has_perm(permission_name, self) or user.has_perm(permission_name)
# 
#     def serialize(self):
#         return {
#             'name': self.name,
#         }


import sys
from django.core.management import BaseCommand
from rest_framework.authtoken.models import Token
from labshare.models import Device




class Command(BaseCommand):
    help = "lists the authentication token for the given device"

    def add_arguments(self, parser):
        parser.add_argument("device_name",
                            help="the name of the registered device for which the token should be retrieved")

    def handle(self, *args, **options):
        device_name = options["device_name"]
        try:
            device = Device.objects.get(name=device_name)

# Path: labshare/models.py
# class Device(models.Model):
#     name = models.CharField(max_length=255)
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
# 
#     class Meta:
#         permissions = (
#             ('use_device', 'User/Group is allowed to use that device'),
#         )
# 
#     def __str__(self):
#         return self.name
# 
#     def can_be_used_by(self, user):
#         content_type = ContentType.objects.get_for_model(self)
#         permission_name = "{app}.use_{model}".format(app=content_type.app_label, model=content_type.model)
#         return user.has_perm(permission_name, self) or user.has_perm(permission_name)
# 
#     def serialize(self):
#         return {
#             'name': self.name,
#         }


# Path: labshare/management/commands/token.py
import sys
from django.core.management import BaseCommand
from rest_framework.authtoken.models import Token
from labshare.models import Device





class Command(BaseCommand):
    help = "lists the authentication token for the given device"

    def add_arguments(self, parser):
        parser.add_argument("device_name",
                            help="the name of the registered device for which the token should be retrieved")

    def handle(self, *args, **options):
        device_name = options["device_name"]
        try:
            device = Device.objects.get(name=device_name)

        except Device.DoesNotExist: