I have a form schema which inherits from another form schema. Both have fieldsets. However, the fieldsets are put in the order they are created. So the fieldset described in the last schema will be the last one. I would like it to be the first. Is there a way to do that ?
Example:
from plone.supermodel import model
from zope import schema
class FormSchema(model.Schema):
model.fieldset(
'test',
label='Test',
fields=['field1']
)
field1 = schema.Text(title=u'test')
class FormSchema2(FormSchema):
# Is last but I would like to place it first
model.fieldset(
'test2',
label='Test2',
fields=['field2']
)
field2 = schema.Text(title=u'test2')
You can't, I am afraid. The schema fieldsets are always merged in reverse interface resolution order; base before derived interface. Declaring the fieldset again on the FormSchema2 schema will only result in the fieldset being listed twice.
If you have to control fieldset order, don't derive from the base schema but re-declare it.
Related
Grid Pro features three recommended built-in editors: Text Field, Checkbox, and Select.
Ho can you manage a list with key and value properties?
For example:
Country list
I'm unable to show country name in the select value and save the id in the database record.
I usually rely on ComboBox when I manage a list with key and value.
Combobox is not present in the list of built-in editors.
Do you suggest to write your own editor?
Let's assume you have a Country class with the properties id and name. And a Person class with a country property. You display a GridPro<Person>.
You can make a Select editor and define it's itemLabelGenerator (or renderer, if you want to show a flag or something) to show Country::getName. **
The saving to the database should be handled by the annotations on the relation. Usually using JPA, there would be a #ManyToOne relation between Person and Country, and save the country-FK (id, specified using #Id) in the person table.
** I don't use Grid Pro, but upon inspection of the code I can see that by using gridPro.addEditColumn(Person::getCountry).select(Person::setCountry, countriesList) you cannot specify the itemLabelGenerator/renderer.
However, you could prepare your own Select component and use the EditColumnConfigurator::custommethod.
Select<Country> countryEditorComponent = new Select<>();
countryEditorComponent.setItems(countriesList);
countryEditorComponent.setItemLabelGenerator(country -> country.getName());
gridPro.addEditColumn(Person::getCountry).custom(countryEditorComponent , Person::setCountry).setHeader("Country");
$page1 = PageType1::get();
$page2 = PageType2::get();
Is there any way in to fetch latest 5 post from combination of two page type.
Any help is accepted.
Assuming PageType1 and PageType2 are both children of Page class you can do:
$myPages = Page::get()->filter(['ClassName' => ['PageType1', 'PageType2']]);
or any other parent class of both page types.
You can sort by Date created (which is saved in SiteTree table), and limit, e.g.
$sortedAndLimited = $myPages->sort('Created')->limit(5);
Downside: you cannot easily search, filter or sort for individual fields that are not shared with the parent class Page, for doing this you need to make the joins manually.
Some columns in my django table happened to be empty and as a result the text rendered there is 'None'.
I would like to see a blank space instead.
django tables2 has some documentation on the subject, but I don't understand it completely.
Where do I have to define this empty_text behavior parameter? Tried in the relevant class meta, but apparently it has no effect.
You can override the default value in your column definition.
If you are not explicitly declaring your column (for example you are letting tables2 figure it out from your model) then you will have to define it so that you can set options for it. It is ok to do that with data coming from models.. as long as the column name you define matches the model field name it will match them up.
class TableClass(tables.Table):
mycolumn = tables.Column(default=' ')
If you need to dynamically work out your default value on a row-by-row basis then define your column and pass empty_values=[], eg:
class TableClass(tables.Table):
mycolumn = tables.Column(empty_values=[])
This tells tables2 that it should not consider any values to be 'empty'.. you can then declare a custom rendering method for that column:
def render_mycolumn(value):
# This is a very simplified example, you will have to work out your
# own test for blankness, depending on your data. And, if you are
# returning html, you need to wrap it in mark_safe()
if not value:
return 'Nobody Home'
return value
Keep in mind that render_ methods are not called if tables2 thinks the value is blank hence you must also set empty_values=[].
Here is the tables2 documentation which describes how custom render methods work: http://django-tables2.readthedocs.org/en/latest/pages/custom-rendering.html?highlight=empty#table-render-foo-method
I have a table that has attributes not common to all rows that will be inserted, which mean my schematic will allow some columns to be empty and this will depend on the type selected.
The tables
Item table
ItemId
Name
Location
Typeid
Type table
Typeid
Desc
Upon a certain type selected (from a dropdown) in the form, some attributes in the item would be shown to the user and they would be have to be entered. How do I approach this.
You'll likely have a controller action (probably a controller) per table so you get separate urls for SEO. You'll also want a view per table as well as these values aren't really shared. You could create an ivory castle that would render a table given a generic List or DataTable, but if you're leaning that route, just use a control for it.
You can also do it with Javascript and AJAX. You can have a div which is hidden called 'item-form'. And on selecting one of the dropdown options, a javascript function can fill the item-form with the html for the selected item type (with the necessary attributes) and make the div visible.
Something like -
$("#dropdown").change(function(){
if($(this).val()==1)
$("#item-form").html(); //form with the attributes for type 1
else if ($(this).val()==2)
$("#item-form").hmtl(); //form with the attributes for type 2
});
You could fill the div's using calls to controller actions that are specific to the type selected which would return partial views.
I'm building an ASP.NET 4 web application using EF4 and I have tables like this:
Product
Attribute
Product_Attribute_Map
Product_Attribute_Map is a cross table, many to many. So Product can have zero or many Attribute and vice versa.
In code I do this:
//Attribute a = new Attribute(); // Edit:
Attribute a = (from a in context.Attributes where a.AttributeID = 1 select a).First();
a.Name = "test";
Product.Attributes.Add(a);
I noticed a problem which makes this very slow. EF4 will execute this SQL on the server:
SELECT
[Extent2].* FROM [dbo].[Product_Attribute_Map] AS [Extent1]
INNER JOIN [dbo].[Product] AS [Extent2] ON [Extent1].[ProductID] = [Extent2].[ProductID]
WHERE [Extent1].[AttributeID] = #p1
I don't understand why it does this. An Attribute may be assigned to 10.000 Products, which makes this a bad query. It takes over 5 seconds to add an Attribute to a Product...
How can I prevent EF4 from selecting all attributes? And just select the attributes for this product.
Thanks
Edit: This is only using POCO t4 template. EntityObject template doesnt have this problem.
My guess: This happens because of LazyLoading used together with FixUpCollections generated by POCO template. When you add attribute to product, fixup collection will perform reverse operation as well - it will add prduct to attribute but first access to products collection in attribute will trigger lazy loading and so your query is executed. I don't like fixup collections ... You can modify POCO template to not use them or you can delete Products navigation property in Attribute (if you don't need it).