Usercreated column in AppEngine - google-app-engine

Imagine you have a column called
usercreated = db.ReferenceProperty(User)
And you want this field to automaticly filled when first putted to store. Like this did for auto_date. Is this possible?

The User property type has an auto_current_user flag, which is an easy solution if your using google accounts for authentication.
http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#UserProperty

According to the docs, your best bet is going to be a redefinition of the property class you're working with in order to override the default_value() method. You could also try duckpunching, though it's probably not a viable option.

Related

External access settings for Office 365 groups

I'm trying to update GroupSettings of individual O365 Group, however I always get error
Resource 'guid' does not exist or one of its queried reference-property objects are not present.
A code I'm using to update the group settings
var graphResult = graphClient.GroupSettings[guid].Request().UpdateAsync(groupSetting).GetAwaiter().GetResult();
I've tried to use Group guid as well as GroupSettings guid, none of that worked.
I can set the settings for the first time (overwrite defaults) using codde below, but update doesn't work afterwards.
graphResult = graphClient.Groups[guid].Settings.Request().AddAsync(groupSetting).GetAwaiter().GetResult();
Any idea what can be wrong please?
Thanks
You should use GroupSettings guid here.
I can repro your issue when I use an incorrect guid here.
You should firstly use GET https://graph.microsoft.com/v1.0/groupSettings to find the GroupSettings guid of the GroupSetting you want to update.
Please note that you should include all the values in the request body even though you don't want to update some of them.
Then you could put it as the guid in your code.
It's stronly recommended to have a quick test in Microsoft Graph Explorer.
Since documentation doesn't say how to update settings for particular group, here it is: you need to use both IDs in call
graphResult = graphClient.Groups[groupGuid].Settings[settingsGuid].Request().UpdateAsync(groupSetting)

SmartGWT mobile Record with SwitchItem

I am moderately new to SmartGWT and am trying to figure out how to have a RecordList where each record has the ability to have a SwitchItem attached to it. So basically create a list of selectable items, but those items also will have a SwitchItem on them to enable/disable some behavior.
Any thoughts on how I can accomplish this?
Looking at Record and RecordList it appears that Record extends HashMap and does nothing fancy like what I am wanting...but i wondered if it was possible to set the "description" property with perhaps some html string that creates the SwitchItem...is this way off? And if so...how is the best way to do this?
Use setShowRecordComponents() and createRecordComponent(). Documentation for how these work can be found in the core SmartGWT docs:
http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/grid/ListGrid.html#setShowRecordComponents%28java.lang.Boolean%29
There's no support for "recycle" mode yet. A sample is being created.

copy entity in entity framework?

For example I have a wpf window bound to an customer Entity (let suppose it's cus1). Then I load another entity from context :
customer cus2 = context.customers.where(x=>x.id=10).FirstOrDefault();
Now I want cus1 = cus2 ? I can do this way :
cus1.name = cus2.name;
cus1.address = cus2.address;
...
...
This way meets my case (the content of textboxs in the form change immediately into values of cus2) but I wonder if there is anyway to make it shorter since cus1=cus2 doesn't work ?
Thanks
You can use the memberwise Clone method to make a shallowcopy of a business object:
See http://msdn.microsoft.com/de-de/library/system.object.memberwiseclone.aspx
You could also use Serialization or Reflection, to do it on your own. However both oof the methods are slower then writing it directly.
Take a look at this article. Maybe you will find it helpful:
http://www.codeproject.com/KB/dotnet/CloningLINQ2Entities.aspx
Edit:
Btw. Remember, using using MemberwiseClone, in case of ReferenceTypes will effect in copying the references, not objects.
If you want to update the values of a Customer entity in memory with the newest values in the datastore you can use the Refresh method on your ObjectContext.
Here is the documentation.
In your case it would look like:
context.Refresh(RefreshMode.StoreWins, cus1);
If you really want to map two entities you could have a look at AutoMapper. AutoMapper will help you by automatically mapping entities to each other with a default setup that you can tweak to your needs.

CakePHP a class that can be used anywhere?

I have a multi-domain site. Depending on the domain the site needs to behave accordingly.
I created a helper called CompanyInfo it has methods such as name(), phone(), email(), etc.
Depending on what domain you are on it returns the correct information.
So for example if I need to display the phone number for a user to call I would use $this->CompanyInfo->phone() and it will display the correct phone number for the user depending on the domain.
Ok, this is all good, but not really relevant. The real issue is, I need this information in more than just the view. Helpers are just for views though. If I want to access this information from a controller I need to create a component to do it.
I really don't want to have a Helper and a Component doing the same thing. I would rather have one class handle it rather than copy and paste logic.
So whats the best way to have a class with methods that can be accessed from the controller or view or even model?
Is it just this kind of static information (name, phonenumber, email, etc) what you need to display? Why not just add them to your configuration in core.php?
Something like
# in core.php
Configuration::write('Company.name', 'Acme Corp.');
Configuration::write('Company.email', 'joe#acme.com');
You can then get this info anywhere you need using
Configuration::read('Company.name');
You can define this variable in your app_controller and then use these variable easily in any of your controller as set these variables from there only.
Call this function in your construct class.
i think that will solve your problem.
You can access model classes from any place this way :
$companyInfoModel = ClassRegistry::init('CompanyInfo');
$phone = $companyInfoModel->phone();
a) you can use libs in cake1.3 for that
b) static model methods which you can pass the content to and which will return the expected value
echo Model::phone($data)

Change type of Datastore field to Text from String?

I can't seem to do this. The list that the app engine datastore viewer does not contain Text as an option. I had to change my fields because some of my values were too long for String, but now I can't retroactively fix my old entries.
To change the property type used by the old entities, you need to manually update each of them.
This can be easily and efficiently accomplished using the mapper API. This guide explains how to use this API.
You may also want to read this blog post by Nick Johnson.
You don't have to fix your old entries. The old ones should work as is, and the new ones just won't be indexed.
See
http://groups.google.com/group/google-appengine/browse_thread/thread/282dc825f9c46684 .

Resources