Merge pull request #2 from rev112/settings-extra-fields
Add an option to specify extra fields in settings
This commit is contained in:
commit
ccf4686515
|
@ -1,4 +1,5 @@
|
|||
from __future__ import absolute_import
|
||||
import json
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -17,6 +18,11 @@ class RedmineOptionsForm(forms.Form):
|
|||
label='Tracker', coerce=int)
|
||||
default_priority = forms.TypedChoiceField(
|
||||
label='Default Priority', coerce=int)
|
||||
extra_fields = forms.CharField(
|
||||
widget=forms.Textarea(attrs={'rows': 5, 'class': 'span9'}),
|
||||
help_text='Extra attributes (custom fields, status id, etc.) in JSON format',
|
||||
label='Extra Fields',
|
||||
required=False)
|
||||
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
super(RedmineOptionsForm, self).__init__(data=data, *args, **kwargs)
|
||||
|
@ -86,6 +92,24 @@ class RedmineOptionsForm(forms.Form):
|
|||
return url.rstrip('/')
|
||||
return url
|
||||
|
||||
def clean_extra_fields(self):
|
||||
"""
|
||||
Ensure that the value provided is either a valid JSON dictionary,
|
||||
or the empty string.
|
||||
"""
|
||||
extra_fields_json = self.cleaned_data.get('extra_fields').strip()
|
||||
if not extra_fields_json:
|
||||
return ''
|
||||
|
||||
try:
|
||||
extra_fields_dict = json.loads(extra_fields_json)
|
||||
except ValueError:
|
||||
raise forms.ValidationError('Invalid JSON specified')
|
||||
|
||||
if not isinstance(extra_fields_dict, dict):
|
||||
raise forms.ValidationError('JSON dictionary must be specified')
|
||||
return json.dumps(extra_fields_dict, indent=4)
|
||||
|
||||
|
||||
class RedmineNewIssueForm(forms.Form):
|
||||
title = forms.CharField(max_length=200, widget=forms.TextInput(attrs={'class': 'span9'}))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from __future__ import absolute_import
|
||||
import json
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -67,13 +68,22 @@ class RedminePlugin(IssuePlugin):
|
|||
if default_priority is None:
|
||||
default_priority = 4
|
||||
|
||||
response = client.create_issue({
|
||||
issue_dict = {
|
||||
'project_id': self.get_option('project_id', group.project),
|
||||
'tracker_id': self.get_option('tracker_id', group.project),
|
||||
'priority_id': default_priority,
|
||||
'subject': form_data['title'].encode('utf-8'),
|
||||
'description': form_data['description'].encode('utf-8'),
|
||||
})
|
||||
}
|
||||
|
||||
extra_fields_str = self.get_option('extra_fields', group.project)
|
||||
if extra_fields_str:
|
||||
extra_fields = json.loads(extra_fields_str)
|
||||
else:
|
||||
extra_fields = {}
|
||||
issue_dict.update(extra_fields)
|
||||
|
||||
response = client.create_issue(issue_dict)
|
||||
return response['issue']['id']
|
||||
|
||||
def get_issue_url(self, group, issue_id, **kwargs):
|
||||
|
|
Reference in New Issue