Add created, updated and full_link to every model
This commit is contained in:
parent
e74afdd550
commit
ac629dd116
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.7 on 2016-06-25 11:37
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0005_participation_sound'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='participation',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2016, 6, 25, 11, 37, 1, 575397, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='participation',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 25, 11, 37, 5, 56658, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2016, 6, 25, 11, 37, 6, 538667, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 25, 11, 37, 7, 804703, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -6,14 +6,14 @@ from django.contrib.sites.models import Site
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
|
||||
from ponyconf.utils import enum_to_choices
|
||||
from ponyconf.utils import PonyConfModel, enum_to_choices
|
||||
|
||||
from .utils import generate_user_uid
|
||||
|
||||
__all__ = ['Profile']
|
||||
|
||||
|
||||
class Profile(models.Model):
|
||||
class Profile(PonyConfModel):
|
||||
|
||||
user = models.OneToOneField(User)
|
||||
biography = models.TextField(blank=True, verbose_name='Biography')
|
||||
|
@ -26,7 +26,7 @@ class Profile(models.Model):
|
|||
return reverse('profile')
|
||||
|
||||
|
||||
class Participation(models.Model):
|
||||
class Participation(PonyConfModel):
|
||||
|
||||
TRANSPORTS = IntEnum('Transport', 'train plane others')
|
||||
CONNECTORS = IntEnum('Connector', 'VGA HDMI miniDP')
|
||||
|
|
|
@ -3,8 +3,6 @@ from django.contrib.sites.models import Site
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
|
||||
from ponyconf.utils import full_link
|
||||
|
||||
from .models import Participation, Profile
|
||||
|
||||
ROOT_URL = 'accounts'
|
||||
|
@ -21,7 +19,7 @@ class AccountTests(TestCase):
|
|||
self.client.login(username='b', password='b')
|
||||
for model in [Profile, Participation]:
|
||||
item = model.objects.first()
|
||||
self.assertEqual(self.client.get(full_link(item)).status_code, 200)
|
||||
self.assertEqual(self.client.get(item.full_link()).status_code, 200)
|
||||
self.assertTrue(str(item))
|
||||
|
||||
def test_views(self):
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.7 on 2016-06-25 11:37
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('conversations', '0003_auto_20160615_2031'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='message',
|
||||
options={'ordering': ['created']},
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='message',
|
||||
old_name='date',
|
||||
new_name='created',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='conversationabouttalk',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2016, 6, 25, 11, 37, 10, 600649, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='conversationabouttalk',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 25, 11, 37, 12, 58625, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='conversationwithparticipant',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2016, 6, 25, 11, 37, 13, 178710, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='conversationwithparticipant',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 25, 11, 37, 14, 346657, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='message',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 25, 11, 37, 15, 482594, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -5,12 +5,13 @@ from django.core.urlresolvers import reverse
|
|||
from django.db import models
|
||||
|
||||
from accounts.models import Participation
|
||||
from ponyconf.utils import PonyConfModel
|
||||
from proposals.models import Talk
|
||||
|
||||
from .utils import generate_message_token, notify_by_email
|
||||
|
||||
|
||||
class Message(models.Model):
|
||||
class Message(PonyConfModel):
|
||||
|
||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||
object_id = models.PositiveIntegerField()
|
||||
|
@ -19,11 +20,10 @@ class Message(models.Model):
|
|||
token = models.CharField(max_length=64, default=generate_message_token, unique=True)
|
||||
|
||||
author = models.ForeignKey(User)
|
||||
date = models.DateTimeField(auto_now_add=True)
|
||||
content = models.TextField()
|
||||
|
||||
class Meta:
|
||||
ordering = ['date']
|
||||
ordering = ['created']
|
||||
|
||||
def __str__(self):
|
||||
return "Message from %s" % self.author
|
||||
|
@ -32,7 +32,7 @@ class Message(models.Model):
|
|||
return self.conversation.get_absolute_url()
|
||||
|
||||
|
||||
class Conversation(models.Model):
|
||||
class Conversation(PonyConfModel):
|
||||
|
||||
subscribers = models.ManyToManyField(User, related_name='+', blank=True)
|
||||
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.db import models
|
||||
|
||||
|
||||
def enum_to_choices(enum):
|
||||
return ((item.value, item.name.replace('_', ' ')) for item in list(enum))
|
||||
|
||||
|
||||
def full_link(obj, request=None):
|
||||
protocol = 'https' if request is None or request.is_secure() else 'http'
|
||||
return '%s://%s%s' % (protocol, get_current_site(request), obj.get_absolute_url())
|
||||
class PonyConfModel(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def full_link(self, request=None):
|
||||
protocol = 'https' if request is None or request.is_secure() else 'http'
|
||||
return '%s://%s%s' % (protocol, get_current_site(request), self.get_absolute_url())
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.7 on 2016-06-25 11:37
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('proposals', '0003_auto_20160625_1037'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='speech',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2016, 6, 25, 11, 37, 17, 777177, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='speech',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 25, 11, 37, 19, 212622, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='talk',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2016, 6, 25, 11, 37, 20, 576319, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='talk',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 25, 11, 37, 21, 782675, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='topic',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2016, 6, 25, 11, 37, 23, 418591, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='topic',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 25, 11, 37, 24, 722598, tzinfo=utc)),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -9,12 +9,12 @@ from django.db import models
|
|||
from autoslug import AutoSlugField
|
||||
|
||||
from accounts.models import Participation
|
||||
from ponyconf.utils import enum_to_choices
|
||||
from ponyconf.utils import PonyConfModel, enum_to_choices
|
||||
|
||||
__all__ = ['Topic', 'Talk', 'Speech']
|
||||
|
||||
|
||||
class Topic(models.Model):
|
||||
class Topic(PonyConfModel):
|
||||
|
||||
name = models.CharField(max_length=128, verbose_name='Name', unique=True)
|
||||
slug = AutoSlugField(populate_from='name', unique=True)
|
||||
|
@ -28,7 +28,7 @@ class Topic(models.Model):
|
|||
return reverse('list-talks-by-topic', kwargs={'topic': self.slug})
|
||||
|
||||
|
||||
class Talk(models.Model):
|
||||
class Talk(PonyConfModel):
|
||||
|
||||
EVENTS = IntEnum('Event', 'conference_short conference_long workshop stand other')
|
||||
|
||||
|
@ -65,7 +65,7 @@ class Talk(models.Model):
|
|||
return self.topics.filter(reviewers=participation).exists()
|
||||
|
||||
|
||||
class Speech(models.Model):
|
||||
class Speech(PonyConfModel):
|
||||
|
||||
SPEAKER_NO = tuple((i, str(i)) for i in range(1, 8))
|
||||
|
||||
|
|
Loading…
Reference in New Issue