kopia lustrzana https://gitlab.com/marnanel/chapeau
AcItem gains a "serial" field for the serial number (at the end of
the URL path, after the username). It gets set automatically.remote_update_not_partial
rodzic
6ce087579f
commit
c82a6def70
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.4 on 2019-11-15 15:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('kepi', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='acitem',
|
||||
name='serial',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
|
@ -3,6 +3,7 @@ from . import acobject, audience
|
|||
from .. import PUBLIC_IDS
|
||||
from django.conf import settings
|
||||
import logging
|
||||
import random
|
||||
|
||||
logger = logging.getLogger(name='chapeau')
|
||||
|
||||
|
@ -20,6 +21,32 @@ class AcItem(acobject.AcObject):
|
|||
blank=True,
|
||||
)
|
||||
|
||||
serial = models.IntegerField(
|
||||
default = 0,
|
||||
)
|
||||
|
||||
def _generate_id(self):
|
||||
if not self.f_attributedTo:
|
||||
logger.info(' -- new object has no f_attributedTo')
|
||||
return super()._generate_id()
|
||||
|
||||
max_so_far = AcItem.objects.filter(
|
||||
f_attributedTo = self.f_attributedTo,
|
||||
).aggregate(models.Max('serial'))['serial__max']
|
||||
|
||||
if max_so_far is None:
|
||||
max_so_far = 0
|
||||
|
||||
self.serial = max_so_far + random.randint(0, 256)
|
||||
|
||||
logger.info(' -- max serial so far is %d; using serial %d',
|
||||
max_so_far, self.serial)
|
||||
|
||||
# TODO: For now, we return the same IDs as the superclass.
|
||||
# When I'm sure the serial numbers work and the tests pass,
|
||||
# we'll have IDs in the form "/username/serial".
|
||||
return super()._generate_id()
|
||||
|
||||
@property
|
||||
def visibility(self):
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue