Splitting tags if containing ,
parent
e8cc305fb7
commit
d985e93be0
|
@ -21,7 +21,7 @@ from rest_framework import serializers
|
||||||
from .neighbors import get_neighbors
|
from .neighbors import get_neighbors
|
||||||
|
|
||||||
|
|
||||||
class PickleField(serializers.WritableField):
|
class TagsField(serializers.WritableField):
|
||||||
"""
|
"""
|
||||||
Pickle objects serializer.
|
Pickle objects serializer.
|
||||||
"""
|
"""
|
||||||
|
@ -29,7 +29,11 @@ class PickleField(serializers.WritableField):
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def from_native(self, data):
|
def from_native(self, data):
|
||||||
return data
|
if not data:
|
||||||
|
return data
|
||||||
|
|
||||||
|
ret = sum([tag.split(",") for tag in data], [])
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class JsonField(serializers.WritableField):
|
class JsonField(serializers.WritableField):
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
from django.db import connection
|
||||||
|
from taiga.projects.userstories.models import *
|
||||||
|
from taiga.projects.tasks.models import *
|
||||||
|
from taiga.projects.issues.models import *
|
||||||
|
from taiga.projects.models import *
|
||||||
|
|
||||||
|
def _fix_tags_model(tags_model):
|
||||||
|
table_name = tags_model._meta.db_table
|
||||||
|
query = "select id from (select id, unnest(tags) tag from %s) x where tag LIKE '%%,%%'"%(table_name)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
id = row[0]
|
||||||
|
instance = tags_model.objects.get(id=id)
|
||||||
|
instance.tags = [tag.replace(",", "") for tag in instance.tags]
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
|
||||||
|
def fix_tags(apps, schema_editor):
|
||||||
|
print("Fixing user issue tags")
|
||||||
|
_fix_tags_model(Issue)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('issues', '0002_issue_external_reference'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(fix_tags),
|
||||||
|
]
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from taiga.base.serializers import Serializer, PickleField, NeighborsSerializerMixin, PgArrayField
|
from taiga.base.serializers import Serializer, TagsField, NeighborsSerializerMixin, PgArrayField
|
||||||
from taiga.mdrender.service import render as mdrender
|
from taiga.mdrender.service import render as mdrender
|
||||||
from taiga.projects.validators import ProjectExistsValidator
|
from taiga.projects.validators import ProjectExistsValidator
|
||||||
from taiga.projects.notifications.validators import WatchersValidator
|
from taiga.projects.notifications.validators import WatchersValidator
|
||||||
|
@ -25,7 +25,7 @@ from . import models
|
||||||
|
|
||||||
|
|
||||||
class IssueSerializer(WatchersValidator, serializers.ModelSerializer):
|
class IssueSerializer(WatchersValidator, serializers.ModelSerializer):
|
||||||
tags = PickleField(required=False)
|
tags = TagsField(required=False)
|
||||||
external_reference = PgArrayField(required=False)
|
external_reference = PgArrayField(required=False)
|
||||||
is_closed = serializers.Field(source="is_closed")
|
is_closed = serializers.Field(source="is_closed")
|
||||||
comment = serializers.SerializerMethodField("get_comment")
|
comment = serializers.SerializerMethodField("get_comment")
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
from django.db import connection
|
||||||
|
from taiga.projects.userstories.models import *
|
||||||
|
from taiga.projects.tasks.models import *
|
||||||
|
from taiga.projects.issues.models import *
|
||||||
|
from taiga.projects.models import *
|
||||||
|
|
||||||
|
def _fix_tags_model(tags_model):
|
||||||
|
table_name = tags_model._meta.db_table
|
||||||
|
query = "select id from (select id, unnest(tags) tag from %s) x where tag LIKE '%%,%%'"%(table_name)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
id = row[0]
|
||||||
|
instance = tags_model.objects.get(id=id)
|
||||||
|
instance.tags = [tag.replace(",", "") for tag in instance.tags]
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
|
||||||
|
def fix_tags(apps, schema_editor):
|
||||||
|
print("Fixing project tags")
|
||||||
|
_fix_tags_model(Project)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('projects', '0012_auto_20141210_1009'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(fix_tags),
|
||||||
|
]
|
|
@ -0,0 +1,36 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
from django.db import connection
|
||||||
|
from taiga.projects.userstories.models import *
|
||||||
|
from taiga.projects.tasks.models import *
|
||||||
|
from taiga.projects.issues.models import *
|
||||||
|
from taiga.projects.models import *
|
||||||
|
|
||||||
|
def _fix_tags_model(tags_model):
|
||||||
|
table_name = tags_model._meta.db_table
|
||||||
|
query = "select id from (select id, unnest(tags) tag from %s) x where tag LIKE '%%,%%'"%(table_name)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
id = row[0]
|
||||||
|
instance = tags_model.objects.get(id=id)
|
||||||
|
instance.tags = [tag.replace(",", "") for tag in instance.tags]
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
|
||||||
|
def fix_tags(apps, schema_editor):
|
||||||
|
print("Fixing user task tags")
|
||||||
|
_fix_tags_model(Task)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tasks', '0003_task_external_reference'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(fix_tags),
|
||||||
|
]
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from taiga.base.serializers import Serializer, PickleField, NeighborsSerializerMixin, PgArrayField
|
from taiga.base.serializers import Serializer, TagsField, NeighborsSerializerMixin, PgArrayField
|
||||||
from taiga.mdrender.service import render as mdrender
|
from taiga.mdrender.service import render as mdrender
|
||||||
from taiga.projects.validators import ProjectExistsValidator
|
from taiga.projects.validators import ProjectExistsValidator
|
||||||
from taiga.projects.milestones.validators import SprintExistsValidator
|
from taiga.projects.milestones.validators import SprintExistsValidator
|
||||||
|
@ -27,7 +27,7 @@ from . import models
|
||||||
|
|
||||||
|
|
||||||
class TaskSerializer(WatchersValidator, serializers.ModelSerializer):
|
class TaskSerializer(WatchersValidator, serializers.ModelSerializer):
|
||||||
tags = PickleField(required=False, default=[])
|
tags = TagsField(required=False, default=[])
|
||||||
external_reference = PgArrayField(required=False)
|
external_reference = PgArrayField(required=False)
|
||||||
comment = serializers.SerializerMethodField("get_comment")
|
comment = serializers.SerializerMethodField("get_comment")
|
||||||
milestone_slug = serializers.SerializerMethodField("get_milestone_slug")
|
milestone_slug = serializers.SerializerMethodField("get_milestone_slug")
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
from django.db import connection
|
||||||
|
from taiga.projects.userstories.models import *
|
||||||
|
from taiga.projects.tasks.models import *
|
||||||
|
from taiga.projects.issues.models import *
|
||||||
|
from taiga.projects.models import *
|
||||||
|
|
||||||
|
def _fix_tags_model(tags_model):
|
||||||
|
table_name = tags_model._meta.db_table
|
||||||
|
query = "select id from (select id, unnest(tags) tag from %s) x where tag LIKE '%%,%%'"%(table_name)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
id = row[0]
|
||||||
|
instance = tags_model.objects.get(id=id)
|
||||||
|
instance.tags = [tag.replace(",", "") for tag in instance.tags]
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
|
||||||
|
def fix_tags(apps, schema_editor):
|
||||||
|
print("Fixing user story tags")
|
||||||
|
_fix_tags_model(UserStory)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('userstories', '0007_userstory_external_reference'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(fix_tags),
|
||||||
|
]
|
|
@ -18,7 +18,7 @@ import json
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from taiga.base.serializers import Serializer, PickleField, NeighborsSerializerMixin, PgArrayField
|
from taiga.base.serializers import Serializer, TagsField, NeighborsSerializerMixin, PgArrayField
|
||||||
from taiga.mdrender.service import render as mdrender
|
from taiga.mdrender.service import render as mdrender
|
||||||
from taiga.projects.validators import ProjectExistsValidator, UserStoryStatusExistsValidator
|
from taiga.projects.validators import ProjectExistsValidator, UserStoryStatusExistsValidator
|
||||||
from taiga.projects.userstories.validators import UserStoryExistsValidator
|
from taiga.projects.userstories.validators import UserStoryExistsValidator
|
||||||
|
@ -38,7 +38,7 @@ class RolePointsField(serializers.WritableField):
|
||||||
|
|
||||||
|
|
||||||
class UserStorySerializer(WatchersValidator, serializers.ModelSerializer):
|
class UserStorySerializer(WatchersValidator, serializers.ModelSerializer):
|
||||||
tags = PickleField(default=[], required=False)
|
tags = TagsField(default=[], required=False)
|
||||||
external_reference = PgArrayField(required=False)
|
external_reference = PgArrayField(required=False)
|
||||||
points = RolePointsField(source="role_points", required=False)
|
points = RolePointsField(source="role_points", required=False)
|
||||||
total_points = serializers.SerializerMethodField("get_total_points")
|
total_points = serializers.SerializerMethodField("get_total_points")
|
||||||
|
|
Loading…
Reference in New Issue