# Path: depot/models.py
# class Item(models.Model):
#     """
#     An item describes one or more instances of an object in a depot.
# 
#     It always belongs to a single depot and has a unique name within the depot.
#     The location field can be used to roughly describe where
#     the item can be found in the depot.
#     Items can either be public or internal which affects the visibility
#     of the item to users outside of the organization connected to the depot.
#     The quantity describes how many version of the item exist in the depot.
# 
#     :author: Leo Tappe
#     """
# 
#     VISIBILITY_PUBLIC = '1'
#     VISIBILITY_INTERNAL = '2'
#     VISIBILITY_DELETED = '3'
#     VISIBILITY_LEVELS = (
#         (VISIBILITY_PUBLIC, _('public')),
#         (VISIBILITY_INTERNAL, _('internal')),
#         (VISIBILITY_DELETED, _('deleted')),
#     )
# 
#     name = models.CharField(max_length=32)
#     description = models.CharField(max_length=1024, blank=True)
#     quantity = models.PositiveSmallIntegerField()
#     visibility = models.CharField(max_length=1, choices=VISIBILITY_LEVELS)
#     location = models.CharField(max_length=256, blank=True)
#     depot = models.ForeignKey(Depot, on_delete=models.CASCADE)
# 
#     @staticmethod
#     def filter_by_user(user):
#         """
#         Filter for items managed by the given user
#         """
# 
#         return (models.Q(depot__organization__managers__id=user.id)
#                 | models.Q(depot__manager_users__id=user.id)
#                 | models.Q(depot__manager_groups__id__in=user.groups.all()))
# 
#     class Meta:
#         unique_together = (
#             ('name', 'depot'),
#         )
# 
#     def __str__(self):
#         return self.name
# 
# Path: rental/models.py
# class Rental(models.Model):
#     """
#     A rental defines the amount of items and has a start and return date.
#     Only items from one depot can be requested for rental at once.
# 
#     When requesting a rental, the user has to enter his full name and email
#     address as well as describing the purpose of his rental. If they are
#     logged in, the user's id will be stored as well.
# 
#     After creating a rental request, it is in the PENDING state. From this,
#     it can be either APPROVED or DECLINED by a depot manager or REVOKED by
#     the requesting user. If all items were returned correctly, it can be
#     set to RETURNED to finish the rental process.
# 
#     :author: Benedikt Seidl
#     """
# 
#     STATE_PENDING = '1'
#     STATE_APPROVED = '2'
#     STATE_DECLINED = '3'
#     STATE_REVOKED = '4'
#     STATE_RETURNED = '5'
#     STATES = (
#         (STATE_PENDING, _('pending')),
#         (STATE_APPROVED, _('approved')),
#         (STATE_DECLINED, _('declined')),
#         (STATE_REVOKED, _('revoked')),
#         (STATE_RETURNED, _('returned')),
#     )
# 
#     uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
#     depot = models.ForeignKey(Depot, on_delete=models.CASCADE)
#     items = models.ManyToManyField(Item, through='ItemRental')
#     firstname = models.CharField(max_length=32)
#     lastname = models.CharField(max_length=32)
#     email = models.EmailField()
#     purpose = models.CharField(max_length=256)
#     user = models.ForeignKey(User, blank=True, null=True, on_delete=models.SET_NULL)
#     start_date = models.DateTimeField()
#     return_date = models.DateTimeField()
#     state = models.CharField(max_length=1, choices=STATES, default=STATE_PENDING)
# 
#     def clean(self):
#         if not self.depot.active:
#             raise ValidationError({'depot': 'The depot has to be active.'})
# 
#         if self.start_date > self.return_date:
#             raise ValidationError({
#                 'start_date': 'The start date must be before the return date.'
#             })
# 
#         if self.start_date < datetime.now() and self.state == self.STATE_PENDING:
#             raise ValidationError({
#                 'start_date': 'The start date must be in the future for new rentals.'
#             })
# 
#     def __str__(self):
#         return 'Rental by %s %s' % (self.firstname, self.lastname)


import json
from django import template
from django.urls import translate_url
from depot.models import Item
from rental.models import Rental
    If the current page belongs to the given app, then return the given content.

    :author: Benedikt Seidl
    """

    current_app_name = context['request'].resolver_match.app_names[0]
    if app_name == current_app_name:
        return content


@register.simple_tag(takes_context=True)
def base_url(context):
    return context['request'].build_absolute_uri('/')[:-1]


@register.simple_tag(takes_context=True)
def change_lang(context, lang):
    path = context['request'].path

    return translate_url(path, lang)


@register.simple_tag
def item_visibility(visibility):
    """
    Turn the given visibility into a readable string.

    :author: Florian Stamer
    """


# Path: depot/models.py
# class Item(models.Model):
#     """
#     An item describes one or more instances of an object in a depot.
# 
#     It always belongs to a single depot and has a unique name within the depot.
#     The location field can be used to roughly describe where
#     the item can be found in the depot.
#     Items can either be public or internal which affects the visibility
#     of the item to users outside of the organization connected to the depot.
#     The quantity describes how many version of the item exist in the depot.
# 
#     :author: Leo Tappe
#     """
# 
#     VISIBILITY_PUBLIC = '1'
#     VISIBILITY_INTERNAL = '2'
#     VISIBILITY_DELETED = '3'
#     VISIBILITY_LEVELS = (
#         (VISIBILITY_PUBLIC, _('public')),
#         (VISIBILITY_INTERNAL, _('internal')),
#         (VISIBILITY_DELETED, _('deleted')),
#     )
# 
#     name = models.CharField(max_length=32)
#     description = models.CharField(max_length=1024, blank=True)
#     quantity = models.PositiveSmallIntegerField()
#     visibility = models.CharField(max_length=1, choices=VISIBILITY_LEVELS)
#     location = models.CharField(max_length=256, blank=True)
#     depot = models.ForeignKey(Depot, on_delete=models.CASCADE)
# 
#     @staticmethod
#     def filter_by_user(user):
#         """
#         Filter for items managed by the given user
#         """
# 
#         return (models.Q(depot__organization__managers__id=user.id)
#                 | models.Q(depot__manager_users__id=user.id)
#                 | models.Q(depot__manager_groups__id__in=user.groups.all()))
# 
#     class Meta:
#         unique_together = (
#             ('name', 'depot'),
#         )
# 
#     def __str__(self):
#         return self.name
# 
# Path: rental/models.py
# class Rental(models.Model):
#     """
#     A rental defines the amount of items and has a start and return date.
#     Only items from one depot can be requested for rental at once.
# 
#     When requesting a rental, the user has to enter his full name and email
#     address as well as describing the purpose of his rental. If they are
#     logged in, the user's id will be stored as well.
# 
#     After creating a rental request, it is in the PENDING state. From this,
#     it can be either APPROVED or DECLINED by a depot manager or REVOKED by
#     the requesting user. If all items were returned correctly, it can be
#     set to RETURNED to finish the rental process.
# 
#     :author: Benedikt Seidl
#     """
# 
#     STATE_PENDING = '1'
#     STATE_APPROVED = '2'
#     STATE_DECLINED = '3'
#     STATE_REVOKED = '4'
#     STATE_RETURNED = '5'
#     STATES = (
#         (STATE_PENDING, _('pending')),
#         (STATE_APPROVED, _('approved')),
#         (STATE_DECLINED, _('declined')),
#         (STATE_REVOKED, _('revoked')),
#         (STATE_RETURNED, _('returned')),
#     )
# 
#     uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
#     depot = models.ForeignKey(Depot, on_delete=models.CASCADE)
#     items = models.ManyToManyField(Item, through='ItemRental')
#     firstname = models.CharField(max_length=32)
#     lastname = models.CharField(max_length=32)
#     email = models.EmailField()
#     purpose = models.CharField(max_length=256)
#     user = models.ForeignKey(User, blank=True, null=True, on_delete=models.SET_NULL)
#     start_date = models.DateTimeField()
#     return_date = models.DateTimeField()
#     state = models.CharField(max_length=1, choices=STATES, default=STATE_PENDING)
# 
#     def clean(self):
#         if not self.depot.active:
#             raise ValidationError({'depot': 'The depot has to be active.'})
# 
#         if self.start_date > self.return_date:
#             raise ValidationError({
#                 'start_date': 'The start date must be before the return date.'
#             })
# 
#         if self.start_date < datetime.now() and self.state == self.STATE_PENDING:
#             raise ValidationError({
#                 'start_date': 'The start date must be in the future for new rentals.'
#             })
# 
#     def __str__(self):
#         return 'Rental by %s %s' % (self.firstname, self.lastname)


# Path: verleihtool/templates/tags.py
import json
from django import template
from django.urls import translate_url
from depot.models import Item
from rental.models import Rental

    If the current page belongs to the given app, then return the given content.

    :author: Benedikt Seidl
    """

    current_app_name = context['request'].resolver_match.app_names[0]
    if app_name == current_app_name:
        return content


@register.simple_tag(takes_context=True)
def base_url(context):
    return context['request'].build_absolute_uri('/')[:-1]


@register.simple_tag(takes_context=True)
def change_lang(context, lang):
    path = context['request'].path

    return translate_url(path, lang)


@register.simple_tag
def item_visibility(visibility):
    """
    Turn the given visibility into a readable string.

    :author: Florian Stamer
    """


    return dict(Item.VISIBILITY_LEVELS)[visibility]