# Path: holodeck/models.py
# class Dashboard(models.Model):
#     name = models.CharField(max_length=255)
#     owner = models.ForeignKey(User, null=True)
#     share_key = models.CharField(
#         max_length=32,
#         unique=True,
#         blank=True,
#         null=True
#     )
# 
#     def save(self, *args, **kwargs):
#         if not self.share_key:
#             self.share_key = generate_key()
#         super(Dashboard, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name


from functools import wraps
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponseRedirect
from holodeck.models import Dashboard


def login_required(func):
    @wraps(func)
    def wrapped(request, *args, **kwargs):
        if not request.user.is_authenticated():
            request.session['_next'] = request.build_absolute_uri()
            return HttpResponseRedirect(reverse('holodeck-login'))
        return func(request, *args, **kwargs)
    return wrapped

def validate_share(func):
    @wraps(func)
    def wrapped(request, dashboard_id, share_key, *args, **kwargs):
        try:
            Dashboard.objects.get(id=dashboard_id, share_key=share_key)

# Path: holodeck/models.py
# class Dashboard(models.Model):
#     name = models.CharField(max_length=255)
#     owner = models.ForeignKey(User, null=True)
#     share_key = models.CharField(
#         max_length=32,
#         unique=True,
#         blank=True,
#         null=True
#     )
# 
#     def save(self, *args, **kwargs):
#         if not self.share_key:
#             self.share_key = generate_key()
#         super(Dashboard, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name


# Path: holodeck/decorators.py
from functools import wraps
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponseRedirect
from holodeck.models import Dashboard



def login_required(func):
    @wraps(func)
    def wrapped(request, *args, **kwargs):
        if not request.user.is_authenticated():
            request.session['_next'] = request.build_absolute_uri()
            return HttpResponseRedirect(reverse('holodeck-login'))
        return func(request, *args, **kwargs)
    return wrapped

def validate_share(func):
    @wraps(func)
    def wrapped(request, dashboard_id, share_key, *args, **kwargs):
        try:
            Dashboard.objects.get(id=dashboard_id, share_key=share_key)

        except Dashboard.DoesNotExist: