I use https://github.com/elo80ka/django-dynamic-formset to add and delete rows from a formset.
The problem is that the add row and delete row buttons are automatically inserted weird places.
Can I place these buttons manually?
Or are there any other jquery libraries to add and delete rows in a formset dynamically?
I don't think you can place these buttons manually, maybe if you check the rules followed by the plugin to place the buttons: https://github.com/elo80ka/django-dynamic-formset/blob/master/src/jquery.formset.js#L49
As you can see:
//If the forms are laid out in table rows, insert
// the remove button into the last table cell
// If they're laid out as an ordered/unordered list,
// insert an < li > after the last list item
// Otherwise, just insert the remove button as the
// last child element of the form's container
You can specify addCssClass (which is by default 'add-row'), maybe that can help you.
Related
I have a QAbstractItemModel derived model attached to a QTreeView
I want to programatically append a single row to a node somewhere in my tree hierarchy.
I have a slot which is connected to a signal from my view. The signal sends the QModelIndex of the node to which I want to append my new row. In the slot I call beginInsertRows(...) using that QModelIndex and the new row's row number, append the new row to my model data, and then call endInsertRows():
The value passed to beginInsertRows(...) is the number of child rows the parent node has prior to appending the new node.
That is, if there are 4 child rows, they will have row indices 0, 1, 2 and 3. Therefore the new row number added will be 4.
void Model::slotOnAddRow(QModelIndex parent, std::string key)
{
assert(parent.isValid());
Row& parent_row = *static_cast<Row*>(parent.internalPointer());
beginInsertRows(parent, parent_row.numChildren(), parent_row.numChildren());
parent_row.addChildRow(key);
endInsertRows();
}
The problem I'm having is that after calling endInsertRows() my view does not update.
Example:
Here is an example of my tree view.
Scenario:
I want to append a new row to SPREAD_1.
SPREAD_1 currently has 4 children rows:
0: inst_id
1: LEG_1
2: LEG_2
3: LEG_3
The new row will therefore have row index 4, so I call beginInsertRows(SPREAD_1, 4, 4);
I do just this, and my view does not show my new row.
Proof the node does actually exist:
I know the row exists in my model, because if I collapse the SPREAD_1 node, and then re-expand it, my newly added row is now visible:
Question:
AFAIKT I've followed the example online correctly, but I'm obviously missing something.
How can I append a new row to a tree node, and have the view update?
Do I need to emit a signal or override another base class method?
An issue like this is indicative of an error elsewhere in the model. Without seeing the implementation of the model it is impossible to say where.
Using Model Test can be very helpful in diagnosing the issue.
Literally all you need to is instantiate a ModelTest instance with your model
QTreeView(&_model);
ModelTest test(&_model);
If the model doesn't conform, you will get assertion failures from ModelTest
I fixed this by adding ui->treeView->reset(); after insert rows
Make sure that the index passed to beginInsertRows is correct. In particular the column number for the index needs to be zero if the children are attached to column zero (which they normally are)!
Try to emit dataChanged signal with parent index as argument.
1) Initial load of list page shows 50 items.
2) By "clicking show more" using django endless pagination, there are 100 items on the page now.
3) follow link to 90th item in list and go to another page
4) click back button on the browser
The problem is that after step 4, the list contains only the first 50 items.The last 50 items is not displayed.
Is it possible to return to position of 90th item on list page by hitting the back button
I think it's not special to Django. We can use url hash to return to specified place. So,
1. in html, code snippet <div id="test">...</div>
2. url like http://xxxx/#test will be located to div with id 'test'
But, this way cannot remember the exact position.
For example, cannot remember position between two div each with an id.
A minor but rather annoying flaw in the default layout of forms in Django manager apps is the positioning of checkboxes where the checkbox and its label are positioned in the first column and its help text (if set) is aligned in the second column:
Either the checkbox and label should be positioned in the second column or -better- the label should be aligned in the first column (with all other labels) and the checkbox positioned in the second column.
I presume the chances are slim, but is there a relatively easy fix for this?
If you can do it by adding css, then it is relatively easy:
class MyModel(admin.ModelAdmin):
class Media:
css = {
'all': ('/path/to/css.css',)
}
I would like to be able to store reusable html-formatted text in Sitecore and reference in codebehind for inclusion in a custom user control. What is the best practice for doing this? If a user selects option A, for example, I would reference standard text A in my control. Any examples for how to accomplish this are appreciated. Thanks.
You have a couple options:
Store the text in the Standard Values of the same template that defines your option list. That makes it available on the same item, but standard for all items. Use security to lock down the field if you are worried about it being edited. This could also be accomplished with the new "cloning" feature in 6.4, I believe.
Create a structure outside of your Home element for storing this data. Based on the option selected, find an item in your content tree which corresponds to the selected item, and read the text off of it. You would need to find this item either relative to /sitecore/Content, or relative to your website root if multi-site support is a requirement.
No.2 in pseudo-code:
//get the item where we have the text values
Item textBase = Sitecore.Context.Database.SelectSingleItem(textBasePath);
//find the child w/ the same name as the selected option
Item textItem = textBase.Axes.GetChild(selectedOptionValue);
string value = textItem["text"];
I think I would do something like techphoria414's 2. option:
ie you have your normal "page" templates as per usual, but then you have some fields (multilist, treelist fields), where you put the source pointing to your other items contain the different texts.
then you basically just have to get the items from the current item (with some very quick'n'dirty code/pseudocode):
var CurrentItem = Sitecore.Context.Item;
Sitecore.Data.Fields.MultilistField mlf1 = CurrentItem.Fields["myExternalTexts"];
if(mlf1 != null)
{
foreach (Item itm in mlf1.GetItems())
{
lit += Sitecore.Web.UI.WebControls.FieldRenderer.Render(itm, "richtext");
}
}
You ofc shouldn't just add them to a literal and you should you Sitecore built in Field renderes if using Sitecore 6 or above and it's a Rich text field.
I hope that helps.
I have a Django app that displays a list of rows in a table to the user. Each row maps to an entry in a database. I want to let the user select the rows they would like deleting by adding a checkbox to the end of each row and a delete button ( similar to how gmail lets you delete multiple mail messages). I can't quite figure out how to write the view in terms of finding out which rows were selected and how to map these to the IDs of the entries that need deleting from the database. A simple code snippet showing how to do this would be greatly appreciated.
UPDATE:
I've found this code snippet that I think should do the trick
You can use the CheckboxSelectMultiple widget to auto-generate the corresponding HTML code so you don't have to do it manually.
You can define your form like so:
class UsersForm(forms.Form):
users = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=[QuerySetIterator(Users.objects.all(), "", False)], label="")
Another advantage is that you also get validation for free.
Create a formset and pass can_delete = True to the constructor. Then, in the template,
{{formset}}