Merge branch 'top_year_choice'

1330
remotes/origin/search
Alexander Burdeiny 10 years ago
commit 8da54fb8a3
  1. 9
      expobanner/forms.py
  2. 15
      expobanner/migrations/0002_auto__add_field_top_months.py
  3. 8
      expobanner/models.py
  4. 3
      expobanner/utils.py
  5. 15
      functions/custom_fields.py

@ -292,19 +292,20 @@ class FieldsetMixin(object):
class TopUpdateForm(forms.ModelForm, FieldsetMixin):
cities = forms.CharField(label=u'Город', widget=forms.HiddenInput() ,required=False)
cities = forms.CharField(label=_(u'Город'), widget=forms.HiddenInput() ,required=False)
verbose = u'Изменить выставку'
class Meta:
model = Top
fields = ['catalog', 'position', 'theme', 'country', 'fr', 'to', 'months', 'cities']
fields = [
'catalog', 'position', 'theme', 'country', 'fr', 'to', 'months',
'cities', 'years']
fieldsets = [
{'title': '',
'class': '',
'fields': ['catalog', 'position', 'theme', 'country', 'fr', 'to']},
{'title': _(u'Топ города'),
'class': '',
'fields': ['cities', 'months']}
'fields': ['cities', 'months', 'years']}
]
def __init__(self, *args, **kwargs):
super(TopUpdateForm, self).__init__(*args, **kwargs)

@ -13,6 +13,11 @@ class Migration(SchemaMigration):
self.gf('functions.custom_fields.MonthMultiSelectField')(default=None, max_length=255, null=True, blank=True),
keep_default=False)
# Adding field 'Top.years'
db.add_column(u'expobanner_top', 'years',
self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=None, null=True, blank=True),
keep_default=False)
# Adding M2M table for field cities on 'Top'
m2m_table_name = db.shorten_name(u'expobanner_top_cities')
db.create_table(m2m_table_name, (
@ -27,6 +32,9 @@ class Migration(SchemaMigration):
# Deleting field 'Top.months'
db.delete_column(u'expobanner_top', 'months')
# Deleting field 'Top.years'
db.delete_column(u'expobanner_top', 'years')
# Removing M2M table for field cities on 'Top'
db.delete_table(db.shorten_name(u'expobanner_top_cities'))
@ -171,7 +179,7 @@ class Migration(SchemaMigration):
'country': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['country.Country']", 'null': 'True', 'blank': 'True'}),
'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'flash': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'fr': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2016, 5, 1, 0, 0)'}),
'fr': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2016, 5, 3, 0, 0)'}),
'group': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'banners'", 'null': 'True', 'to': u"orm['expobanner.BannerGroup']"}),
'html': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
@ -273,14 +281,15 @@ class Migration(SchemaMigration):
'country': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['country.Country']", 'null': 'True', 'blank': 'True'}),
'excluded_cities': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['city.City']", 'null': 'True', 'blank': 'True'}),
'excluded_tags': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['theme.Tag']", 'null': 'True', 'blank': 'True'}),
'fr': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2016, 5, 1, 0, 0)'}),
'fr': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2016, 5, 3, 0, 0)'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'link': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['expobanner.Banner']"}),
'months': ('functions.custom_fields.MonthMultiSelectField', [], {'default': 'None', 'max_length': '255', 'null': 'True', 'blank': 'True'}),
'position': ('django.db.models.fields.PositiveIntegerField', [], {'default': '2', 'null': 'True', 'blank': 'True'}),
'stat_pswd': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'theme': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['theme.Theme']", 'null': 'True', 'blank': 'True'}),
'to': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'})
'to': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'years': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'})
},
u'expobanner.topstat': {
'Meta': {'object_name': 'TopStat'},

@ -278,6 +278,11 @@ class Top(models.Model, StatMixin):
"""
store information about events in top
"""
YEARS = map(
lambda x: (x, x),
tuple(xrange(date.today().year - 1, date.today().year + 5))
)
link = models.ForeignKey(Banner)
catalog = models.CharField(max_length=16, verbose_name=u'Каталог для топа')
position = models.PositiveIntegerField(blank=True, default=2, null=True, verbose_name=u'Позиция')
@ -285,7 +290,8 @@ class Top(models.Model, StatMixin):
excluded_tags = models.ManyToManyField('theme.Tag', blank=True, null=True, verbose_name=u'Исключить теги')
country = models.ManyToManyField('country.Country', blank=True, null=True, verbose_name=u'Страны')
cities = models.ManyToManyField('city.City', related_name='top_in_set', blank=True, null=True, verbose_name=_(u'Города'))
months = MonthMultiSelectField(_(u'Топ месяцев'), blank=True, null=True, default=None, max_length=255,)
months = MonthMultiSelectField(_(u'Топ месяца'), blank=True, null=True, default=None, max_length=255,)
years = models.PositiveSmallIntegerField(_(u'Топ года'), choices=YEARS, blank=True, null=True, default=None)
excluded_cities = models.ManyToManyField('city.City', blank=True, null=True, verbose_name=u'Исключить города')
fr = models.DateField(default=date.today(), verbose_name=u'Начало')
to = models.DateField(blank=True, null=True, verbose_name=u'Конец')

@ -144,7 +144,8 @@ def get_top_events(tops, params, request):
continue
# check city
if all([city, city in city_ids, not theme]):
if (month and not month in top.months) or (not month and year):
# check for top of month or top of year
if (month and not month in top.months) or (not month and year and year != str(top.years)):
continue
good_tops.append(top)
continue

@ -241,8 +241,7 @@ _regex_validator = validators.RegexValidator(
class MonthMultiSelectField(models.CharField):
__metaclass__ = models.SubfieldBase
_saved_month_names = None
_saved_choices_start_month = None
_saved_choices_start_year = None
_saved_choices_month = None
_saved_choices = None
_saved_choices_values = None
_inst_saved_choices = set()
@ -259,7 +258,7 @@ class MonthMultiSelectField(models.CharField):
self.validators.append(_regex_validator)
if choices is None:
self._choices = self._make_choices()
self._choices = self.make_choices()
@property
def flatchoices(self):
@ -300,6 +299,7 @@ class MonthMultiSelectField(models.CharField):
def _make_choices(cls):
today = date.today()
#years = [today.year, today.year + 1] # map(lambda x: today.year + x, xrange(0, 2))
cls._saved_choices_month == today.replace(day=1)
choices = []
cls._saved_choices_values = set()
for year in [today.year, today.year + 1]:
@ -310,6 +310,15 @@ class MonthMultiSelectField(models.CharField):
choices.append((year, year_choices))
return choices
@classmethod
def _check_relevance(cls):
return cls._saved_choices_month == date.today().replace(day=1)
def make_choices(self):
if self._saved_choices is not None and self._check_relevance():
return self._saved_choices
return self._make_choices()
@property
def flatchoices(self):
return None

Loading…
Cancel
Save