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")
Exemple #3
0
 def location(self, obj):
     return resolve("issue", obj.project.slug, obj.ref)
Exemple #4
0
 def location(self, obj):
     return resolve("wiki", obj.project.slug, obj.slug)
Exemple #5
0
 def location(self, obj):
     return resolve("taskboard", obj.project.slug, obj.slug)
Exemple #6
0
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
    )
Exemple #7
0
 def location(self, obj):
     return resolve(obj["url_key"])
Exemple #8
0
 def location(self, obj):
     return resolve("userstory", obj.project.slug, obj.ref)