kopia lustrzana https://gitlab.com/marnanel/chapeau
let's use a SlugField to identify Activities
rodzic
8e9b36696a
commit
354eee6a47
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 2.0.6 on 2018-08-19 18:07
|
# Generated by Django 2.0.6 on 2018-08-19 18:29
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django_kepi.models
|
import django_kepi.models
|
||||||
|
@ -106,57 +106,57 @@ class Migration(migrations.Migration):
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='accept',
|
model_name='accept',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='add',
|
model_name='add',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='create',
|
model_name='create',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='delete',
|
model_name='delete',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='follow',
|
model_name='follow',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='like',
|
model_name='like',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='reject',
|
model_name='reject',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='remove',
|
model_name='remove',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='tombstone',
|
model_name='tombstone',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='undo',
|
model_name='undo',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='update',
|
model_name='update',
|
||||||
name='numeric_id',
|
name='numeric_id',
|
||||||
field=models.PositiveIntegerField(default=django_kepi.models.Cobject.random_number, editable=False, primary_key=True, serialize=False),
|
field=models.SlugField(default=django_kepi.models.Cobject.random_slug, editable=False, primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
migrations.DeleteModel(
|
migrations.DeleteModel(
|
||||||
name='Register',
|
name='Register',
|
|
@ -0,0 +1,68 @@
|
||||||
|
# Generated by Django 2.0.6 on 2018-08-19 18:31
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('django_kepi', '0004_auto_20180819_1829'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='accept',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='add',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='create',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='delete',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='follow',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='like',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='reject',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='remove',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='tombstone',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='undo',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='update',
|
||||||
|
old_name='numeric_id',
|
||||||
|
new_name='slug',
|
||||||
|
),
|
||||||
|
]
|
|
@ -20,13 +20,27 @@ class Cobject(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def random_number():
|
def random_slug():
|
||||||
return randint(0, 2**32)
|
result = ''
|
||||||
|
|
||||||
numeric_id = models.PositiveIntegerField(
|
for i in range(6):
|
||||||
|
digit = randint(0, 35)
|
||||||
|
|
||||||
|
# yes, I know this can be done more efficiently.
|
||||||
|
# I want it to be readable.
|
||||||
|
|
||||||
|
if digit<10:
|
||||||
|
result += chr(ord('0')+digit)
|
||||||
|
else:
|
||||||
|
result += chr(ord('a')+(digit-10))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
slug = models.SlugField(
|
||||||
primary_key = True,
|
primary_key = True,
|
||||||
default = random_number,
|
default = random_slug,
|
||||||
editable = False)
|
editable = False,
|
||||||
|
)
|
||||||
|
|
||||||
verified = models.BooleanField(default=False)
|
verified = models.BooleanField(default=False)
|
||||||
remote_id = models.URLField(blank=True, null=True, default=None)
|
remote_id = models.URLField(blank=True, null=True, default=None)
|
||||||
|
@ -39,7 +53,7 @@ class Cobject(models.Model):
|
||||||
else:
|
else:
|
||||||
return settings.KEPI['URL_FORMAT'] % {
|
return settings.KEPI['URL_FORMAT'] % {
|
||||||
'type': self.__class__.__name__.lower(),
|
'type': self.__class__.__name__.lower(),
|
||||||
'id': self.numeric_id,
|
'slug': self.slug,
|
||||||
}
|
}
|
||||||
|
|
||||||
def is_local(self):
|
def is_local(self):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
KEPI = {
|
KEPI = {
|
||||||
'URL_FORMAT': 'https://example.com/activities/%(type)s/%(id)x',
|
'URL_FORMAT': 'https://example.com/activities/%(type)s/%(slug)s',
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
|
|
Ładowanie…
Reference in New Issue