def __init__(self, *args, **kwargs): super(JIRAOptionsForm, self).__init__(*args, **kwargs) initial = kwargs.get("initial") if initial: # make a connection to JIRA to fetch a default project. jira = JIRAClient(initial.get("instance_url"), initial.get("username"), initial.get("password")) projects = jira.get_projects_list() if projects: project_choices = [(p.get('key'), "%s (%s)" % (p.get('name'), p.get('key'))) for p in projects] self.fields["default_project"].choices = project_choices else: del self.fields["default_project"] else: del self.fields["default_project"]
def __init__(self, *args, **kwargs): super(JIRAOptionsForm, self).__init__(*args, **kwargs) initial = kwargs.get("initial") project_safe = False if initial: # make a connection to JIRA to fetch a default project. jira = JIRAClient(initial.get("instance_url"), initial.get("username"), initial.get("password")) projects_response = jira.get_projects_list() if projects_response.status_code == 200: projects = projects_response.json if projects: project_choices = [(p.get('key'), "%s (%s)" % (p.get('name'), p.get('key'))) for p in projects] project_safe = True self.fields["default_project"].choices = project_choices if not project_safe: del self.fields["default_project"] del self.fields["ignored_fields"]
def __init__(self, *args, **kwargs): super(JIRAOptionsForm, self).__init__(*args, **kwargs) initial = kwargs.get("initial") project_safe = False if initial: # make a connection to JIRA to fetch a default project. jira = JIRAClient(initial.get("instance_url"), initial.get("username"), initial.get("password")) projects_response = jira.get_projects_list() if projects_response.status_code == 200: projects = projects_response.json if projects: project_choices = [ (p.get('key'), "%s (%s)" % (p.get('name'), p.get('key'))) for p in projects ] project_safe = True self.fields["default_project"].choices = project_choices if not project_safe: del self.fields["default_project"] del self.fields["ignored_fields"]