<commit_before># -*- coding: utf-8 -*-
"""
Site tools models module
===============================================

.. module:: sitetools.models
    :platform: Django
    :synopsis: Site tools models module
.. moduleauthor:: (C) 2014 <NAME>
"""

# Python imports
import sys
import traceback
import json

# Django imports
from django.db import models
from django.contrib.sites.models import Site
from django.utils.translation import ugettext,ugettext_lazy as _
from django.core.mail import mail_admins as django_mail_admins
from django.core.exceptions import ValidationError
from django.template import Template, Context, RequestContext
from django.template.loader import render_to_string
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey

# Applications imports
from sitetools.utils import get_site_from_request
from sitetools.models.fields import CountryField, LanguageField, JSONField

class SiteInfo(models.Model):
    """
    Site information model
    """
    class Meta:
        """
        Metadata for this model
        """
        verbose_name=_('Site information')
        verbose_name_plural=_('Site information')
    
    site=models.OneToOneField(Site,verbose_name=_('Site'),
        help_text=_('Site this information is bound to'))
    maintenance=models.BooleanField(_('Maintenance'),default=False,
        help_text=_('Specify if this site is currently under maintenance'))
    active=models.BooleanField(_('Active'),default=False,
        help_text=_('Specifies if this site is currently active'))

    def get_vars(self,varnames=None):
        """
        Get all site variables in a dictionary
        """
        varlist=SiteVar.objects.filter(site=self)
        if varnames:
            varlist=varlist.filter(name__in=varlist)
        data={}
        for var in varlist:
            data[var.name]=var.get_value()
        return data

    def get_var(self,name,default=None):
        """
        Get a variable value for this site
        """
        var=self.get_vars([name])
        return var.get(name,default)

    def __unicode__(self):
        """
        Unicode representation
        """
        return self.site.domain

class SiteVar(models.Model):
    """
    Site variables model
    """
    VAR_UNICODE='unicode'
    VAR_INT='int'
    VAR_FLOAT='float'
    VAR_BOOL='bool'
    VAR_LIST='list'
    VAR_JSON='json'

    VAR_TYPES=(<commit_msg>Fixed error in get_vars method<commit_after># -*- coding: utf-8 -*-
"""
Site tools models module
===============================================

.. module:: sitetools.models
    :platform: Django
    :synopsis: Site tools models module
.. moduleauthor:: (C) 2014 <NAME>
"""

# Python imports
import sys
import traceback
import json

# Django imports
from django.db import models
from django.contrib.sites.models import Site
from django.utils.translation import ugettext,ugettext_lazy as _
from django.core.mail import mail_admins as django_mail_admins
from django.core.exceptions import ValidationError
from django.template import Template, Context, RequestContext
from django.template.loader import render_to_string
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey

# Applications imports
from sitetools.utils import get_site_from_request
from sitetools.models.fields import CountryField, LanguageField, JSONField

class SiteInfo(models.Model):
    """
    Site information model
    """
    class Meta:
        """
        Metadata for this model
        """
        verbose_name=_('Site information')
        verbose_name_plural=_('Site information')
    
    site=models.OneToOneField(Site,verbose_name=_('Site'),
        help_text=_('Site this information is bound to'))
    maintenance=models.BooleanField(_('Maintenance'),default=False,
        help_text=_('Specify if this site is currently under maintenance'))
    active=models.BooleanField(_('Active'),default=False,
        help_text=_('Specifies if this site is currently active'))

    def get_vars(self,varnames=None):
        """
        Get all site variables in a dictionary
        """
        varlist=SiteVar.objects.filter(site=self)
        if varnames is not None:
            varlist=varlist.filter(name__in=varnames)
        data={}
        for var in varlist:
            data[var.name]=var.get_value()
        print data
        return data

    def get_var(self,name,default=None):
        """
        Get a variable value for this site
        """
        var=self.get_vars([name])
        print var
        return var.get(name,default)

    def __unicode__(self):
        """
        Unicode representation
        """
        return self.site.domain

class SiteVar(models.Model):
    """
    Site variables model
    """
    VAR_UNICODE='unicode'
    VAR_INT='int'
    VAR_FLOAT='float'
    VAR_BOOL='bool'
    VAR_LIST='list'
    VAR_JSON='json'

    VAR_TYPES=(
{'fraction_non_alphanumeric': 0.11311768207977774, 'fraction_numerical': 0.0019845207382417148, 'mean_word_length': 3.2930153321976148, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2103209', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1375, 'n_words': 364}