mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: pages and inbox issue in dummy data (#4177)
This commit is contained in:
parent
20b0edeaa6
commit
d58bc03db6
@ -1,6 +1,6 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import random
|
import random
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
@ -12,7 +12,6 @@ from faker import Faker
|
|||||||
# Module imports
|
# Module imports
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
Workspace,
|
Workspace,
|
||||||
WorkspaceMember,
|
|
||||||
User,
|
User,
|
||||||
Project,
|
Project,
|
||||||
ProjectMember,
|
ProjectMember,
|
||||||
@ -27,26 +26,13 @@ from plane.db.models import (
|
|||||||
IssueActivity,
|
IssueActivity,
|
||||||
CycleIssue,
|
CycleIssue,
|
||||||
ModuleIssue,
|
ModuleIssue,
|
||||||
|
Page,
|
||||||
|
PageLabel,
|
||||||
|
Inbox,
|
||||||
|
InboxIssue,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_workspace_members(workspace, members):
|
|
||||||
members = User.objects.filter(email__in=members)
|
|
||||||
|
|
||||||
_ = WorkspaceMember.objects.bulk_create(
|
|
||||||
[
|
|
||||||
WorkspaceMember(
|
|
||||||
workspace=workspace,
|
|
||||||
member=member,
|
|
||||||
role=20,
|
|
||||||
)
|
|
||||||
for member in members
|
|
||||||
],
|
|
||||||
ignore_conflicts=True,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def create_project(workspace, user_id):
|
def create_project(workspace, user_id):
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
name = fake.name()
|
name = fake.name()
|
||||||
@ -57,6 +43,7 @@ def create_project(workspace, user_id):
|
|||||||
: random.randint(2, 12 if len(name) - 1 >= 12 else len(name) - 1)
|
: random.randint(2, 12 if len(name) - 1 >= 12 else len(name) - 1)
|
||||||
].upper(),
|
].upper(),
|
||||||
created_by_id=user_id,
|
created_by_id=user_id,
|
||||||
|
inbox_view=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add current member as project member
|
# Add current member as project member
|
||||||
@ -244,12 +231,67 @@ def create_modules(workspace, project, user_id, module_count):
|
|||||||
return Module.objects.bulk_create(modules, ignore_conflicts=True)
|
return Module.objects.bulk_create(modules, ignore_conflicts=True)
|
||||||
|
|
||||||
|
|
||||||
|
def create_pages(workspace, project, user_id, pages_count):
|
||||||
|
fake = Faker()
|
||||||
|
Faker.seed(0)
|
||||||
|
|
||||||
|
pages = []
|
||||||
|
for _ in range(0, pages_count):
|
||||||
|
text = fake.text(max_nb_chars=60000)
|
||||||
|
pages.append(
|
||||||
|
Page(
|
||||||
|
name=fake.name(),
|
||||||
|
project=project,
|
||||||
|
workspace=workspace,
|
||||||
|
owned_by_id=user_id,
|
||||||
|
access=random.randint(0, 1),
|
||||||
|
color=fake.hex_color(),
|
||||||
|
description_html=f"<p>{text}</p>",
|
||||||
|
archived_at=None,
|
||||||
|
is_locked=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return Page.objects.bulk_create(pages, ignore_conflicts=True)
|
||||||
|
|
||||||
|
|
||||||
|
def create_page_labels(workspace, project, user_id, pages_count):
|
||||||
|
# labels
|
||||||
|
labels = Label.objects.filter(project=project).values_list("id", flat=True)
|
||||||
|
pages = random.sample(
|
||||||
|
list(
|
||||||
|
Page.objects.filter(project=project).values_list("id", flat=True)
|
||||||
|
),
|
||||||
|
int(pages_count / 2),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Bulk page labels
|
||||||
|
bulk_page_labels = []
|
||||||
|
for page in pages:
|
||||||
|
for label in random.sample(
|
||||||
|
list(labels), random.randint(0, len(labels) - 1)
|
||||||
|
):
|
||||||
|
bulk_page_labels.append(
|
||||||
|
PageLabel(
|
||||||
|
page_id=page,
|
||||||
|
label_id=label,
|
||||||
|
project=project,
|
||||||
|
workspace=workspace,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Page labels
|
||||||
|
PageLabel.objects.bulk_create(
|
||||||
|
bulk_page_labels, batch_size=1000, ignore_conflicts=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_issues(workspace, project, user_id, issue_count):
|
def create_issues(workspace, project, user_id, issue_count):
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
Faker.seed(0)
|
Faker.seed(0)
|
||||||
|
|
||||||
states = State.objects.values_list("id", flat=True)
|
states = State.objects.filter(workspace=workspace, project=project).exclude(group="Triage").values_list("id", flat=True)
|
||||||
creators = ProjectMember.objects.values_list("member_id", flat=True)
|
creators = ProjectMember.objects.filter(workspace=workspace, project=project).values_list("member_id", flat=True)
|
||||||
|
|
||||||
issues = []
|
issues = []
|
||||||
|
|
||||||
@ -283,15 +325,15 @@ def create_issues(workspace, project, user_id, issue_count):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
sentence = fake.sentence()
|
text = fake.text(max_nb_chars=60000)
|
||||||
issues.append(
|
issues.append(
|
||||||
Issue(
|
Issue(
|
||||||
state_id=states[random.randint(0, len(states) - 1)],
|
state_id=states[random.randint(0, len(states) - 1)],
|
||||||
project=project,
|
project=project,
|
||||||
workspace=workspace,
|
workspace=workspace,
|
||||||
name=sentence[:254],
|
name=text[:254],
|
||||||
description_html=f"<p>{sentence}</p>",
|
description_html=f"<p>{text}</p>",
|
||||||
description_stripped=sentence,
|
description_stripped=text,
|
||||||
sequence_id=last_id,
|
sequence_id=last_id,
|
||||||
sort_order=largest_sort_order,
|
sort_order=largest_sort_order,
|
||||||
start_date=start_date,
|
start_date=start_date,
|
||||||
@ -339,7 +381,35 @@ def create_issues(workspace, project, user_id, issue_count):
|
|||||||
],
|
],
|
||||||
batch_size=100,
|
batch_size=100,
|
||||||
)
|
)
|
||||||
return
|
return issues
|
||||||
|
|
||||||
|
|
||||||
|
def create_inbox_issues(workspace, project, user_id, inbox_issue_count):
|
||||||
|
issues = create_issues(workspace, project, user_id, inbox_issue_count)
|
||||||
|
inbox, create = Inbox.objects.get_or_create(
|
||||||
|
name="Inbox",
|
||||||
|
project=project,
|
||||||
|
is_default=True,
|
||||||
|
)
|
||||||
|
InboxIssue.objects.bulk_create(
|
||||||
|
[
|
||||||
|
InboxIssue(
|
||||||
|
issue=issue,
|
||||||
|
inbox=inbox,
|
||||||
|
status=(status := [-2, -1, 0, 1, 2][random.randint(0, 4)]),
|
||||||
|
snoozed_till=(
|
||||||
|
datetime.now() + timedelta(days=random.randint(1, 30))
|
||||||
|
if status == 0
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
source="in-app",
|
||||||
|
workspace=workspace,
|
||||||
|
project=project,
|
||||||
|
)
|
||||||
|
for issue in issues
|
||||||
|
],
|
||||||
|
batch_size=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_issue_parent(workspace, project, user_id, issue_count):
|
def create_issue_parent(workspace, project, user_id, issue_count):
|
||||||
@ -396,7 +466,7 @@ def create_issue_assignees(workspace, project, user_id, issue_count):
|
|||||||
|
|
||||||
|
|
||||||
def create_issue_labels(workspace, project, user_id, issue_count):
|
def create_issue_labels(workspace, project, user_id, issue_count):
|
||||||
# assignees
|
# labels
|
||||||
labels = Label.objects.filter(project=project).values_list("id", flat=True)
|
labels = Label.objects.filter(project=project).values_list("id", flat=True)
|
||||||
issues = random.sample(
|
issues = random.sample(
|
||||||
list(
|
list(
|
||||||
@ -420,7 +490,7 @@ def create_issue_labels(workspace, project, user_id, issue_count):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Issue assignees
|
# Issue labels
|
||||||
IssueLabel.objects.bulk_create(
|
IssueLabel.objects.bulk_create(
|
||||||
bulk_issue_labels, batch_size=1000, ignore_conflicts=True
|
bulk_issue_labels, batch_size=1000, ignore_conflicts=True
|
||||||
)
|
)
|
||||||
@ -487,16 +557,20 @@ def create_module_issues(workspace, project, user_id, issue_count):
|
|||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def create_dummy_data(
|
def create_dummy_data(
|
||||||
slug, email, members, issue_count, cycle_count, module_count
|
slug,
|
||||||
|
email,
|
||||||
|
members,
|
||||||
|
issue_count,
|
||||||
|
cycle_count,
|
||||||
|
module_count,
|
||||||
|
pages_count,
|
||||||
|
inbox_issue_count,
|
||||||
):
|
):
|
||||||
workspace = Workspace.objects.get(slug=slug)
|
workspace = Workspace.objects.get(slug=slug)
|
||||||
|
|
||||||
user = User.objects.get(email=email)
|
user = User.objects.get(email=email)
|
||||||
user_id = user.id
|
user_id = user.id
|
||||||
|
|
||||||
# create workspace members
|
|
||||||
create_workspace_members(workspace=workspace, members=members)
|
|
||||||
|
|
||||||
# Create a project
|
# Create a project
|
||||||
project = create_project(workspace=workspace, user_id=user_id)
|
project = create_project(workspace=workspace, user_id=user_id)
|
||||||
|
|
||||||
@ -527,6 +601,22 @@ def create_dummy_data(
|
|||||||
module_count=module_count,
|
module_count=module_count,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# create pages
|
||||||
|
create_pages(
|
||||||
|
workspace=workspace,
|
||||||
|
project=project,
|
||||||
|
user_id=user_id,
|
||||||
|
pages_count=pages_count,
|
||||||
|
)
|
||||||
|
|
||||||
|
# create page labels
|
||||||
|
create_page_labels(
|
||||||
|
workspace=workspace,
|
||||||
|
project=project,
|
||||||
|
user_id=user_id,
|
||||||
|
pages_count=pages_count,
|
||||||
|
)
|
||||||
|
|
||||||
# create issues
|
# create issues
|
||||||
create_issues(
|
create_issues(
|
||||||
workspace=workspace,
|
workspace=workspace,
|
||||||
@ -535,6 +625,14 @@ def create_dummy_data(
|
|||||||
issue_count=issue_count,
|
issue_count=issue_count,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# create inbox issues
|
||||||
|
create_inbox_issues(
|
||||||
|
workspace=workspace,
|
||||||
|
project=project,
|
||||||
|
user_id=user_id,
|
||||||
|
inbox_issue_count=inbox_issue_count,
|
||||||
|
)
|
||||||
|
|
||||||
# create issue parent
|
# create issue parent
|
||||||
create_issue_parent(
|
create_issue_parent(
|
||||||
workspace=workspace,
|
workspace=workspace,
|
||||||
|
@ -35,17 +35,6 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
members = input("Enter Member emails (comma separated): ")
|
members = input("Enter Member emails (comma separated): ")
|
||||||
members = members.split(",") if members != "" else []
|
members = members.split(",") if members != "" else []
|
||||||
|
|
||||||
issue_count = int(
|
|
||||||
input("Number of issues to be created: ")
|
|
||||||
)
|
|
||||||
cycle_count = int(
|
|
||||||
input("Number of cycles to be created: ")
|
|
||||||
)
|
|
||||||
module_count = int(
|
|
||||||
input("Number of modules to be created: ")
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create workspace
|
# Create workspace
|
||||||
workspace = Workspace.objects.create(
|
workspace = Workspace.objects.create(
|
||||||
slug=workspace_slug,
|
slug=workspace_slug,
|
||||||
@ -56,18 +45,45 @@ class Command(BaseCommand):
|
|||||||
WorkspaceMember.objects.create(
|
WorkspaceMember.objects.create(
|
||||||
workspace=workspace, role=20, member=user
|
workspace=workspace, role=20, member=user
|
||||||
)
|
)
|
||||||
|
user_ids = User.objects.filter(email__in=members)
|
||||||
|
|
||||||
from plane.bgtasks.dummy_data_task import create_dummy_data
|
_ = WorkspaceMember.objects.bulk_create(
|
||||||
|
[
|
||||||
create_dummy_data.delay(
|
WorkspaceMember(
|
||||||
slug=workspace_slug,
|
workspace=workspace,
|
||||||
email=creator,
|
member=user_id,
|
||||||
members=members,
|
role=20,
|
||||||
issue_count=issue_count,
|
)
|
||||||
cycle_count=cycle_count,
|
for user_id in user_ids
|
||||||
module_count=module_count,
|
],
|
||||||
|
ignore_conflicts=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
project_count = int(input("Number of projects to be created: "))
|
||||||
|
|
||||||
|
for i in range(project_count):
|
||||||
|
print(f"Please provide the following details for project {i+1}:")
|
||||||
|
issue_count = int(input("Number of issues to be created: "))
|
||||||
|
cycle_count = int(input("Number of cycles to be created: "))
|
||||||
|
module_count = int(input("Number of modules to be created: "))
|
||||||
|
pages_count = int(input("Number of pages to be created: "))
|
||||||
|
inbox_issue_count = int(
|
||||||
|
input("Number of inbox issues to be created: ")
|
||||||
|
)
|
||||||
|
|
||||||
|
from plane.bgtasks.dummy_data_task import create_dummy_data
|
||||||
|
|
||||||
|
create_dummy_data.delay(
|
||||||
|
slug=workspace_slug,
|
||||||
|
email=creator,
|
||||||
|
members=members,
|
||||||
|
issue_count=issue_count,
|
||||||
|
cycle_count=cycle_count,
|
||||||
|
module_count=module_count,
|
||||||
|
pages_count=pages_count,
|
||||||
|
inbox_issue_count=inbox_issue_count,
|
||||||
|
)
|
||||||
|
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
self.style.SUCCESS("Data is pushed to the queue")
|
self.style.SUCCESS("Data is pushed to the queue")
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user