fix merge conflict
This commit is contained in:
commit
f7b1f040bb
20
src/camps/migrations/0020_camp_read_only.py
Normal file
20
src/camps/migrations/0020_camp_read_only.py
Normal 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)'),
|
||||
),
|
||||
]
|
|
@ -1,4 +1,3 @@
|
|||
import datetime
|
||||
from django.db import models
|
||||
from utils.models import UUIDModel, CreatedUpdatedModel
|
||||
from program.models import EventType, EventLocation
|
||||
|
@ -47,6 +46,11 @@ class Camp(CreatedUpdatedModel, UUIDModel):
|
|||
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):
|
||||
return reverse('camp_detail', kwargs={'camp_slug': self.slug})
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
|
||||
from django.contrib import messages
|
||||
from django.db import models
|
||||
from utils.models import CreatedUpdatedModel
|
||||
from utils.models import CreatedUpdatedModel, CampRelatedModel
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class InfoCategory(CreatedUpdatedModel):
|
||||
class InfoCategory(CreatedUpdatedModel, CampRelatedModel):
|
||||
class Meta:
|
||||
ordering = ['weight', 'headline']
|
||||
unique_together = (('anchor', 'camp'), ('headline', 'camp'))
|
||||
|
@ -40,7 +38,7 @@ class InfoCategory(CreatedUpdatedModel):
|
|||
return '%s (%s)' % (self.headline, self.camp)
|
||||
|
||||
|
||||
class InfoItem(CreatedUpdatedModel):
|
||||
class InfoItem(CreatedUpdatedModel, CampRelatedModel):
|
||||
class Meta:
|
||||
ordering = ['weight', 'headline']
|
||||
unique_together = (('anchor', 'category'), ('headline', 'category'))
|
||||
|
@ -69,6 +67,10 @@ class InfoItem(CreatedUpdatedModel):
|
|||
default = 100,
|
||||
)
|
||||
|
||||
@property
|
||||
def camp(self):
|
||||
return self.category.camp
|
||||
|
||||
def clean(self):
|
||||
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)
|
||||
|
|
|
@ -3,13 +3,13 @@ from django.db import models
|
|||
from django.utils.text import slugify
|
||||
from django.conf import settings
|
||||
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 datetime import timedelta
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
|
||||
|
||||
class UserSubmittedModel(CreatedUpdatedModel):
|
||||
class UserSubmittedModel(CampRelatedModel):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
@ -39,7 +39,7 @@ class UserSubmittedModel(CreatedUpdatedModel):
|
|||
)
|
||||
|
||||
|
||||
class EventLocation(CreatedUpdatedModel):
|
||||
class EventLocation(CreatedUpdatedModel, CampRelatedModel):
|
||||
""" The places where stuff happens """
|
||||
name = models.CharField(max_length=100)
|
||||
slug = models.SlugField()
|
||||
|
@ -106,7 +106,7 @@ class Event(UserSubmittedModel):
|
|||
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 """
|
||||
event = models.ForeignKey('program.event', related_name='instances')
|
||||
when = DateTimeRangeField()
|
||||
|
@ -127,6 +127,10 @@ class EventInstance(CreatedUpdatedModel):
|
|||
if errors:
|
||||
raise ValidationError(errors)
|
||||
|
||||
@property
|
||||
def camp(self):
|
||||
return self.event.camp
|
||||
|
||||
@property
|
||||
def schedule_date(self):
|
||||
"""
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.contrib import messages
|
||||
from django.db import models
|
||||
|
||||
|
||||
|
@ -46,3 +47,22 @@ class CreatedUpdatedModel(CleanedModel):
|
|||
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)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.db import models
|
||||
from django.utils.text import slugify
|
||||
from utils.models import CreatedUpdatedModel, UUIDModel
|
||||
from utils.models import CreatedUpdatedModel, UUIDModel, CampRelatedModel
|
||||
from .managers import VillageQuerySet
|
||||
|
||||
|
||||
class Village(CreatedUpdatedModel, UUIDModel):
|
||||
class Village(CreatedUpdatedModel, UUIDModel, CampRelatedModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
|
|
Loading…
Reference in a new issue