7 import uuid, logging, json, datetime |
7 import uuid, logging, json, datetime |
8 from django.conf import settings |
8 from django.conf import settings |
9 from django.db import models, transaction |
9 from django.db import models, transaction |
10 from django.core.exceptions import ValidationError |
10 from django.core.exceptions import ValidationError |
11 from django.utils import timezone, dateparse |
11 from django.utils import timezone, dateparse |
|
12 from django.utils.translation import ugettext_lazy as _ |
12 |
13 |
13 |
14 |
14 |
15 |
15 logger = logging.getLogger(__name__) |
16 logger = logging.getLogger(__name__) |
16 auth_user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') |
17 auth_user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') |
118 if self.current_revision: |
119 if self.current_revision: |
119 return self.current_revision.content |
120 return self.current_revision.content |
120 else: |
121 else: |
121 return '' |
122 return '' |
122 |
123 |
|
124 def __unicode__(self): |
|
125 return self.renkan_guid |
|
126 |
|
127 def __str__(self): |
|
128 return self.renkan_guid |
|
129 |
123 @transaction.atomic |
130 @transaction.atomic |
124 def save_renkan(self, updator, timestamp="", title="", content="", create_new_revision=False): |
131 def save_renkan(self, updator, timestamp="", title="", content="", create_new_revision=False): |
125 """ |
132 """ |
126 Saves over current revision or saves a new revision entirely. |
133 Saves over current revision or saves a new revision entirely. |
127 Timestamp must be the current revision modification_date. |
134 Timestamp must be the current revision modification_date. |
128 """ |
135 """ |
129 if (not timestamp) or ((self.current_revision is not None) and dateparse.parse_datetime(timestamp) < self.current_revision.modification_date): |
136 if (not timestamp) or ((self.current_revision is not None) and dateparse.parse_datetime(timestamp) < self.current_revision.modification_date): |
130 logger.error("SAVING RENKAN: provided timestamp is %r, which isn't current revision modification_date %r", timestamp, self.current_revision.modification_date) |
137 logger.error("SAVING RENKAN: provided timestamp is %r, which isn't current revision modification_date %r", timestamp, self.current_revision.modification_date) |
131 raise ValidationError(message="Error saving Renkan: provided timestamp isn't current revision modification_date") |
138 raise ValidationError(_("Cannot save, provided timestamp is invalid")) |
132 else: |
139 else: |
133 dt_timestamp = dateparse.parse_datetime(timestamp) |
140 dt_timestamp = dateparse.parse_datetime(timestamp) |
134 self.save() |
141 self.save() |
135 if create_new_revision: |
142 if create_new_revision: |
136 revision_to_update = Revision(parent_renkan=self) |
143 revision_to_update = Revision(parent_renkan=self) |