Here is my problem:
I have a custom Dexterity content type that its ids must be always a computed value out of two fields (week and year).
What I need to ensure is that if someone tries to create a new object of that content type and uses an already existing (week, year) tuple Plone needs to give an error and ask the user to change either the week or year fields.
So I not only need to check that no other object already exists with that week and year values, but also that the object id is consistent (WWYY, WW for week and YY year is the format).
I first thought of an invariant on the content type interface, but that still leaves the id up to INameChooser.
So registering an INameChooser for the parent folder (fortunately I have a specific parent folder for that content type) can be enough?
Related
Is it possible to make a report, where lines of the table will be different url parameter values and other columns - say ecommerce (transactions, CR)?
There is no out of the box report.
To do that you would need to:
create custom dimensions in the property settings (you only have 20). Let's say you name them imaginatively parameter1 - parameter20
user filters to map the query parameter (lets say param1-param20) to the custom dimension.
create a custom report for your custom dimensions
Go to filters, custom, advanced. Set Field A First field Request URI. In the Extract A field you enter (for a GET parameter "param1") the expression param1=([^&.]*). This stores the value for param1 in a variable called $A1. Leave Field B and Extract B empty.
In "Output to" select the name of your custom dimension, in this case "parameter1". In Constructor enter $A1. This will map the value extracted from the parameter to your custom dimension.
Other options: Field A required "Yes", Field B required "No", Override Output Field "Yes", case sensitive "No".
Now wait a while until data has been collected. Then go to "customization", create a new custom report, select parameter1 (or any other of your custom dimensions) as dimension and add metrics at your gusto. The report will only show data for pageview where the dimension has been set.
You would probably create your custom dimensions at hit level (unless you are only interested in the last value in a user session), so combining them with conversion metrics like transactions might produce not particulary valid results.
If you have more than 20 different url parameters you want to capture you are out of luck.
(Btw. I'm not actually sure this is a on-topic question, but the answer has an regular expression in it so it might count. Still reporting questions are probably better suited for webmasters.stackexchange.org).
I have a behavior that defines two fields: year and week (of the year).
This behavior is reused for several content types, and only in one of them I need to make sure that this fields are not repeated in any other instance of the same content type, i.e. two objects of this content type can not share the same year and week (is fine to share the same year or the same week).
As this restriction is only meant for this specific content type I tried with an zope.interface.invariant but for some reason I can not get access to the fields defined in the behavior.
A simplified version of the Content type would be:
class IMyContentType(form.Schema)
title = schema.TextLine(title="My title",
description="My description",
required=True,
)
#invariant
def check_year_and_week(data):
data.week
How can I get the value (if any) from within check_year_and_week invariant?
You can't. Invariants have access to values for other fields in the same interface, but not fields from other interfaces.
You can use a widget manager validator instead: http://developer.plone.org/reference_manuals/active/schema-driven-forms/customising-form-behaviour/validation.html#widget-manager-validators
Or do the validation in your form's action handler: http://developer.plone.org/reference_manuals/active/schema-driven-forms/customising-form-behaviour/validation.html#validating-in-action-handlers
A behavior is nothing but an adapter; if you're not getting the fields on the invariant you probably need adapt your content type before trying to access the extra fields.
I'm building content type using dexterity. We've date of birth field and by default year range is +- 10 year from current year.
Date field need to be modify and year should start from 1950. I did bit goggling and couldn't find right information I'm after.
Below is my DOB field definition.
dob = schema.Date(
title=_(u"Date of Birth"),
)
Any advise or reference would be great.
Thanks in advance.
Use the collective.z3cform.datetimewidget (https://github.com/collective/collective.z3cform.datetimewidget)
for your field.
This widget has a yearRange attribute.
By default it gets the range defined in site_properties: calendar_starting_year and calendar_future_years_available
Check the documentation if you don't know how to setup the widget
BTW since Version 1.2.4, You can set the min/max value on the field.
I have a dexterity content type (container) where I have two custom fields for a contract start date and end date.
When creating the type I’d like the end date to be used also for the Plone “expiration date”.
How do I copy the Date over to the Expiration Date field?
I think you have 2 approaches to solve this: the first is to use the standard expires field directly instead of your custom end date field; you could have an issue if you want to override the label/description of it, as you will have no way (AFAIK) to change them only for your domain.
the second one could be to override the standard expires field and make its getter method return the value of your custom end date field.
check the following documentation:
Plone and Dexterity: Working with computed fields
Plone Developer Documentation: Behaviors
Medatada definitions inside plone.app.dexterity
I have a question about type 2 dimensions.
Within our HR system, it is possible to hire an employee with one date, and then at a later point in time, change the hire date if it had been entered incorrectly in the first place. This gets complicated when using Type 2 dimensions as the change would result in a new record in the dimension table.
So, I basically need a way to say that some updates (such as the one above) shouldn't result in a new record in the dimension table. But, for other instances such as if an employee moves to a new position, then I definitely need to create a record in the dimension table.
What are my options here?
A type 2 dimension doesn't need to apply to every attribute in the dimension. You can choose to make some attributes Type 1 which overwrites values and loses the history and some attributes Type 2 which creates the new record and retains history.
So in your example above you'd make the "Position" attribute type 2 and the "Hire date" type 1.
Check out this wikipedia link with a list of the different types of slowly changing attributes, http://en.wikipedia.org/wiki/Slowly_changing_dimension.
Most of the time you'll only need Type 1 and Type 2 tho.