fix merge conflict

This commit is contained in:
Thomas Steen Rasmussen 2017-03-08 00:07:12 +01:00
commit f7b1f040bb
6 changed files with 64 additions and 14 deletions

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-07 20:04
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('camps', '0019_auto_20170131_1849'),
]
operations = [
migrations.AddField(
model_name='camp',
name='read_only',
field=models.BooleanField(default=False, help_text='Whether the camp is read only (i.e. in the past)'),
),
]

View file

@ -1,4 +1,3 @@
import datetime
from django.db import models from django.db import models
from utils.models import UUIDModel, CreatedUpdatedModel from utils.models import UUIDModel, CreatedUpdatedModel
from program.models import EventType, EventLocation from program.models import EventType, EventLocation
@ -47,6 +46,11 @@ class Camp(CreatedUpdatedModel, UUIDModel):
help_text='The camp teardown period.', help_text='The camp teardown period.',
) )
read_only = models.BooleanField(
help_text='Whether the camp is read only (i.e. in the past)',
default=False
)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('camp_detail', kwargs={'camp_slug': self.slug}) return reverse('camp_detail', kwargs={'camp_slug': self.slug})

View file

@ -1,11 +1,9 @@
from django.contrib import messages
from django.db import models from django.db import models
from utils.models import CreatedUpdatedModel from utils.models import CreatedUpdatedModel, CampRelatedModel
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
class InfoCategory(CreatedUpdatedModel): class InfoCategory(CreatedUpdatedModel, CampRelatedModel):
class Meta: class Meta:
ordering = ['weight', 'headline'] ordering = ['weight', 'headline']
unique_together = (('anchor', 'camp'), ('headline', 'camp')) unique_together = (('anchor', 'camp'), ('headline', 'camp'))
@ -40,7 +38,7 @@ class InfoCategory(CreatedUpdatedModel):
return '%s (%s)' % (self.headline, self.camp) return '%s (%s)' % (self.headline, self.camp)
class InfoItem(CreatedUpdatedModel): class InfoItem(CreatedUpdatedModel, CampRelatedModel):
class Meta: class Meta:
ordering = ['weight', 'headline'] ordering = ['weight', 'headline']
unique_together = (('anchor', 'category'), ('headline', 'category')) unique_together = (('anchor', 'category'), ('headline', 'category'))
@ -69,6 +67,10 @@ class InfoItem(CreatedUpdatedModel):
default = 100, default = 100,
) )
@property
def camp(self):
return self.category.camp
def clean(self): def clean(self):
if InfoCategory.objects.filter(camp=self.category.camp, anchor=self.anchor).exists(): if InfoCategory.objects.filter(camp=self.category.camp, anchor=self.anchor).exists():
# this anchor is already in use on a category, so it cannot be used here (they must be unique on the entire page) # this anchor is already in use on a category, so it cannot be used here (they must be unique on the entire page)

View file

@ -3,13 +3,13 @@ from django.db import models
from django.utils.text import slugify from django.utils.text import slugify
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from utils.models import CreatedUpdatedModel from utils.models import CreatedUpdatedModel, CampRelatedModel
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from datetime import timedelta from datetime import timedelta
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
class UserSubmittedModel(CreatedUpdatedModel): class UserSubmittedModel(CampRelatedModel):
class Meta: class Meta:
abstract = True abstract = True
@ -39,7 +39,7 @@ class UserSubmittedModel(CreatedUpdatedModel):
) )
class EventLocation(CreatedUpdatedModel): class EventLocation(CreatedUpdatedModel, CampRelatedModel):
""" The places where stuff happens """ """ The places where stuff happens """
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
slug = models.SlugField() slug = models.SlugField()
@ -106,7 +106,7 @@ class Event(UserSubmittedModel):
return reverse_lazy('event_detail', kwargs={'camp_slug': self.camp.slug, 'slug': self.slug}) return reverse_lazy('event_detail', kwargs={'camp_slug': self.camp.slug, 'slug': self.slug})
class EventInstance(CreatedUpdatedModel): class EventInstance(CreatedUpdatedModel, CampRelatedModel):
""" An instance of an event """ """ An instance of an event """
event = models.ForeignKey('program.event', related_name='instances') event = models.ForeignKey('program.event', related_name='instances')
when = DateTimeRangeField() when = DateTimeRangeField()
@ -127,6 +127,10 @@ class EventInstance(CreatedUpdatedModel):
if errors: if errors:
raise ValidationError(errors) raise ValidationError(errors)
@property
def camp(self):
return self.event.camp
@property @property
def schedule_date(self): def schedule_date(self):
""" """

View file

@ -1,5 +1,6 @@
import uuid import uuid
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.contrib import messages
from django.db import models from django.db import models
@ -11,7 +12,7 @@ class CleanedModel(models.Model):
try: try:
# call this models full_clean() method before saving, # call this models full_clean() method before saving,
# which in turn calls .clean_fields(), .clean() and .validate_unique() # which in turn calls .clean_fields(), .clean() and .validate_unique()
#self.full_clean() # self.full_clean()
# for some reason self.full_clean() appears to call self.clean() before self.clean_fields() # for some reason self.full_clean() appears to call self.clean() before self.clean_fields()
# which is not supposed to happen. Call them manually one by one instead. # which is not supposed to happen. Call them manually one by one instead.
self.clean_fields() self.clean_fields()
@ -46,3 +47,22 @@ class CreatedUpdatedModel(CleanedModel):
updated = models.DateTimeField(auto_now=True) updated = models.DateTimeField(auto_now=True)
class CampRelatedModel(CleanedModel):
class Meta:
abstract = True
def save(self, **kwargs):
if self.camp.read_only:
if hasattr(self, 'request'):
messages.error(self.request, 'Camp is in read only mode.')
raise ValidationError('This camp is in read only mode.')
super(CampRelatedModel, self).save(**kwargs)
def delete(self, **kwargs):
if self.camp.read_only:
if hasattr(self, 'request'):
messages.error(self.request, 'Camp is in read only mode.')
raise ValidationError('This camp is in read only mode.')
super(CampRelatedModel, self).save(**kwargs)

View file

@ -1,11 +1,11 @@
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.db import models from django.db import models
from django.utils.text import slugify from django.utils.text import slugify
from utils.models import CreatedUpdatedModel, UUIDModel from utils.models import CreatedUpdatedModel, UUIDModel, CampRelatedModel
from .managers import VillageQuerySet from .managers import VillageQuerySet
class Village(CreatedUpdatedModel, UUIDModel): class Village(CreatedUpdatedModel, UUIDModel, CampRelatedModel):
class Meta: class Meta:
ordering = ['name'] ordering = ['name']