Change Display Name of Usr Field After Publish - customization

I am working with a new screen that is using a the DAC and Graph of the Inventory Item table. When I add a field into the form header that is a Usr custom field it has the name that has already been assigned in the a different customization project. How can I change this name in the new customization project. I have tried going through the customize attribute but it does not show up in the fields that I can select. Is there a way to do it through Graph or DAC code or even dynamically? I am just updating the display name not the data type of anything like that. I have tried going through the Label Text property but that does not work.

You could override the DAC field DisplayName attribute in your graph using CacheAttached method.
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXUIField(DisplayName = "My Display Name")]
protected virtual void DAC_UsrField_CacheAttached(PXCache sender)
{
}

Related

Set default values when creating contact from lead

I added a few custom string fields using NameValuePair in the Lead form (CR301000). Using the an Action, I create a contact from the lead. I added the same custom fields to my Contact form (CR302000). How can I get the custom values from my lead to my new contact? I tried using the following:
[PXFormula(typeof(Selector<CRLead.contactID, ContactExtNV.usrCROnline>))]
I'm going to have the same issue when I create an account from the lead. Is there a better way to do this instead of using PXFormula?
The Selector parameter for the PXFormula attribute looks like this:
Selector –> Selector<KeyField, ForeignOperand>
KeyField-> The key field to which the PXSelector attribute should be attached.
ForeignOperand-> The expression that is calculated for the data record currently referenced by PXSelector.
That is, in your case it turns out like this:
[PXFormula(typeof(Selector<Contact.contactID, CRLeadExt.usrCROnline>))]
public string UsrCROnline { get; set; }
Adding namespace in the source code using Customization Project Editor

Can I use a Query String to drive personalized content in Sitecore 7.5?

I'm trying to display personalized content on a page IF I have clicked on a specific link on a specific page. My thought was to have a parameter on the link such as:
Go to product page
Then, on "Product Page", hopefully using the rules engine, check if the parameter home exists in the query string. If so, then display a piece of content.
I can't seem to figure out the best way to do this with Sitecore 7.5. Maybe this is the wrong approach.
Out of the box in Sitecore 7.5 there is no rule for using the querystring.
but you can easily create a rule and use with the personalize feature from Sitecore.
See http://blog.martinmiles.net/post/rules-engine-and-sitecore-personalization-based-on-url-query-string-parameters
for a complete description and Example include a link to github with the code
https://github.com/MartinMiles/Personalization
so you would have to have something like this:
public ActionResult Index(string name)
{
Student student = new Student();
student.Name = "John";
if (!String.IsNullOrEmpty(Request.QueryString["name"]))
{
student.Name = Request.QueryString["name"];
}
return View(student);
}
For this example, my controller is named Test. So if I want to call this method I would do ~/test/index, if I do that the student object will contain the name John, however if I do ~/test/index?name=Denis , I will send an object with the name Denis
Here the name will only change when we pass the query string "name" with a value.

django one widget for two m2m fields

I have two manytomany fields for my model ModelFrom, that both go to the same Model, call it ModelTo.
ModelFrom(models.Model):
field_one = ManyToManyField(ModelTo)
checked = ManyToManyField(ModelTo)
checked is a subset of field one. I have properly validated this in model clean() and adminform clean() methods, and updated model::save() to call self.full_clean().
Ideally, I would have one widget, much like the django.forms.SelectMultiple, but with a checkbox inside each <option>.
what it currently looks like, I have one of these widgets for each field:
:
I want to combine them and have a checkbox or something, here is my unicode representation of what it would look like
{ [ blah: 2 ☐] , [blah: 1 ☑] }
Value in the list -> field one is set. Checked box -> checked is set as it is a subset of field_one.
I have seen jQuery UI MultiSelect Widget but there doesn't seem to be a way to be able to select an option, but not check the box.
I couldn't directly answer my own question, but like most questions, if the answer is not possible then there may be an underlying problem.
Instead of having two many2many fields, I should just have one, setting the through property, for an intermediate field.
Like so:
class IntermediateField(models.Model):
checked = BooleanField()
from = ForeignKey(ModelFrom)
to = ForeignKey(ModelTo)
ModelFrom(models.Model):
field_one = ManyToManyField(ModelTo, through=IntermediateField)
Then, we can just use an inline for IntermediateField in ModelFrom admin, easily checking the boxes etc

Django Inline Autocomplete

Is it possible to filter an inline autocomplete field by a dynamic value entered by a user?
For example, I have a an admin form where staff enters games information including home and visiting team, game date and time, score, etc. They also enter individual player names and stats. I would like to add a filter to show only the players on either the home or visiting team.
I am using the InlineAutocompleteAdmin module, which provides autocomplete hints for input fields.
Here is the current inline autocomplete code:
class IndividualFootballGameInline(InlineAutocompleteAdmin):
model = IndividualFootballGame
extra = 1
related_search_fields = {
'player': ('player__first_name', 'player__last_name', '#team__sport__sport=Football', '#team__season__season_start_date__year=' + str(get_current_season_start_year('football'))),
}
If this can be accomplished, can you explain how?
InlineAutocompleteAdmin provides a template that I modified to provide this functionality. The file templates/admin/autocomplete/inline_searchinput.html defines the jQuery lookup() function. I added additional code to check for values in the visiting and home teams field, and to append them to search_fields as needed.

django admin filter tweaking

I want to use django's admin filter on the list page.
The models I have are something like this:
class Location(model):
name = CharField()
class Inquiry(Model):
name = CharFiled()
location = ManyToManyField(Location)
Now I want to filter Inquiries, to display only those that contain relation to specific Location object. If I use
class InqAdmin(ModelAdmin):
list_filter = ['location', ]
admin.site.register(Inquiry, InqAdmin)
the admin page displays me the list of all Locations and allows to filter.
What I would like to get, is to get list of only those locations that have some Inquiries in relation to them (so I don't ever get the empty list result after filtering).
How can this be done?
You could create a custom manager for Locations that only returns Locations that have an Inquiry associated with them. If you make this the default manager, the admin will use it.
Only caveat is that you'll need create another manager that returns all Locations and use that in the rest of your app whenever you want to retrieve Locations that don't have an associated Inquiry.
The managers section in the Django docs is quite good, and should be all you need to get this set up.
EDIT:
sienf brings up a good point. Another way to accomplish this would be to define a subclass of django.contrib.admin.SimpleListFilter, and write the queryset method to filter out Inquiries with empty Locations. See https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter