# Path: archive_chan/settings.py
# class AppSettings:
#     app_settings = {
#         'API_WAIT': 1, # [seconds] Delay between two API calls (catalog/list of posts). This should follow the API rules.
#         'FILE_WAIT': 0, # [seconds] Delay between two file downloads (images/thumbnails). This should follow the API rules (no limit at this point).
#         'CONNECTION_TIMEOUT': 10, # [seconds] Code downloading the data will stop waiting for a response after that time.
#         'RECENT_POSTS_AGE': 48, # [hours] Used for selecting statistics when the board stores posts forever without deleting them. Read more in views.ajax_board_stats
#         'SCRAPER_THREADS_NUMBER': 4, # Number of additional program threads running at the same time. In other words that many 4chan threads will be updated at the same time.
#         'VIEW_CACHE_AGE': 60 * 5, # [seconds] max age of the dynamic pages eg. board
#         'VIEW_CACHE_AGE_STATIC': 60 * 60 * 24, # [seconds] max age of the static pages eg. stats
#         'MEDIA_URL': settings.MEDIA_URL, # You can override the URL from which the downloaded photos are served.
#     }
# 
#     @classmethod
#     def get(self, name):
#         return getattr(settings, 'ARCHIVE_CHAN_' + name, self.app_settings[name])


import os, time
from django.db import models
from django.db.models import Max, Min, Count, F
from django.core.urlresolvers import reverse
from django.core.files.storage import FileSystemStorage
from archive_chan.settings import AppSettings
from django.db.models.signals import pre_delete, post_save, pre_delete, post_delete
from django.dispatch.dispatcher import receiver

    def __str__(self):
        return format("#%s" % (self.number))

    def get_absolute_url(self):
        return '%s#post-%s' % (self.thread.get_absolute_url(), self.number)

class Image(models.Model):
    original_name = models.CharField(max_length=255)
    post = models.OneToOneField('Post')
    image = models.FileField(upload_to = "post_images", storage=fs) # It is impossible to use ImageField to store webm.
    thumbnail = models.FileField(upload_to = "post_thumbnails", storage=fs)

    def get_extension(self):
        name, extension = os.path.splitext(self.image.name)
        return extension


class Trigger(models.Model):
    FIELD_CHOICES = (
        ('name', 'Name'),
        ('trip', 'Trip'),
        ('email', 'Email'),
        ('subject', 'Subject'),
        ('comment', 'Comment'),
    )

    EVENT_CHOICES = (
        ('contains', 'Contains'),
        ('containsno', 'Doesn\'t contain'),

# Path: archive_chan/settings.py
# class AppSettings:
#     app_settings = {
#         'API_WAIT': 1, # [seconds] Delay between two API calls (catalog/list of posts). This should follow the API rules.
#         'FILE_WAIT': 0, # [seconds] Delay between two file downloads (images/thumbnails). This should follow the API rules (no limit at this point).
#         'CONNECTION_TIMEOUT': 10, # [seconds] Code downloading the data will stop waiting for a response after that time.
#         'RECENT_POSTS_AGE': 48, # [hours] Used for selecting statistics when the board stores posts forever without deleting them. Read more in views.ajax_board_stats
#         'SCRAPER_THREADS_NUMBER': 4, # Number of additional program threads running at the same time. In other words that many 4chan threads will be updated at the same time.
#         'VIEW_CACHE_AGE': 60 * 5, # [seconds] max age of the dynamic pages eg. board
#         'VIEW_CACHE_AGE_STATIC': 60 * 60 * 24, # [seconds] max age of the static pages eg. stats
#         'MEDIA_URL': settings.MEDIA_URL, # You can override the URL from which the downloaded photos are served.
#     }
# 
#     @classmethod
#     def get(self, name):
#         return getattr(settings, 'ARCHIVE_CHAN_' + name, self.app_settings[name])


# Path: archive_chan/models.py
import os, time
from django.db import models
from django.db.models import Max, Min, Count, F
from django.core.urlresolvers import reverse
from django.core.files.storage import FileSystemStorage
from archive_chan.settings import AppSettings
from django.db.models.signals import pre_delete, post_save, pre_delete, post_delete
from django.dispatch.dispatcher import receiver


    def __str__(self):
        return format("#%s" % (self.number))

    def get_absolute_url(self):
        return '%s#post-%s' % (self.thread.get_absolute_url(), self.number)

class Image(models.Model):
    original_name = models.CharField(max_length=255)
    post = models.OneToOneField('Post')
    image = models.FileField(upload_to = "post_images", storage=fs) # It is impossible to use ImageField to store webm.
    thumbnail = models.FileField(upload_to = "post_thumbnails", storage=fs)

    def get_extension(self):
        name, extension = os.path.splitext(self.image.name)
        return extension


class Trigger(models.Model):
    FIELD_CHOICES = (
        ('name', 'Name'),
        ('trip', 'Trip'),
        ('email', 'Email'),
        ('subject', 'Subject'),
        ('comment', 'Comment'),
    )

    EVENT_CHOICES = (
        ('contains', 'Contains'),
        ('containsno', 'Doesn\'t contain'),

        ('is', 'Is'),