本文整理汇总了Python中taiga.projects.history.services.make_key_from_model_object函数的典型用法代码示例。如果您正苦于以下问题:Python make_key_from_model_object函数的具体用法?Python make_key_from_model_object怎么用?Python make_key_from_model_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_key_from_model_object函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: data_wiki
def data_wiki(data):
m = type("Models", (object,), {})
m.public_wiki = f.WikiPageFactory(project=data.public_project, slug=4)
m.public_history_entry = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.public_project,
comment="testing public",
key=make_key_from_model_object(m.public_wiki),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
m.private_wiki1 = f.WikiPageFactory(project=data.private_project1, slug=8)
m.private_history_entry1 = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.private_project1,
comment="testing 1",
key=make_key_from_model_object(m.private_wiki1),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
m.private_wiki2 = f.WikiPageFactory(project=data.private_project2, slug=12)
m.private_history_entry2 = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.private_project2,
comment="testing 2",
key=make_key_from_model_object(m.private_wiki2),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
return m
示例2: data_issue
def data_issue(data):
m = type("Models", (object,), {})
m.public_issue = f.IssueFactory(project=data.public_project, ref=3)
m.public_history_entry = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.public_project,
comment="testing public",
key=make_key_from_model_object(m.public_issue),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
m.private_issue1 = f.IssueFactory(project=data.private_project1, ref=7)
m.private_history_entry1 = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.private_project1,
comment="testing 1",
key=make_key_from_model_object(m.private_issue1),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
m.private_issue2 = f.IssueFactory(project=data.private_project2, ref=11)
m.private_history_entry2 = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.private_project2,
comment="testing 2",
key=make_key_from_model_object(m.private_issue2),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
return m
示例3: data_task
def data_task(data):
m = type("Models", (object,), {})
m.public_task = f.TaskFactory(project=data.public_project, ref=2)
m.public_history_entry = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.public_project,
comment="testing public",
key=make_key_from_model_object(m.public_task),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
m.private_task1 = f.TaskFactory(project=data.private_project1, ref=6)
m.private_history_entry1 = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.private_project1,
comment="testing 1",
key=make_key_from_model_object(m.private_task1),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
m.private_task2 = f.TaskFactory(project=data.private_project2, ref=10)
m.private_history_entry2 = f.HistoryEntryFactory.create(
type=HistoryType.change,
project=data.private_project2,
comment="testing 2",
key=make_key_from_model_object(m.private_task2),
diff={},
user={"pk": data.project_member_with_perms.pk},
)
return m
示例4: send_notifications
def send_notifications(obj, *, history):
if history.is_hidden:
return None
key = make_key_from_model_object(obj)
owner = User.objects.get(pk=history.user["pk"])
notification, created = (HistoryChangeNotification.objects.select_for_update()
.get_or_create(key=key,
owner=owner,
project=obj.project,
history_type = history.type))
notification.updated_datetime = timezone.now()
notification.save()
notification.history_entries.add(history)
# Get a complete list of notifiable users for current
# object and send the change notification to them.
notify_users = get_users_to_notify(obj, discard_users=[notification.owner])
for notify_user in notify_users:
notification.notify_users.add(notify_user)
# If we are the min interval is 0 it just work in a synchronous and spamming way
if settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL == 0:
send_sync_notifications(notification.id)
示例5: test_get_comment_versions
def test_get_comment_versions(client):
project = f.create_project()
us = f.create_userstory(project=project)
f.MembershipFactory.create(project=project, user=project.owner, is_admin=True)
key = make_key_from_model_object(us)
history_entry = f.HistoryEntryFactory.create(
type=HistoryType.change,
comment="testing",
key=key,
diff={},
user={"pk": project.owner.id},
edit_comment_date=datetime.datetime.now(),
comment_versions = [{
"comment_html": "<p>test</p>",
"date": "2016-05-09T09:34:27.221Z",
"comment": "test",
"user": {
"id": project.owner.id,
}}])
client.login(project.owner)
url = reverse("userstory-history-comment-versions", args=(us.id,))
url = "%s?id=%s" % (url, history_entry.id)
response = client.get(url, content_type="application/json")
assert 200 == response.status_code, response.status_code
assert response.data[0]["user"]["username"] == project.owner.username
示例6: test_edit_comment
def test_edit_comment(client):
project = f.create_project()
us = f.create_userstory(project=project)
f.MembershipFactory.create(project=project, user=project.owner, is_admin=True)
key = make_key_from_model_object(us)
history_entry = f.HistoryEntryFactory.create(type=HistoryType.change,
comment="testing",
key=key,
diff={},
user={"pk": project.owner.id})
history_entry_created_at = history_entry.created_at
assert history_entry.comment_versions == None
assert history_entry.edit_comment_date == None
client.login(project.owner)
url = reverse("userstory-history-edit-comment", args=(us.id,))
url = "%s?id=%s" % (url, history_entry.id)
data = json.dumps({"comment": "testing update comment"})
response = client.post(url, data, content_type="application/json")
assert 200 == response.status_code, response.status_code
history_entry = HistoryEntry.objects.get(id=history_entry.id)
assert len(history_entry.comment_versions) == 1
assert history_entry.comment == "testing update comment"
assert history_entry.comment_versions[0]["comment"] == "testing"
assert history_entry.edit_comment_date != None
assert history_entry.comment_versions[0]["user"]["id"] == project.owner.id
示例7: _import_action
def _import_action(self, us, action, statuses, options):
key = make_key_from_model_object(us)
typename = get_typename_for_model_class(UserStory)
action_data = self._transform_action_data(us, action, statuses, options)
if action_data is None:
return
change_old = action_data['change_old']
change_new = action_data['change_new']
hist_type = action_data['hist_type']
comment = action_data['comment']
user = action_data['user']
diff = make_diff_from_dicts(change_old, change_new)
fdiff = FrozenDiff(key, diff, {})
entry = HistoryEntry.objects.create(
user=user,
project_id=us.project.id,
key=key,
type=hist_type,
snapshot=None,
diff=fdiff.diff,
values=make_diff_values(typename, fdiff),
comment=comment,
comment_html=mdrender(us.project, comment),
is_hidden=False,
is_snapshot=False,
)
HistoryEntry.objects.filter(id=entry.id).update(created_at=action['date'])
return HistoryEntry.objects.get(id=entry.id)
示例8: _import_event
def _import_event(self, obj, event, options, cumulative_data):
typename = get_typename_for_model_class(type(obj))
key = make_key_from_model_object(obj)
event_data = self._transform_event_data(obj, event, options, cumulative_data)
if event_data is None:
return
change_old = event_data['change_old']
change_new = event_data['change_new']
user = event_data['user']
diff = make_diff_from_dicts(change_old, change_new)
fdiff = FrozenDiff(key, diff, {})
values = make_diff_values(typename, fdiff)
values.update(event_data['update_values'])
entry = HistoryEntry.objects.create(
user=user,
project_id=obj.project.id,
key=key,
type=HistoryType.change,
snapshot=None,
diff=fdiff.diff,
values=values,
comment="",
comment_html="",
is_hidden=False,
is_snapshot=False,
)
HistoryEntry.objects.filter(id=entry.id).update(created_at=event['created_at'])
return HistoryEntry.objects.get(id=entry.id)
示例9: store_history
def store_history(project, obj, history):
serialized = serializers.HistoryExportSerializer(data=history, context={"project": project})
if serialized.is_valid():
serialized.object.key = make_key_from_model_object(obj)
if serialized.object.diff is None:
serialized.object.diff = []
serialized.object._importing = True
serialized.save()
return serialized
add_errors("history", serialized.errors)
return serialized
示例10: _store_history
def _store_history(project, obj, history):
validator = validators.HistoryExportValidator(data=history, context={"project": project})
if validator.is_valid():
validator.object.key = make_key_from_model_object(obj)
if validator.object.diff is None:
validator.object.diff = []
validator.object.project_id = project.id
validator.object._importing = True
validator.save()
return validator
add_errors("history", validator.errors)
return validator
示例11: data_us
def data_us(data):
m = type("Models", (object,), {})
m.public_user_story = f.UserStoryFactory(project=data.public_project, ref=1)
m.public_history_entry = f.HistoryEntryFactory.create(type=HistoryType.change,
comment="testing public",
key=make_key_from_model_object(m.public_user_story),
diff={},
user={"pk": data.project_member_with_perms.pk})
m.private_user_story1 = f.UserStoryFactory(project=data.private_project1, ref=5)
m.private_history_entry1 = f.HistoryEntryFactory.create(type=HistoryType.change,
comment="testing 1",
key=make_key_from_model_object(m.private_user_story1),
diff={},
user={"pk": data.project_member_with_perms.pk})
m.private_user_story2 = f.UserStoryFactory(project=data.private_project2, ref=9)
m.private_history_entry2 = f.HistoryEntryFactory.create(type=HistoryType.change,
comment="testing 2",
key=make_key_from_model_object(m.private_user_story2),
diff={},
user={"pk": data.project_member_with_perms.pk})
return m
示例12: test_delete_comment_by_project_owner
def test_delete_comment_by_project_owner(client):
project = f.create_project()
us = f.create_userstory(project=project)
membership = f.MembershipFactory.create(project=project, user=project.owner, is_owner=True)
key = make_key_from_model_object(us)
history_entry = f.HistoryEntryFactory.create(type=HistoryType.change,
comment="testing",
key=key)
client.login(project.owner)
url = reverse("userstory-history-delete-comment", args=(us.id,))
url = "%s?id=%s"%(url, history_entry.id)
response = client.post(url, content_type="application/json")
assert 200 == response.status_code, response.status_code
示例13: test_get_comment_versions_from_history_entry_without_comment
def test_get_comment_versions_from_history_entry_without_comment(client):
project = f.create_project()
us = f.create_userstory(project=project)
f.MembershipFactory.create(project=project, user=project.owner, is_admin=True)
key = make_key_from_model_object(us)
history_entry = f.HistoryEntryFactory.create(
type=HistoryType.change,
key=key,
diff={},
user={"pk": project.owner.id})
client.login(project.owner)
url = reverse("userstory-history-comment-versions", args=(us.id,))
url = "%s?id=%s" % (url, history_entry.id)
response = client.get(url, content_type="application/json")
assert 200 == response.status_code, response.status_code
assert response.data == None