Commit ae9f4828 authored by Michal Čihař's avatar Michal Čihař

Initial support for advertisements

parent ed49bd13
This diff is collapsed.
...@@ -34,6 +34,7 @@ from trans.models.unitdata import ( ...@@ -34,6 +34,7 @@ from trans.models.unitdata import (
from trans.models.changes import Change from trans.models.changes import Change
from trans.models.dictionary import Dictionary from trans.models.dictionary import Dictionary
from trans.models.source import Source from trans.models.source import Source
from trans.models.advertisement import Advertisement
@receiver(post_delete, sender=Project) @receiver(post_delete, sender=Project)
......
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import random
from django.utils.translation import ugettext as _, ugettext_lazy
from django.db import models
from django.utils import timezone
class AdvertisementManager(models.Manager):
def get_advertisement(self, placement):
now = timezone.now()
base = self.filter(
placement=placement,
date_start__lt=now,
date_end__gt=now
)
count = base.count()
if count == 0:
return None
offset = random.randint(0, count - 1)
return base[offset]
class Advertisement(models.Model):
PLACEMENT_MAIL_TEXT = 1
PLACEMENT_MAIL_HTML = 2
PLACEMENT_CHOICES = (
(PLACEMENT_MAIL_TEXT, ugettext_lazy('Mail footer (text)')),
(PLACEMENT_MAIL_HTML, ugettext_lazy('Mail footer (HTML)')),
)
placement = models.IntegerField(
choices=PLACEMENT_CHOICES,
verbose_name=ugettext_lazy('Advertisement placement'),
)
date_start = models.DateField(
verbose_name=ugettext_lazy('Advertisement start date'),
)
date_end = models.DateField(
verbose_name=ugettext_lazy('Advertisement end date'),
)
text = models.TextField(
verbose_name=ugettext_lazy('Advertisement text'),
help_text=ugettext_lazy(
'Depending on placement, HTML can be allowed.'
)
)
note = models.TextField(
verbose_name=ugettext_lazy('Note'),
help_text=ugettext_lazy(
'Free form note for your notes, not used within Weblate.'
),
blank=True
)
class Meta(object):
app_label = 'trans'
index_together = [
('placement', 'date_start', 'date_end'),
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment