Exemple #1
0
 def view_ajax(self, request, group, **kwargs):
     if request.GET.get('action', '') != 'lists':
         return JSONResponse({})
     board_id = request.GET['board_id']
     trello = self.get_client(group.project)
     lists = trello.get_board_list(board_id, fields='name')
     return JSONResponse({'result': lists})
Exemple #2
0
    def view(self, request, group, **kwargs):
        op = request.GET.get("op")
        # TODO(dcramer): add caching
        if op == "getTaskLists":
            project_id = request.GET.get("pid")
            if not project_id:
                return HttpResponse(status=400)

            client = self.get_client(group.project)
            task_list = client.list_tasklists(project_id)
            return JSONResponse([{"id": i["id"], "text": i["name"]} for i in task_list])

        return super(TeamworkPlugin, self).view(request, group, **kwargs)
Exemple #3
0
 def view(self, request, group, **kwargs):
     if request.is_ajax():
         view = self.view_ajax
     else:
         view = super(TrelloCard, self).view
     try:
         return view(request, group, **kwargs)
     except TrelloError as e:
         if request.is_ajax():
             return JSONResponse({})
         return self.render(self.plugin_misconfigured_template, {
             'text': e.text,
             'title': self.get_new_issue_title(),
         })
Exemple #4
0
 def _get_all_users_for_project(self, client, project):
     users = []
     for user in client.get_users_for_project(project).json:
         users.append({
             'value':
             user['name'],
             'display':
             '%s - %s (%s)' %
             (user['displayName'], user['emailAddress'], user['name']),
             'needsRender':
             True,
             'q':
             '',
         })
     return JSONResponse({'users': users})
Exemple #5
0
    def view(self, request, group, **kwargs):
        op = request.GET.get('op')
        # TODO(dcramer): add caching
        if op == 'getTaskLists':
            project_id = request.GET.get('pid')
            if not project_id:
                return HttpResponse(status=400)

            client = self.get_client(group.project)
            task_list = client.list_tasklists(project_id)
            return JSONResponse([{
                'id': i['id'],
                'text': i['name']
            } for i in task_list])

        return super(TeamworkTaskPlugin, self).view(request, group, **kwargs)
Exemple #6
0
    def handle_user_autocomplete(self, request, group, **kwargs):
        """
        Auto-complete JSON handler, Tries to handle multiple different types of
        response from JIRA as only some of their backend is moved over to use
        the JSON REST API, some of the responses come back in XML format and
        pre-rendered HTML.
        """

        url = urllib.unquote_plus(request.GET.get("user_autocomplete"))
        parsed = list(urlparse.urlsplit(url))
        query = urlparse.parse_qs(parsed[3])
        q = request.GET.get('q')

        jira_client = self.get_jira_client(group.project)

        project = self.get_option('default_project', group.project)
        # shortcut case for no input since JIRA's API doesn't return all users
        if q == '':
            return self._get_all_users_for_project(jira_client, project)

        if "/rest/api/latest/user/" in url:  # its the JSON version of the autocompleter
            isXML = False
            query["username"] = q
            query.pop(
                'issueKey',
                False)  # some reason JIRA complains if this key is in the URL.
            query["project"] = project
        else:  # its the stupid XML version of the API.
            isXML = True
            query["query"] = q
            if query.get('fieldName'):
                query["fieldName"] = query["fieldName"][
                    0]  # for some reason its a list.

        parsed[3] = urllib.urlencode(query)
        final_url = urlparse.urlunsplit(parsed)

        autocomplete_response = jira_client.get_cached(final_url)
        users = []

        if isXML:
            for userxml in autocomplete_response.xml.findAll("users"):
                users.append({
                    'value': userxml.find("name").text,
                    'display': userxml.find("html").text,
                    'needsRender': False,
                    'q': q,
                })
        else:
            for user in autocomplete_response.json:
                users.append({
                    'value':
                    user["name"],
                    'display':
                    "%s - %s (%s)" %
                    (user["displayName"], user["emailAddress"], user["name"]),
                    'needsRender':
                    True,
                    'q':
                    q,
                })

        return JSONResponse({'users': users})