# Path: securedpi_locks/models.py
# class Lock(models.Model):
#     """Define class for user profile."""
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         related_name='locks',
#         on_delete=models.CASCADE
#     )
#     name = models.CharField(max_length=20)
#     location = models.CharField(max_length=50)
#     description = models.CharField(max_length=50, blank=True)
#     date_created = models.DateField(auto_now_add=True)
#     date_modified = models.DateField(auto_now=True)
#     serial = models.CharField(max_length=50, unique=True)
#     status = models.CharField(max_length=20, default='unlocked')
#     is_active = models.BooleanField(default=False)
#     facial_recognition = models.BooleanField(default=False)
#     RFID = models.CharField(max_length=100, blank=True)
# 
#     def __str__(self):
#         return 'Lock for {}'.format(self.user)
# 
# Path: securedpi_events/models.py
# class Event(models.Model):
#     """Define class for access events."""
# 
#     lock_id = models.CharField(max_length=20, blank=True)
#     action = models.CharField(max_length=30, default='unlock')
#     RFID = models.CharField(max_length=100, blank=True)
#     photo = models.ImageField(
#         upload_to='lock_photos',
#         blank=True,
#         null=True)
#     date_created = models.DateTimeField(auto_now_add=True)
#     serial = models.CharField(max_length=20)
#     status = models.CharField(max_length=20, default='failed')
#     mtype = models.CharField(max_length=20)
# 
#     def __str__(self):
#         """Show event."""
#         return 'Event for {}'.format(self.lock_id)
# 
# Path: securedpi/settings.py
# FLASK_SERVER = os.environ.get('FLASK_SERVER')


from django.views.generic import UpdateView, DeleteView
from securedpi_locks.models import Lock
from securedpi_events.models import Event
from django.http import HttpResponseRedirect
from django.urls import reverse, reverse_lazy
from securedpi.settings import FLASK_SERVER
import requests
    template_name = 'securedpi_locks/edit_lock.html'
    model = Lock
    fields = [
        'name',
        'location',
        'description',
        'is_active',
        'facial_recognition'
    ]

    def get_success_url(self):
        """Set redirection after updating the album."""
        url = reverse('dashboard')
        return url


class DeleteLockView(DeleteView):
    """Delete class to delete a lock."""

    model = Lock
    success_url = reverse_lazy('dashboard')


def manual_action(request, **kwargs):
    """
    Create an instance of Event.

    Make a request to raspberry pi to lock/unlock.
    Chanage lock status to pending. Redirect to dashboard
    """

# Path: securedpi_locks/models.py
# class Lock(models.Model):
#     """Define class for user profile."""
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         related_name='locks',
#         on_delete=models.CASCADE
#     )
#     name = models.CharField(max_length=20)
#     location = models.CharField(max_length=50)
#     description = models.CharField(max_length=50, blank=True)
#     date_created = models.DateField(auto_now_add=True)
#     date_modified = models.DateField(auto_now=True)
#     serial = models.CharField(max_length=50, unique=True)
#     status = models.CharField(max_length=20, default='unlocked')
#     is_active = models.BooleanField(default=False)
#     facial_recognition = models.BooleanField(default=False)
#     RFID = models.CharField(max_length=100, blank=True)
# 
#     def __str__(self):
#         return 'Lock for {}'.format(self.user)
# 
# Path: securedpi_events/models.py
# class Event(models.Model):
#     """Define class for access events."""
# 
#     lock_id = models.CharField(max_length=20, blank=True)
#     action = models.CharField(max_length=30, default='unlock')
#     RFID = models.CharField(max_length=100, blank=True)
#     photo = models.ImageField(
#         upload_to='lock_photos',
#         blank=True,
#         null=True)
#     date_created = models.DateTimeField(auto_now_add=True)
#     serial = models.CharField(max_length=20)
#     status = models.CharField(max_length=20, default='failed')
#     mtype = models.CharField(max_length=20)
# 
#     def __str__(self):
#         """Show event."""
#         return 'Event for {}'.format(self.lock_id)
# 
# Path: securedpi/settings.py
# FLASK_SERVER = os.environ.get('FLASK_SERVER')


# Path: securedpi_locks/views.py
from django.views.generic import UpdateView, DeleteView
from securedpi_locks.models import Lock
from securedpi_events.models import Event
from django.http import HttpResponseRedirect
from django.urls import reverse, reverse_lazy
from securedpi.settings import FLASK_SERVER
import requests

    template_name = 'securedpi_locks/edit_lock.html'
    model = Lock
    fields = [
        'name',
        'location',
        'description',
        'is_active',
        'facial_recognition'
    ]

    def get_success_url(self):
        """Set redirection after updating the album."""
        url = reverse('dashboard')
        return url


class DeleteLockView(DeleteView):
    """Delete class to delete a lock."""

    model = Lock
    success_url = reverse_lazy('dashboard')


def manual_action(request, **kwargs):
    """
    Create an instance of Event.

    Make a request to raspberry pi to lock/unlock.
    Chanage lock status to pending. Redirect to dashboard
    """

    lock = Lock.objects.get(pk=kwargs['pk'])