I'm trying to declare a custom parser but I'm getting an error.
NoneType' object has no attribute '__getitem__'
(<type 'exceptions.TypeError'>, TypeError("'NoneType' object has no attribute '__getitem__'",), <traceback object at 0xc336234>)".
Here's my code:
class print_task1(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context=None):
super(print_task1, self).__init__(cr, uid, name, context=context)
report_sxw.report_sxw('report.dp_report_2','project.task','addons/exelixir_project/report/dp_report_2_1.mako',parser=print_task1,header="purchase_rep_webk_headq").
Can anyone explain what the problem is?
Try with this:
import time
from openerp.report import report_sxw
class print_task1(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context=None):
super(print_task1, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time
})
report_sxw.report_sxw('report.dp.report.2',
'project.task',
'addons/exelixir_project/report/dp_report_2_1.mako',
parser=print_task1,
header=header="purchase_rep_webk_headq")
If still not working than please check report tag (name attribute) just compare with dp.report.2 In .py side we need to add only report.report_name
Related
The following is a snippet of my code. When I tried running this, the error states that 'self' is not defined. I copied this code online because I don't really know how to use the function user_data_dir. I know that it works (I'm using Windows to write this) with just store = JsonStore('user.json') but I've been reading that using the function user_data_dir would be useful because it is a general function that creates a writeable path for various systems. Would be great if someone could help explain this!
from kivy.storage.jsonstore import JsonStore
from os.path import join
data_dir = getattr(self, 'user_data_dir')
store = JsonStore(join(data_dir,'user.json'))
class Welcome(Screen):
pass
data_dir = getattr(self, 'user_data_dir')
When you copied this line, it was somewhere inside some class's function:
class Some:
def func(self):
data_dir = getattr(self, 'user_data_dir')
Method located inside class in Python receives self as first parameter.
But not every object has user_data_dir attribute: as inclement noticed above it's App objects attribute. You should do something like:
class MyApp(App):
def build(self):
data_dir = getattr(self, 'user_data_dir')
store = JsonStore(join(data_dir,'user.json'))
# ...
Upd:
You can store path to json file inside app class and access to app instance to get this path with App.get_running_app():
class MyApp(App):
#property # see https://www.programiz.com/python-programming/property
def storage(self):
return join(self.user_data_dir, 'user.json')
and later in any place you want:
class SomeClass():
def some_func(self):
print('here\'s our storage:', App.get_running_app().storage)
I had one custom parser rule in which I had defined all my keywords such as _self, _for, _loop etc. Because of this, if I type _s and click Ctrl+ space bar, it shows _self.But what I required is even though I type self or SE, it should auto assign as _self.Is it possible? If so, could anyone please suggest a solution for this. Thanks in advance
There are multiple things to be payed attention to
There needs to be a proposal and only one proposal. Otherwise the user has to select the prosal to be applied and no auto insert takes places
Proposals are created based on the error recovery and so you might not get the proposal you are looking for at all
so lets assume you have a grammar like
Model:
greetings+=Greeting*;
Greeting:
'_self' name=ID '!';
and a model file like
SE
Then the error recovery will work fine an a proposal of "_self" will be added to the list of proposals
Proposals are Filtered based on the current prefix in the model. that would be the place you could start customizing.
e.g. this very naive impl
import org.eclipse.xtext.ui.editor.contentassist.FQNPrefixMatcher;
public class MyPrefixMatcher extends FQNPrefixMatcher {
#Override
public boolean isCandidateMatchingPrefix(String name, String prefix) {
return super.isCandidateMatchingPrefix(name, prefix) || super.isCandidateMatchingPrefix(name, "_" + prefix);
}
}
and dont forget to bind
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher
import org.xtext.example.mydsl4.ui.contentassist.MyPrefixMatcher
#FinalFieldsConstructor
class MyDslUiModule extends AbstractMyDslUiModule {
override Class<? extends PrefixMatcher> bindPrefixMatcher() {
return MyPrefixMatcher;
}
}
There is another feature that does not use proposals at all but the text that is actually typed and if it recognizes something then can replace it with something else. this feature is called "Auto Edit". The extension point in xtext for this is IAutoEditStrategy / AbstractEditStrategyProvider
I have rule like this in my grammar:
`CLASS: 'extends' '=' superClass=[CLASS];`
As You can see my class don't have any name like name=ID and I would like to reference by a file name that contains CLASS declaration. To achieve this I created custom QualifiedNameProvider that extends DefaultDeclarativeQualifiedNameProviderwith:
def QualifiedName qualifiedName(CLASSDeclaration cd) {
var fileName = ???????
return QualifiedName::create(fileName)
}
This works fine when I'm returning hardcoded string but I don't know how to obtain file name where a class is defined.
Thanks for ideas
You can use the eResource of an EObject to get an URI that you can process to get a file name. Please note: [Class] is short for [Class|ID] which means that a ID is parsed.
If you want to allow a dot for the file name there you may need something like [Class|FQN]
And you may useIQualifiedNameConverter
To create the qualified name
In my Jira project I have a custom field called "CASE-Environment". Its a Select List(Multiple values)
I would like this custom field to have values dynamically populated. In my actual project, I am making use of RESTFul calls wherein I get the actual values from an internal RESTFul service. But for demo purposes I am showing the values here as hard coded via an initializer.
I am making use of the Script Runner Jira plugin which lets me define behaviors, associate it with fields. I have the following in the initializer section of the behavior.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
Map fieldOptions = [:]
fieldOptions.put("-1","None")
fieldOptions.put("100","Dev");
fieldOptions.put("101","Staging");
fieldOptions.put("102","QA");
fieldOptions.put("103","Production");
FormField env = getFieldByName("CASE-Environment");
env.setFieldOptions(fieldOptions)
I am successfully able to see this values on the UI when I am trying to create an issue.
But when I am trying to submit the issue, I hit a Jira validation error message which reads as below
Invalid value '102' passed for customfield 'CASE-Environment'
I am guessing that Jira somehow is not recognizing the dynamically added option values for my SelectList [ multiple values ]
I even tried building a mapping for this field wherein my behavior would get triggered everytime the custom field CASE-Environment under went changes.
The mapping code is shown as below :
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.customfields.option.Option
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
def adddOption = {
Issue issue,
CustomField customField,
String value ->
Options l = ComponentAccessor.getOptionsManager().getOptions(customField.getRelevantConfig(issue))
int nextSequence = l.isEmpty() ? 1 : l.getRootOptions().size() + 1;
Option newOption = ComponentAccessor.getOptionsManager().createOption(customField.getRelevantConfig(issue), null, (Long)nextSequence, value);
return newOption;
}
FormField environment = getFieldById(fieldChanged)
Issue issue = getUnderlyingIssue()
MutableIssue mutableIssue = ComponentAccessor.getIssueManager().getIssueObject(issue.id);
CustomField field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("CASE-Environment")
List<Option> allOptions = new LinkedList<>();
List<String> chosenValues = (List<String>) mutableIssue.getCustomFieldValue(field);
for (String eachValue : chosenValues) {
allOptions.add(adddOption(issue, field, eachValue));
}
mutableIssue.setCustomFieldValue(field, allOptions);
But even after this I still can't get past the error message. Can someone please help me with getting this sorted out ?
For what its worth, I am using Jira : JIRA v6.3.5
So after toying around for quite sometime on this, I finally managed to crack this on my own.
The below mentioned initializer section should help get this sorted out easily.
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.getOptionsManager()
def fieldManager = ComponentAccessor.getCustomFieldManager()
def envFld = fieldManager.getCustomFieldObjectByName("CASE-Environment")
def fieldConfig = envFld.getRelevantConfig(getIssueContext())
def newSeqId = 0
//For the sake of e.g., I am using a initialized array. In real life one can
// construct this by querying a DB or hitting a RestFul service etc.,
def envs = ["QA", "Staging", "Dev", "Production"]
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
for (String env : envs) {
def option = optionsManager.createOption(fieldConfig, null, newSeqId++, env)
issueInputParameters.addCustomFieldValue(envFld.idAsLong, option.optionId.toString())
}
Thanks #Krishan
just one comment, new JIRA 7/ScriptRunner have problem with static type check. Replace the definition of "newSeqID"
def newSeqId = 0
with
Long newSeqId = 0
I am trying to use a NumericProperty but getting Type errors when trying to use it as a value
My code looks like this
from kivy.properties import NumericProperty
from kivy.uix.widget import Widget
class Segment(Widget):
def __init__(self, segments):
super(Segment, self).__init__()
self.segments = NumericPropery(segments)
def build(self):
for i in range(0, self.segments):
# Do something
I get an error :
for i in range(0, self.segments):
TypeError: range() integer end argument expected, got kivy.properties.NumericProperty.
so I tried using self.segments.get() instead, but then I got this error
TypeError: get() takes exactly one argument (0 given)
apperently the get function expects <kivy._event.EventDispatcher> object argument
Any idea how to get around this?
I had a similar problem with this code ...
class GameModel(object):
some_number = NumericProperty(1)
def __init__(self):
self.some_number = 2
... which raised the error:
TypeError: Argument 'obj' has incorrect type (expected kivy._event.EventDispatcher, got GameModel)
I did declare the property at class level though. In my case the problem was that the class itself was not derived from a Kivy Widget class or - as stated in the error message - from an EventDispatcher Object
Deriving from EventDispatcher fixed my problem:
class GameModel(EventDispatcher):
Hope this is helpful for someone else some day ;-)
You have to declare properties at class level.
class Segment(Widget):
segments = NumericProperty()
This will give the correct behaviour. The problem is that properties do their own management of per-instance values and interacting with the eventloop etc.. If you don't declare them at class level, they don't get to do this, so your functions only see the NumericProperty itself (which is your problem).