Corona Object Properties - ios4

I would like to find out if it is possible to get the custom properties of an object from its 2nd tier. An example is provided below which can be clearer than explaining in words.
objectA = display.newImage(...)
objectA.dmg = 100
objectA.firstBtn = display.newImage(...)
objectA.firstBtn.id = "firstBtn"
objectA.firstBtn:addEventListener("touch",touchHandler)
function touchHandler(event)
-- I want to get the dmg of objectA
-- I know that by calling event.target.id I can get "firstBtn"
-- but how do I get the dmg value like event.target.parent.dmg?
end
Thank you.

you cannot get the objectA.dmg in event.target even if you use event.target.parent you cannot get or access it. you can refer to this link you have similar question on why you can't access it

Related

How Can I Check For The Existence of a UUID

I am trying to check for the existence of a UUID as a primary key in my Django environment...and when it exists...my code works fine...But if it's not present I get a "" is not a Valid UUID...
Here's my code....
uuid_exists = Book.objects.filter(id=self.object.author_pk,is_active="True").first()
I've tried other variations of this with .exists() or .all()...but I keep getting the ['“” is not a valid UUID.'] error.
I did come up with a workaround....
if self.object.author_pk is not '':
book_exists = Book.objects.filter(id=self.object.author_pk,is_active="True").first()
context['author_exists'] = author_exists
Is this the best way to do this? I was hoping to be able to use a straight filter...without clarifying logic....But I've worked all afternoon and can't seem to come up with anything better. Thanks in advance for any feedback or comments.
I've had the same issue and this is what I have:
Wrapping it into try/except (in my case it's a View so it's supposed to return a Response object)
try:
object = Object.objects.get(id=object_id)
except Exception as e:
return Response(data={...}, status=status.HTTP_40...
It gets to the exception (4th line) but somehow sends '~your_id~' is not a valid UUID. text instead of proper data. Which might be enough in some cases.
This seems like an overlook, so might as well get a fix soon. I don't have enough time to investigate deeper, unfortunately.
So the solution I came up with is not ideal either but hopefully is a bit cleaner and faster than what you're using rn.
# Generate a list of possible object IDs (make use of filters in order to reduce the DB load)
possible_ids = [str(id) for id in Object.objects.filter(~ filters here ~).values_list('id', flat=True)]
# Return an error if ID is not valid
if ~your_id~ not in possible_ids:
return Response(data={"error": "Database destruction sequence initialized!"}, status=status.HTTP_401_UNAUTHORIZED)
# Keep working with the object
object = Objects.objects.get(id=object_id)

Calling methods dynamically, but not from a custom class

I'm trying to create a simple loop that prints out all available values of dir("Hello") side by side with the help("Hello".xxx) for each dir returned.
I've seen a number of stackoverflow threads on calling functions dynamically from a custom class, but it's not so clear how I can loop through built-in methods.
Taking this as an example:
for dr in dir("Hello"):
Using 'format' converts the "Hello.%d" % dr into a string of "hello.upper", but the print(help('hello.upper')) fails, because the help function expects "hello".upper, not "hello.upper":
for dr in dir("Hello"):
print(dr)
print(help("Hello.%d" % dr))
I've tried researching getattr, but the help function is not a method of the string, so getattr("Hello", "help")("upper") isn't working either.
expected results are:
dir value (followed by:)
dir help output
help doesn't return a string, it opens an interactive viewer for reading the help page.
To view each of these pages for some object (warning: there are going to be a lot of these pages), you can use getattr to get the attribute of the object given its name
obj = "Hello"
for attr_name in dir(obj):
help(getattr(obj, attr_name))

Bind list value in ArangoDB query

I'm facing some issues when trying to bind a list variable in an ArangoDB query. More concretely, the list might look like as follows and comes from a URL parameter in a certain Foxx controller endpoint:
.../someAPIEndpoint?list=A,B,C,D
I would like to be able to do something like this:
stmt = db._createStatement({query: "for i in [#list] return i"});
stmt.bind('list', req.params('list').split(','));
Since I do not know how many values will I receive from the API call, I can't create n bindings for each possible one. Is what I want to achieve even possible?
Thanks in advance.
you were almost there, you can bind an array directly to the parameter (i just removed "[" and "]" from your query:
stmt = db._createStatement({query: "for i in #list return i"});
stmt.bind('list', req.params('list').split(','));

Sitecore 7 Search, cannot access a disposed object

I've been working with some Sitecore 7 search code. Example below.
using (var context = Index.CreateSearchContext())
{
// ....Build predicates
var query = context.GetQueryable<SearchResultItem>().Where(predicate);
return query.GetResults();
}
This works fine in SOLR, but when used with standard Lucene, whenever I reference a property in the SearchResults<SearchResultItem> returned by GetResults(), Sitecore errors with "Cannot access a disposed object". It appears that GetResults() doesn't enumerate and still hangs on to the searchcontext.
Anyone come across this before and know how to fix? I've seen some articles suggesting having the SearchContext in application state, but ideally I want to avoid this.
Thanks
Ian
It seems that SearchResults<T> holds reference to SearchHit and the LuceneSearchProvider doesn't hold a reader open. The new version of Lucene automatically closes the reader. I think you might be returning the wrong type. You should probably do like this:
var query = context.GetQueryable<SearchResultItem>().Where(predicate);
return query.ToList();
However make sure, that don't return too many. You should probably use take() etc.
Is GetResults() returning a List or IEnumerable/IQueryable?
Try to return a list in case it isn't already.
return query.GetResults().ToList();
Cheers

sharepoint - add custom column to list via object model

I'm having trouble figuring out how to add a custom column type to a list with the object model.
SPFieldCollection.Add() has a parameter SPFieldType, but that must be one of the enumerated values in the Microsoft.SharePoint.SPFieldType enumeration, thus it cannot be used to create columns of a custom type.
I next attempted using SPFieldCollection.CreateNewField() but when I call SPField.Update() on the returned value I get an exception: "ArgumentException was unhandled. Value does not fall within the expected range.".
I see a reference to SPFieldCollection.AddFieldAsXml() here: How do I add custom column to existing WSS list template but there's hardly any info and I'm not sure that's the right track to take.
UPDATE: I found a post on AddFieldAsXml: http://weblogs.asp.net/bsimser/archive/2005/07/21/420147.aspx and it turns out it's very easy and worked well for me. Posting anyway in hopes it will help someone else.
SPFieldCollection.AddFieldAsXml() is the way to go as far as I can tell. See here for an example: http://weblogs.asp.net/bsimser/archive/2005/07/21/420147.aspx
Try with:
SPField newField = null;
newField= web.Fields.CreateNewField("MyFieldTypeName", fieldName);
web.Fields.Add(newField);
newField = web.Fields[fieldName];
// set some properties
newField.ShowInDisplayForm = false;
newField.ShowInViewForms = true;
newField.Update();

Resources