# Path: harnas/settings.py
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# INSTALLED_APPS = (
#     # harnas.home and harnas.customregistration needs to be
#     # at top to allow correct template overriding
#     'harnas.home',
#     'harnas.customregistration',
#     'grappelli',
#     'django.contrib.admin',
#     'django.contrib.auth',
#     'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     'django.contrib.messages',
#     'django.contrib.staticfiles',
#     'django.contrib.sites',
#     'django.contrib.flatpages',
#     'bootstrap3',
#     'registration',
#     'crispy_forms',
#     'guardian',
#     'django_extensions',
#     'harnas.contest',
#     'harnas.checker',
#     'harnas.userprofile',
#     'floppyforms'
# )
# MIDDLEWARE_CLASSES = (
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.common.CommonMiddleware',
#     'django.middleware.csrf.CsrfViewMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
#     'django.contrib.messages.middleware.MessageMiddleware',
#     'django.middleware.clickjacking.XFrameOptionsMiddleware',
#     'django.middleware.security.SecurityMiddleware',
# )
# ROOT_URLCONF = 'harnas.urls'
# TEMPLATES = [
#     {
#         'BACKEND': 'django.template.backends.django.DjangoTemplates',
#         'DIRS': [],
#         'APP_DIRS': True,
#         'OPTIONS': {
#             'context_processors': [
#                 'django.core.context_processors.request',
#                 'django.template.context_processors.debug',
#                 'django.template.context_processors.request',
#                 'django.contrib.auth.context_processors.auth',
#                 'django.contrib.messages.context_processors.messages',
#                 'harnas.contest.processors.contests',
#                 'harnas.home.processors.task_manager_permissions',
#             ],
#         },
#     },
# ]
# WSGI_APPLICATION = 'harnas.wsgi.application'
# LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'UTC'
# USE_I18N = True
# USE_L10N = True
# USE_TZ = True
# STATIC_URL = '/static/'
# SITE_ID = 1
# ACCOUNT_ACTIVATION_DAYS = 7
# LOGIN_REDIRECT_URL = '/'
# ANONYMOUS_USER_ID = -1
# AUTHENTICATION_BACKENDS = (
#     'django.contrib.auth.backends.ModelBackend',
#     'guardian.backends.ObjectPermissionBackend',
# )
# AUTH_PROFILE_MODULE = 'userprofile.UserProfile'
# REGISTRATION_FORM = 'harnas.customregistration.forms.RegistrationForm'
# CRISPY_TEMPLATE_PACK = 'bootstrap3'
# CRISPY_FAIL_SILENTLY = not DEBUG


from datetime import date
from hashlib import md5
from urllib.parse import urlencode
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db import models
from django.db.models.signals import post_save
from django.utils import timezone
from harnas import settings
    personal_page = models.URLField(
          null=True,
          blank=True
    )
    show_email = models.BooleanField(
          default=False
    )
    show_age = models.BooleanField(
          default=True
    )

    @property
    def display_name(self):
        if (self.user.first_name is not None and self.user.first_name.strip() != "") or \
                (self.user.last_name is not None and self.user.last_name.strip() != ""):
            return self.user.first_name + " " + self.user.last_name
        else:
            return self.user.username

    @property
    def gravatar(self, size=200):
        default = 'default_gravatar_male' if self.sex == 'M' \
            else 'default_gravatar_female'

        return "http://www.gravatar.com/avatar/%s?%s" % (
            md5(self.user.email.lower().encode()).hexdigest(),
            urlencode({
                's': str(size),
                'd': 'http://%s%s%s' %
                # EXPERIMENTAL !!! need to be tested in production

# Path: harnas/settings.py
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# INSTALLED_APPS = (
#     # harnas.home and harnas.customregistration needs to be
#     # at top to allow correct template overriding
#     'harnas.home',
#     'harnas.customregistration',
#     'grappelli',
#     'django.contrib.admin',
#     'django.contrib.auth',
#     'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     'django.contrib.messages',
#     'django.contrib.staticfiles',
#     'django.contrib.sites',
#     'django.contrib.flatpages',
#     'bootstrap3',
#     'registration',
#     'crispy_forms',
#     'guardian',
#     'django_extensions',
#     'harnas.contest',
#     'harnas.checker',
#     'harnas.userprofile',
#     'floppyforms'
# )
# MIDDLEWARE_CLASSES = (
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.common.CommonMiddleware',
#     'django.middleware.csrf.CsrfViewMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
#     'django.contrib.messages.middleware.MessageMiddleware',
#     'django.middleware.clickjacking.XFrameOptionsMiddleware',
#     'django.middleware.security.SecurityMiddleware',
# )
# ROOT_URLCONF = 'harnas.urls'
# TEMPLATES = [
#     {
#         'BACKEND': 'django.template.backends.django.DjangoTemplates',
#         'DIRS': [],
#         'APP_DIRS': True,
#         'OPTIONS': {
#             'context_processors': [
#                 'django.core.context_processors.request',
#                 'django.template.context_processors.debug',
#                 'django.template.context_processors.request',
#                 'django.contrib.auth.context_processors.auth',
#                 'django.contrib.messages.context_processors.messages',
#                 'harnas.contest.processors.contests',
#                 'harnas.home.processors.task_manager_permissions',
#             ],
#         },
#     },
# ]
# WSGI_APPLICATION = 'harnas.wsgi.application'
# LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'UTC'
# USE_I18N = True
# USE_L10N = True
# USE_TZ = True
# STATIC_URL = '/static/'
# SITE_ID = 1
# ACCOUNT_ACTIVATION_DAYS = 7
# LOGIN_REDIRECT_URL = '/'
# ANONYMOUS_USER_ID = -1
# AUTHENTICATION_BACKENDS = (
#     'django.contrib.auth.backends.ModelBackend',
#     'guardian.backends.ObjectPermissionBackend',
# )
# AUTH_PROFILE_MODULE = 'userprofile.UserProfile'
# REGISTRATION_FORM = 'harnas.customregistration.forms.RegistrationForm'
# CRISPY_TEMPLATE_PACK = 'bootstrap3'
# CRISPY_FAIL_SILENTLY = not DEBUG


# Path: harnas/userprofile/models.py
from datetime import date
from hashlib import md5
from urllib.parse import urlencode
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db import models
from django.db.models.signals import post_save
from django.utils import timezone
from harnas import settings

    personal_page = models.URLField(
          null=True,
          blank=True
    )
    show_email = models.BooleanField(
          default=False
    )
    show_age = models.BooleanField(
          default=True
    )

    @property
    def display_name(self):
        if (self.user.first_name is not None and self.user.first_name.strip() != "") or \
                (self.user.last_name is not None and self.user.last_name.strip() != ""):
            return self.user.first_name + " " + self.user.last_name
        else:
            return self.user.username

    @property
    def gravatar(self, size=200):
        default = 'default_gravatar_male' if self.sex == 'M' \
            else 'default_gravatar_female'

        return "http://www.gravatar.com/avatar/%s?%s" % (
            md5(self.user.email.lower().encode()).hexdigest(),
            urlencode({
                's': str(size),
                'd': 'http://%s%s%s' %
                # EXPERIMENTAL !!! need to be tested in production

                     (Site.objects.get_current(), settings.STATIC_URL, default)