http://django-rest-framework.org/api-guide/relations.html#primarykeyrelatedfield
I am trying to write to a PrimaryKeyRelatedField() and, although a 200 status is returned, an empty value is being input for the field in question, rather than multiple values.
$.ajax({url:'<MY MODELVIEWSET>/<ID>', type:'PUT', data:{'field1':'xyz', <FIELD IN QUESTION WITH PrimaryKeyRelatedField(many=True)>:[1,2,3]}})
--> Updated field is empty
Updates are successful and correct when only one value is given for this field.
$.ajax({url:'<MY MODELVIEWSET>/<ID>', type:'PUT', data:{'field1':'xyz', <FIELD IN QUESTION WITH PrimaryKeyRelatedField(many=True)>:1}})
--> Updates correctly
You need to set traditional to true so jquery will encode the params that contains arrays in a way that django will understand:
$.ajax({
url:'<MY MODELVIEWSET>/<ID>',
type:'PUT',
traditional: true,
data:{field1:'xyz', field2:[1,2,3]}
})
See here for the difference between default and traditional encoding.
Related
How to get droplink and treelist values in sitecore search .
Below are my code and config file . But when i am searching based on droplink and treelist value its not coming in search result .
var fquery = new FullTextQuery(search);
SearchHits searchHits = sc.Search(fquery, int.MaxValue);
return searchHits.FetchResults(0, int.MaxValue).Select(r => r.GetObject()).ToList();
config file entry .
I am not sure if i have to parse them or something else . Looking forward for help.
You don't say which version of Sitecore you're using, but speaking as someone who works with v6.6:
ID-based fields, like TreeList store GUIDs in the Sitecore database. At index time, Sitecore parses these into ShortID format and forces it to lower case. So the Lucene index entry actually contains a lowercase GUID with no curly braces or hyphens.
Chances are, your text-based query is not going to contain text that will match this.
I tend to use a Term based BooleanQuery object to match ID-based fields. Something like:
BooleanQuery query = new BooleanQuery();
query.Add(new TermQuery(new Term("myfieldname", ShortID.Encode(myGuidToMatch).ToLowerInvariant())), BooleanClause.Occur.MUST);
Note that the field name you want to query should be in lower case, as Sitecore / Lucene generally works in lower case.
You may find the code and UI example in this blog post helpful to see an example of building queries against ID-based fields:
http://jermdavis.wordpress.com/2014/06/09/faceted-search-in-sitecore-6-6/
If you want to be able to match the values contained in these fields from a free text type of search box, then you will have to pre-process the values from these ID-based fields before they are indexed.
Sitecore and Lucene allow for the idea of "computed fields" in your index - basically you can configure the indexing process to run bits of your own code in order to process data at index time, and to create new Lucene index fields from the results of your code.
This blog post of mine gives an example of a computed field:
http://jermdavis.wordpress.com/2014/05/05/using-dms-profile-cards-as-search-metadata/
That example is not doing what you want - but it does talk about how you might configure one of these custom fields.
You'd probably want your custom field code to:
Get the raw value of the ID-based field
Load the item that this ID points to
Process that item to turn it into the pattern of text you want to be indexed
Return this text, to be saved into the computed field in Lucene
With that done, you should find that your index will contain the text associated with your ID field(s). And hence you should be able to match it with a text-based query.
-- EDITED TO ADD --
More detail on creating computed index items:
Sitecore 6.6 doesn't directly support computed fields in your Lucene indexes. To get them you can make use of the Advanced Database Crawler - which is part of the Sitecore SearchContrib project available on GitHub: https://github.com/sitecorian/SitecoreSearchContrib
There are assorted blog posts about on getting started with this code.
[NB: In Sitecore 7.x I believe this behaviour has migrated into the core of Sitecore. However I think they changed the names of stuff. Details of that are available via google - things like Upgrading sitecore 6.6 index configuration to sitecore 7 (using ComputedFields) for example]
The code for a dynamic field to turn something ID-based into text might look like:
public class IndexIDField : BaseDynamicField
{
public override string ResolveValue(Sitecore.Data.Items.Item item)
{
Field fld = item.Fields["FieldYouAreInterestedIn"];
if (fld != null && !string.IsNullOrWhiteSpace(fld.Value))
{
string[] ids = fld.Value.Split('|');
StringBuilder text = new StringBuilder();
foreach (string id in ids)
{
Item relatedItem = item.Database.GetItem(id);
if (relatedItem != null)
{
text.Append(relatedItem.DisplayName);
text.Append(" ");
}
}
return text.ToString();
}
return null;
}
}
This is extracting the appropriate field from the context item that's being passed in. If it exists and is not empty, it splits it by "|" to get a list of all the IDs stored in this field. Then for each one it tries to load it. Note use of the appropriate database specified by the input item - Sitecore.Context.Database will point to Core at this point, and you won't find your items there. Finally, if we get back a valid item from the ID, we append its display name to our text to be indexed. You could use other fields than Display Name - depending on what makes sense in your solution.
With that code added to your solution you need to ensure it's called at index build time. The default config for the Advanced Database Crawler includes a config element for dynamic fields. (And again, SC7.x will have something similar but I don't know the names off the top of my head) You need to add your type to the configuration for dynamic fields. Snipping out all the extraneous bits from the default config:
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/">
<sitecore>
<!-- snip -->
<search>
<!-- snip -->
<crawlers>
<demo type="scSearchContrib.Crawler.Crawlers.AdvancedDatabaseCrawler,scSearchContrib.Crawler">
<!-- snip -->
<dynamicFields hint="raw:AddDynamicFields">
<!-- snip -->
<dynamicField type="YourNamespace.IndexIDField,YourDLL" name="_myfieldname" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
</dynamicFields>
<!-- snip -->
</demo>
</crawlers>
</search>
</sitecore>
</configuration>
That sets up a new field called "_myfieldname" with sensible options for indexing text.
Rebuild your search index, and you should find your free text queries will match the appropriate items. Testing this basic setup on an instance of SC6.6, I get hits with some test data I happened to have lying around. If I search my computed column for "blue" I get only rows which were tagged with a metadata item that had "blue" in its name:
I want to realize the button on the current logon were not visible:
<group attrs="{'invisible': [('shenqr.user_id','=', uid)]}">
<button string="prove" name="fjj_action_prove" states="wait_prove"
groups="qingjia.group_assistant_depmanager" />
</group>
but it says the field shenqr.user_id cannot be found
while i use like this:
<field name="domain">[('shenqr.user_id','<>',uid)]</field>
it works.
what is the problems
You could not get it works in attrs, because it does not support. To make such things, you need to add fields on the current model
In attrs you can only pass OpenERP basic domain.
The domain is parsed by the Web client. That force you to have all fields used in domain in the view event if not shown, they must be invisible fields.
The domain value must be static.
attrs="{'readonly': [('my_filed_must_be_in_view', '=', 'static_value')]}"
You can not use complex function, or server related code the scope is limited to the view.
Domain
Normaly when you add a domain on a field using view definition you can use any kind of standard domain condition.
[('invoice.partner_id.name', '=', True)]
But you have to consider your self outside of system. It means you can only do domain that will work trough an XMLRPC call.
In the domain value you can use any static value or any field value. Once again if you want to use a field that is not shown as a value, it must be present in view even if invisible.
I do not think you can use context in domain value like in ir.action domain but I will not be categoric.
Regards
I'm newbie in Orbeon xforms, so I ask my questions here. I have REST webservice with some address (method GET) and I want to call him and the result should be provide to metadata of my form:
<!-- Main instance -->
<xforms:instance id="fr-form-instance">
<form>
<section-meta>
<resultOfMyRestWebservice/>
I've tried to follow this tutorial http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data (pull solution) but I don't know how I can put the result of rest in the marker: resultOfMyRestWebservice, and where I have to put the submission code:
<xforms:submission
id="load-data-submission"
method="get" serialization="none"
resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
replace="?" instance="?"/>
regards
If I were you I would use a temporary run-time instance to hold the results of your REST call and then use setvalue to populate your persisting instance.
The following example works if you define the structure of your meta-data in your model, so you can use setvalue to populate. Otherwise you can use insert.
Ie. In your xforms:model define:
<!-- Run-time instance to hold Service response -->
<xforms:instance id="fr-service-response-instance" xxforms:exclude-result-prefixes="#all">
<response/>
</xforms:instance>
Define your submission to replace this response instance:
<xforms:submission id="load-data-submission" method="get"
serialization="none" mediatype="application/xml"
resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
replace="instance" instance="fr-service-response-instance"/>
And then create an action to call the submission and populate your instance:
<!-- Populate Data
uses Load Data Submission
runs on form load -->
<xforms:action id="populate-data-binding">
<xforms:action ev:event="xforms-ready" ev:observer="fr-form-model" if="true()">
<xforms:send submission="load-data-submission"/>
</xforms:action>
<!-- Populate resultOfMyRestWebservice control with pathToResults value
following successful submission -->
<xforms:action ev:event="xforms-submit-done" ev:observer="load-data-submission"
context="instance('fr-service-response-instance')">
<xforms:action>
<xf:var name="control-name" value="'resultOfMyRestWebservice'" as="xs:string"/>
<xf:var name="control-value" value="/pathToResults" as="xs:string"/>
<xforms:setvalue ref="instance('fr-form-instance')/*/*[name() = $control-name]"
value="$control-value"/>
</xforms:action>
</xforms:action>
</xforms:action>
Note pathToResults is the xpath to the value you want from the results.
I do everything like in mentioned tutorial: http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data I mean:
....
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<!-- User in which user data is collected -->
<xf:instance id="user-data">
<registration>
<first-name/>
<last-name/>
</registration>
</xf:instance>
<!-- Load initial data from a service -->
<xf:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
<xf:submission id="load-data-submission" method="get" serialization="none"
resource="http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml"
replace="instance"
instance="user-data"/>
<!-- Main instance -->
<xf:instance id="fr-form-instance">
<form>
<name/>
....
....
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel"
xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline">
....
<xforms:action ev:event="xforms-enabled">
<xforms:setvalue ref="xxf:instance('fr-form-instance')/name"
value="xxf:instance('user-data')/first-name"/>
</xforms:action>
</fr:body>
....
I want to get xml from link (http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml), put in to the 'user-data' instance and then get the first-name and put to the 'name' marker in the 'fr-form-instance'. Unfortunately it does not working, I mean setvalue not working, because when I change 'user-instance' like that:
<xf:instance id="user-data">
<registration>
<first-name>SomeName</first-name>
<last-name/>
</registration>
</xf:instance>
it working, and the final xml look like:
....
<name>SomeName</name>
....
I really haven't idea why it doesn't working.
regards
///
Now I see that my problem may be reduced to:
It works:
<xforms:instance id="user-data" src="http://example.org/service/load-initial-form-data-pull-instance"/>
And it does not work:
<xforms:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
<xforms:submission id="load-data-submission"
method="get" serialization="none"
resource="http://example.org/service/load-initial-form-data-pull-instance"
replace="instance" instance="user-data"/>
I have to use second way, because I have to pass some parameter to resource (resource="http.../{xxforms:get-request-parameter('myParam')}")
I'm using a ColdFusion autosuggest for my UserID field. When a user starts to type in a UserID, a list of user ids and the user names associated with it pop up (populated by a cfc function). Sample code:
<cfinput name="userID" type="text" value="#userID#" autoSuggest="cfc:Utilities.suggestUser({cfautosuggestvalue})" matchcontains="true" />
The suggestions are listed in the format "User Name <userID>". So if the user would start typing 123, a sample suggestion that would pop up would be "Harvey Mann <1234>".
The problem is that if the user chooses that suggestion, I don't want to insert the whole suggested text into the input field - I just want to insert the user id ("1234" in this case). I would also like to be able to insert the user name ("Harvey Mann") into an adjacent field/area if possible. Is there any way to accomplish this?
Since you are using CF's built-in implementation of autosuggest, you are stuck with only having access to one returned value. Thus if the value consists of mutliple 'parts' and you want to insert different 'parts' of the value into different columns, you will have to parse the value and extract appropriate parts from the string. In your example case you could treat the value as a list delimited by <. In this case you can get the name 'part' with
trim(listfirst(form.userID, "<"))
and the id 'part' with
replace(listlast(form.userID, "<"), ">", "")
Alternatively, you can always use jQuery UI Autocomplete implementation - you'll have to write your own javascript for it, but it gives you far more control than the built-in cf's implementation. Check jQuery UI docs for more info: http://jqueryui.com/demos/autocomplete/
UPDATE:
On second thought, if you just want to display selected value's 'name' part in another area on the same page, you may be able to do it using just CF's built-in autosuggest and a bit of javascript. Try adding this code to the HEAD section of your page:
<cfajaxproxy bind="javaScript:showName({userID})">
<script type="text/javascript">
showName = function(strUserId) {
document.getElementById("someID").innerHTML = strUserId.split('<')[0];
}
</script>
I have a custom field (fixedInVersion), the field is required when state = 'Closed'.
I also have a custom control for the field (combo with sorting, because the default sorting of TFS control is ascending).
When the work Item state is Closed, I display in my control Required but the user can still save the work item without getting error.
Does anyone knows what is the problem?
If I remove the text Required the item cannot be saved, but the only indication for the user is that the combo is yellow (no text Required is displayed).
The "When" Required value, did you use it? see the following example:
<FieldDefinition refname="fixedInVersion" name="fixedInVersion" type="String">
<WHEN field="System.State" value="Closed">
<REQUIRED />
</WHEN>
</FieldDefinition>