# Path: shortener/linkmetrics/managers.py
# class LingLogManager(models.Manager):
# 
#     def create_from_request(self, link, request):
#         linklog = self.model(
#             link=link,
#             http_accept_language=request.META.get("HTTP_ACCEPT_LANGUAGE", ""),
#             http_host=request.META.get("HTTP_HOST", ""),
#             http_referer=request.META.get("HTTP_REFERER", ""),
#             http_user_agent=request.META.get("HTTP_USER_AGENT", ""),
#             query_string=request.META.get("QUERY_STRING", ""),
#             remote_addr=request.META.get("REMOTE_ADDR", ""),
#             remote_host=request.META.get("REMOTE_HOST", ""),
#             request_method=request.META.get("REQUEST_METHOD", ""),
#         )
#         linklog.save()
#         return linklog


from django.db import models
from django.utils.translation import ugettext_lazy as _
from model_utils.models import TimeStampedModel
from .managers import LingLogManager
from links.models import Link




class LinkLog(TimeStampedModel):
    """
        TODO - consider moving this to Redis or MongoDB
    """

    link = models.ForeignKey(Link)

    http_accept_language = models.TextField(_("HTTP_ACCEPT_LANGUAGE"), blank=True)
    http_host = models.CharField(_("HTTP_HOST"), max_length=255, blank=True)
    http_referer = models.CharField(_("HTTP_REFERER"), max_length=255, blank=True)
    http_user_agent = models.CharField(_("HTTP_USER_AGENT"), max_length=255, blank=True)
    query_string = models.TextField(_("QUERY_STRING"), blank=True)
    remote_addr = models.CharField(_("REMOTE_ADDR"), max_length=255, blank=True)
    remote_host = models.CharField(_("REMOTE_HOST"), max_length=255, blank=True)
    request_method = models.CharField(_("REQUEST_METHOD"), max_length=30, blank=True)


# Path: shortener/linkmetrics/managers.py
# class LingLogManager(models.Manager):
# 
#     def create_from_request(self, link, request):
#         linklog = self.model(
#             link=link,
#             http_accept_language=request.META.get("HTTP_ACCEPT_LANGUAGE", ""),
#             http_host=request.META.get("HTTP_HOST", ""),
#             http_referer=request.META.get("HTTP_REFERER", ""),
#             http_user_agent=request.META.get("HTTP_USER_AGENT", ""),
#             query_string=request.META.get("QUERY_STRING", ""),
#             remote_addr=request.META.get("REMOTE_ADDR", ""),
#             remote_host=request.META.get("REMOTE_HOST", ""),
#             request_method=request.META.get("REQUEST_METHOD", ""),
#         )
#         linklog.save()
#         return linklog


# Path: shortener/linkmetrics/models.py
from django.db import models
from django.utils.translation import ugettext_lazy as _
from model_utils.models import TimeStampedModel
from .managers import LingLogManager
from links.models import Link





class LinkLog(TimeStampedModel):
    """
        TODO - consider moving this to Redis or MongoDB
    """

    link = models.ForeignKey(Link)

    http_accept_language = models.TextField(_("HTTP_ACCEPT_LANGUAGE"), blank=True)
    http_host = models.CharField(_("HTTP_HOST"), max_length=255, blank=True)
    http_referer = models.CharField(_("HTTP_REFERER"), max_length=255, blank=True)
    http_user_agent = models.CharField(_("HTTP_USER_AGENT"), max_length=255, blank=True)
    query_string = models.TextField(_("QUERY_STRING"), blank=True)
    remote_addr = models.CharField(_("REMOTE_ADDR"), max_length=255, blank=True)
    remote_host = models.CharField(_("REMOTE_HOST"), max_length=255, blank=True)
    request_method = models.CharField(_("REQUEST_METHOD"), max_length=30, blank=True)


    objects = LingLogManager()