# Path: app/models.py
# class TheUser(models.Model):
#     """
#     Class for user objects in database.
#     """
#     REMINDER_TEMPLATE = json.dumps({
#         "common": {
#             "fb_page": True,
#             "fb_group": True,
#             "twitter": True,
#             "vk": True,
#             "disabled_all": False
#         },
#         "api": {
#             "app_rate": True
#         },
#         "web": {
#             "app_download": True,
#         },
#     })
# 
#     id_user = models.OneToOneField(User)
#     user_photo = models.ImageField(blank=True, upload_to='user', storage=OverwriteStorage())
#     auth_token = models.CharField(max_length=50, null=True, blank=True)
#     subscription = models.BooleanField(default=True)
#     reminder = models.CharField(max_length=256, null=False, default=REMINDER_TEMPLATE)
# 
#     # ------------------------------------------------------------------------------------------------------------------
#     def __str__(self):
#         return str(self.id_user)
# 
#     # ------------------------------------------------------------------------------------------------------------------
#     def get_api_reminders(self):
#         """
#         Returns the reminders only necessary for API endpoints.
#         """
#         data = json.loads(self.reminder)
# 
#         mobile_data = dict(data['common'])
#         mobile_data.update(data['api'])
# 
#         return mobile_data
# 
#     # ------------------------------------------------------------------------------------------------------------------
#     def get_web_reminders(self):
#         """
#         Returns the reminders only necessary for web part.
#         """
#         data = json.loads(self.reminder)
#         
#         web_data = dict(data['common'])
#         web_data.update(data['web'])
# 
#         return web_data
# 
#     # ------------------------------------------------------------------------------------------------------------------
#     def update_reminder(self, field, value):
#         """
#         Updates the reminder status.
#         """
#         data = json.loads(self.reminder)
# 
#         for key in data:
#             if field in data[key]:
#                 data[key][field] = value
# 
#         self.reminder = json.dumps(data)
#         self.save()


import random
from django.conf import settings
from ..models import TheUser
        if settings.STATIC_URL not in request.path and settings.MEDIA_URL not in request.path:
            self.set_reminder(request)
        else:
            request.session['reminder'] = None

        return self.get_response(request)

    def set_reminder(self, request):
        """
        Sets the reminder to request object.
        """
        if not request.user.is_anonymous:
            self.increment_counter(request)

            if request.session['reminder_counter'] >= SHOW_REMINDER_COUNT:
                request.session['reminder_counter'] = 0
                self.select_reminder(request)
            else:
                request.session['reminder'] = None

    def increment_counter(self, request):
        """
        Raises the reminder counter in each request.
        """
        if 'reminder_counter' in request.session:
            request.session['reminder_counter'] += 1
        else:
            request.session['reminder_counter'] = 0

    def select_reminder(self, request):

# Path: app/models.py
# class TheUser(models.Model):
#     """
#     Class for user objects in database.
#     """
#     REMINDER_TEMPLATE = json.dumps({
#         "common": {
#             "fb_page": True,
#             "fb_group": True,
#             "twitter": True,
#             "vk": True,
#             "disabled_all": False
#         },
#         "api": {
#             "app_rate": True
#         },
#         "web": {
#             "app_download": True,
#         },
#     })
# 
#     id_user = models.OneToOneField(User)
#     user_photo = models.ImageField(blank=True, upload_to='user', storage=OverwriteStorage())
#     auth_token = models.CharField(max_length=50, null=True, blank=True)
#     subscription = models.BooleanField(default=True)
#     reminder = models.CharField(max_length=256, null=False, default=REMINDER_TEMPLATE)
# 
#     # ------------------------------------------------------------------------------------------------------------------
#     def __str__(self):
#         return str(self.id_user)
# 
#     # ------------------------------------------------------------------------------------------------------------------
#     def get_api_reminders(self):
#         """
#         Returns the reminders only necessary for API endpoints.
#         """
#         data = json.loads(self.reminder)
# 
#         mobile_data = dict(data['common'])
#         mobile_data.update(data['api'])
# 
#         return mobile_data
# 
#     # ------------------------------------------------------------------------------------------------------------------
#     def get_web_reminders(self):
#         """
#         Returns the reminders only necessary for web part.
#         """
#         data = json.loads(self.reminder)
#         
#         web_data = dict(data['common'])
#         web_data.update(data['web'])
# 
#         return web_data
# 
#     # ------------------------------------------------------------------------------------------------------------------
#     def update_reminder(self, field, value):
#         """
#         Updates the reminder status.
#         """
#         data = json.loads(self.reminder)
# 
#         for key in data:
#             if field in data[key]:
#                 data[key][field] = value
# 
#         self.reminder = json.dumps(data)
#         self.save()


# Path: app/middleware/reminder_middleware.py
import random
from django.conf import settings
from ..models import TheUser

        if settings.STATIC_URL not in request.path and settings.MEDIA_URL not in request.path:
            self.set_reminder(request)
        else:
            request.session['reminder'] = None

        return self.get_response(request)

    def set_reminder(self, request):
        """
        Sets the reminder to request object.
        """
        if not request.user.is_anonymous:
            self.increment_counter(request)

            if request.session['reminder_counter'] >= SHOW_REMINDER_COUNT:
                request.session['reminder_counter'] = 0
                self.select_reminder(request)
            else:
                request.session['reminder'] = None

    def increment_counter(self, request):
        """
        Raises the reminder counter in each request.
        """
        if 'reminder_counter' in request.session:
            request.session['reminder_counter'] += 1
        else:
            request.session['reminder_counter'] = 0

    def select_reminder(self, request):

        user = TheUser.objects.get(id_user=request.user)