def run(self, root): links = root.getiterator("a") for a in links: href = a.get("href", "") if SLUG_RE.search(href): # [wiki](wiki_page) -> <a href="FRONT_HOST/.../wiki/wiki_page" ... url = resolve("wiki", self.project.slug, href) a.set("href", url) a.set("class", "reference wiki") elif href and href[0] == "/": # [some link](/some/link) -> <a href="FRONT_HOST/some/link" ... url = "{}{}".format(resolve("home"), href[1:]) a.set("href", url)
def handleMatch(self, m): obj_ref = m.group(2) instance = get_instance_by_ref(self.project.id, obj_ref) if instance is None or instance.content_object is None: return "#{}".format(obj_ref) subject = instance.content_object.subject if instance.content_type.model == "epic": html_classes = "reference epic" elif instance.content_type.model == "userstory": html_classes = "reference user-story" elif instance.content_type.model == "task": html_classes = "reference task" elif instance.content_type.model == "issue": html_classes = "reference issue" else: return "#{}".format(obj_ref) url = resolve(instance.content_type.model, self.project.slug, obj_ref) link_text = "#{}".format(obj_ref) a = etree.Element('a') a.text = link_text a.set('href', url) a.set('title', "#{} {}".format(obj_ref, subject)) a.set('class', html_classes) self.md.extracted_data['references'].append(instance.content_object) return a
def run(self, root): home_url = resolve("home") links = root.getiterator("a") for a in links: href = a.get("href", "") url = a.get("href", "") if url.endswith("/"): url = url[:-1] if not url.startswith(home_url): a.set("target", "_blank")
def handleMatch(self, m): label = m.group(2).strip() url = resolve("wiki", self.project.slug, slugify(label)) if m.group(3): title = m.group(3).strip()[1:] else: title = label a = etree.Element("a") a.text = title a.set("href", url) a.set("title", title) a.set("class", "reference wiki") return a
def emit_live_notification_for_model(obj, user, history, *, type: str = "change", channel: str = "events", sessionid: str = "not-existing"): """ Sends a model live notification to users. """ if obj._importing: return None content_type = get_typename_for_model_instance(obj) if content_type == "userstories.userstory": if history.type == HistoryType.create: title = _("User story created") url = resolve("userstory", obj.project.slug, obj.ref) elif history.type == HistoryType.change: title = _("User story changed") url = resolve("userstory", obj.project.slug, obj.ref) else: title = _("User story deleted") url = None body = _("US #{} - {}").format(obj.ref, obj.subject) elif content_type == "tasks.task": if history.type == HistoryType.create: title = _("Task created") url = resolve("task", obj.project.slug, obj.ref) elif history.type == HistoryType.change: title = _("Task changed") url = resolve("task", obj.project.slug, obj.ref) else: title = _("Task deleted") url = None body = _("Task #{} - {}").format(obj.ref, obj.subject) elif content_type == "issues.issue": if history.type == HistoryType.create: title = _("Issue created") url = resolve("issue", obj.project.slug, obj.ref) elif history.type == HistoryType.change: title = _("Issue changed") url = resolve("issue", obj.project.slug, obj.ref) else: title = _("Issue deleted") url = None body = _("Issue: #{} - {}").format(obj.ref, obj.subject) elif content_type == "wiki.wiki_page": if history.type == HistoryType.create: title = _("Wiki Page created") url = resolve("wiki", obj.project.slug, obj.slug) elif history.type == HistoryType.change: title = _("Wiki Page changed") url = resolve("wiki", obj.project.slug, obj.slug) else: title = _("Wiki Page deleted") url = None body = _("Wiki Page: {}").format(obj.slug) elif content_type == "milestones.milestone": if history.type == HistoryType.create: title = _("Sprint created") url = resolve("taskboard", obj.project.slug, obj.slug) elif history.type == HistoryType.change: title = _("Sprint changed") url = resolve("taskboard", obj.project.slug, obj.slug) else: title = _("Sprint deleted") url = None body = _("Sprint: {}").format(obj.name) else: return None return emit_event( { "title": title, "body": "Project: {}\n{}".format(obj.project.name, body), "url": url, "timeout": 10000, "id": history.id }, "live_notifications.{}".format(user.id), sessionid=sessionid)
def location(self, obj): return resolve("wiki", obj.project.slug, obj.slug)
def location(self, obj): return resolve("epic", obj.project.slug, obj.ref)
def location(self, obj): return resolve("user", obj.username)
def location(self, obj): return resolve("kanban", obj.slug)
def location(self, obj): return resolve("backlog", obj.slug)
def location(self, obj): return resolve("project", obj.slug)
def location(self, obj): return resolve(obj["url_key"])
def location(self, obj): return resolve("userstory", obj.project.slug, obj.ref)
def location(self, obj): return resolve("taskboard", obj.project.slug, obj.slug)