本文整理汇总了Python中taiga.users.services.get_photo_or_gravatar_url函数的典型用法代码示例。如果您正苦于以下问题:Python get_photo_or_gravatar_url函数的具体用法?Python get_photo_or_gravatar_url怎么用?Python get_photo_or_gravatar_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_photo_or_gravatar_url函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_slackhook
def create_slackhook(url, channel, obj):
obj_type = _get_type(obj)
template = loader.get_template('taiga_contrib_slack/create.jinja')
context = Context({"obj": obj, "obj_type": obj_type})
description = getattr(obj, 'description', '-')
data = {
"text": template.render(context),
"attachments": [{
"color": "good",
"fields": [{
"title": "Creator",
"value": obj.owner.get_full_name(),
"short": True,
}]
}]
}
if description:
data["attachments"][0]["fields"].append({
"title": "Description",
"value": description,
"short": False,
})
if channel:
data["channel"] = channel
data["username"] = "{} ({})".format(getattr(settings, "SLACKHOOKS_USERNAME", "Taiga"), obj.owner.get_full_name())
data["icon_url"] = get_photo_or_gravatar_url(obj.owner)
if not data["icon_url"].startswith("http"):
data["icon_url"] = "https:{}".format(data["icon_url"])
_send_request(url, data)
示例2: delete_slackhook
def delete_slackhook(url, channel, notify_config, obj, change):
obj_type = _get_type(obj)
if not _check_notify_permission(notify_config, obj_type, 'delete'):
return
template = loader.get_template('taiga_contrib_slack/delete.jinja')
context = Context({"obj": obj, "obj_type": obj_type})
description = getattr(obj, 'description', '-')
data = {
"text": template.render(context),
"attachments": [{
"color": "danger",
"fields": [{
"title": "Description",
"value": description,
"short": False,
}]
}]
}
if channel:
data["channel"] = channel
data["username"] = "{} ({})".format(getattr(settings, "SLACKHOOKS_USERNAME", "Taiga"), change.user['name'])
try:
user = User.objects.get(pk=change.user['pk'])
data["icon_url"] = get_photo_or_gravatar_url(user)
if not data["icon_url"].startswith("http"):
data["icon_url"] = "https:{}".format(data["icon_url"])
except User.DoesNotExist:
data["icon_url"] = getattr(settings, "SLACKHOOKS_ICON", "https://tree.taiga.io/images/favicon.png")
_send_request(url, data)
示例3: extract_user_info
def extract_user_info(instance):
return {
"id": instance.pk,
"name": instance.get_full_name(),
"photo": get_photo_or_gravatar_url(instance),
"big_photo": get_big_photo_or_gravatar_url(instance),
"username": instance.username,
}
示例4: change_slackhook
def change_slackhook(url, channel, notify_config, obj, change):
obj_type = _get_type(obj)
if not _check_notify_permission(notify_config, obj_type, 'change'):
return
template_change = loader.get_template('taiga_contrib_slack/change.jinja')
comment = re.sub(LINK_RE, _link_transform, change.comment)
context = Context({"obj": obj, "obj_type": obj_type, "change": change, "comment": comment})
change_text = template_change.render(context)
data = {"text": change_text.strip()}
data['attachments'] = []
if channel:
data["channel"] = channel
# Get markdown fields
if change.diff:
template_field = loader.get_template('taiga_contrib_slack/field-diff.jinja')
included_fields = ["description", "content", "blocked_note"]
for field_name, values in change.diff.items():
if field_name in included_fields:
attachment = _markdown_field_to_attachment(template_field, field_name, values)
data['attachments'].append(attachment)
# Get rest of fields
if change.values_diff:
template_field = loader.get_template('taiga_contrib_slack/field-diff.jinja')
excluded_fields = ["description_diff", "description_html", "content_diff",
"content_html", "blocked_note_diff", "blocked_note_html",
"backlog_order", "kanban_order", "taskboard_order", "us_order",
"finish_date", "is_closed"]
for field_name, values in change.values_diff.items():
if field_name in excluded_fields:
continue
attachment = _field_to_attachment(template_field, field_name, values)
if attachment:
data['attachments'].append(attachment)
data["username"] = "{} ({})".format(getattr(settings, "SLACKHOOKS_USERNAME", "Taiga"), change.user['name'])
try:
user = User.objects.get(pk=change.user['pk'])
data["icon_url"] = get_photo_or_gravatar_url(user)
if not data["icon_url"].startswith("http"):
data["icon_url"] = "https:{}".format(data["icon_url"])
except User.DoesNotExist:
data["icon_url"] = getattr(settings, "SLACKHOOKS_ICON", "https://tree.taiga.io/images/favicon.png")
_send_request(url, data)
示例5: get_user
def get_user(self, entry):
user = {"pk": None, "username": None, "name": None, "photo": None, "is_active": False}
user.update(entry.user)
user["photo"] = get_photo_or_gravatar_url(entry.owner)
user["is_active"] = entry.owner.is_active
if entry.owner.is_active or entry.owner.is_system:
user["name"] = entry.owner.get_full_name()
user["username"] = entry.owner.username
return user
示例6: test_slackhook
def test_slackhook(url, channel):
data = {
"text": "Test slack message",
}
if channel:
data["channel"] = channel
data["username"] = getattr(settings, "SLACKHOOKS_USERNAME", "Taiga")
try:
user = User.objects.get(pk=change.user['pk'])
data["icon_url"] = get_photo_or_gravatar_url(user)
except User.DoesNotExist:
data["icon_url"] = getattr(settings, "SLACKHOOKS_ICON", "https://tree.taiga.io/images/favicon.png")
_send_request(url, data)
示例7: create_slackhook
def create_slackhook(url, channel, notify_config, obj):
obj_type = _get_type(obj)
if not _check_notify_permission(notify_config, obj_type, 'create'):
return
template = loader.get_template('taiga_contrib_slack/create.jinja')
context = Context({"obj": obj, "obj_type": obj_type})
data = {
"text": template.render(context.flatten()),
"attachments": [{
"color": "good",
"fields": [{
"title": "Creator",
"value": obj.owner.get_full_name(),
"short": True,
}]
}]
}
if obj_type == "wikipage":
# For wikipages
content = getattr(obj, 'content', '-')
if content:
data["attachments"][0]["fields"].append({
"title": "Content",
"value": content,
"short": False,
})
else:
# For stories, tasks and issues
description = getattr(obj, 'description', '-')
if description:
data["attachments"][0]["fields"].append({
"title": "Description",
"value": description,
"short": False,
})
if channel:
data["channel"] = channel
data["username"] = "{} ({})".format(getattr(settings, "SLACKHOOKS_USERNAME", "Taiga"), obj.owner.get_full_name())
data["icon_url"] = get_photo_or_gravatar_url(obj.owner)
if not data["icon_url"].startswith("http"):
data["icon_url"] = "https:{}".format(data["icon_url"])
_send_request(url, data)
示例8: to_native
def to_native(self, obj):
#Updates the data user info saved if the user exists
User = apps.get_model("users", "User")
userData = obj.get("user", None)
if userData:
try:
user = User.objects.get(id=userData["id"])
obj["user"] = {
"id": user.pk,
"name": user.get_full_name(),
"photo": get_photo_or_gravatar_url(user),
"big_photo": get_big_photo_or_gravatar_url(user),
"username": user.username,
}
except User.DoesNotExist:
pass
return obj
示例9: get_data
def get_data(self, obj):
#Updates the data user info saved if the user exists
if hasattr(obj, "_prefetched_user"):
user = obj._prefetched_user
else:
User = apps.get_model("users", "User")
userData = obj.data.get("user", None)
try:
user = User.objects.get(id=userData["id"])
except User.DoesNotExist:
user = None
if user is not None:
obj.data["user"] = {
"id": user.pk,
"name": user.get_full_name(),
"photo": get_photo_or_gravatar_url(user),
"big_photo": get_big_photo_or_gravatar_url(user),
"username": user.username,
"is_profile_visible": user.is_active and not user.is_system,
"date_joined": user.date_joined
}
return obj.data
示例10: get_photo
def get_photo(self, membership):
return get_photo_or_gravatar_url(membership.user)
示例11: get_photo
def get_photo(self, obj):
return get_photo_or_gravatar_url(obj)