Add a custom link/model to wagtail's admin sub-menu - wagtail

Wagtail documentation explains how to:
Add an item to the admin menu
Add a group/submenu to the admin menu
Let our model be CustomManager and its admin url be /admin/custom_manager/.
Using a hook, we can add a link to our page on to the first level of the admin menu:
#hooks.register('register_admin_menu_item')
def register_edit_menu_item():
return MenuItem( 'Custom Manager', '/admin/custom_manager/', classnames='icon icon-folder-inverse', order=1000)
But how can we add this link to a sub-menu/group, when our model is not a wagtail model?

Related

Prevent field from being save into Django Model

I am creating a form that allow user to edit all the fields in the form. I would like to check with the community if there is a viable solution to display say the object ID in the form itself but when the user submit the updates, it will save the other fields and will not save the object ID?
Currently, I am prevented from saving due to the error: "ID already in database"
I have tried to add the attributes "readonly"; "disabled" but these are not working.
I am using {{form.as_p}} to display all the fields in my templates (HTML)
My apologies that I am not able to show the codes as it is on my corporate server.
Much help appreciated
Let assume that user want to update 'First name', then here below is technic to update authenticated user 'First name':
forms.py
from django import forms
from django.contrib.auth.models import User
class EditUserForm(forms.ModelForm):
class Meta:
model = User # You can provide model class here to update
fields = ['first_name'] # You can provide any field you want to update
views.py
from .forms import EditUserForm
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
#login_required
def edit_user(request): # give a url path with name='edit_user' in urls.py file
user = User.objects.filter(id=request.user.id).first() # Here you can write your model name which you want to update
form = EditUserForm(request.POST or None, instance=user)
if form.is_valid():
form.save() # that's it
return redirect('/') # redirect to wherever you want
return render(request,'update.html',{'form':form}) # provide template name here
update.html
<h1>Update First name:- </h1>
<form action="{% url 'edit_user' %}" method=POST>
{{form.as_p}}
<button type='submit'>Update</button>
</form>
Now, try it manually and you able to change the 'First name'. After that you get some confidence how you update any field of models.

Wagtail 2.11 translatable field with wagtai-localize

Is it possible to translate a non snipppet/page model in Wagtail >= 2.11 and wagtail-localize >= 0.9.3 ?
I've set up my model as follows:
class TrainingPlace(TranslatableMixin, models.Model):
name = models.CharField()
description = models.TextField()
class Meta(TranslatableMixin.Meta):
verbose_name = "Training Places"
translatable_fields = [
TranslatableField("description")
]
I have a "Training" submenu in my wagtail admin page, with Trainings, Training Photos, Trainers, Training Places, where I can add Trainers, new Trainings etc.
If I register a TraningPlace with a #register_snipppet I can translate it, but at the moment there are some problems:
I see many Trainings (menu) -> TrainingPlace recoreds in admin listing with no "Translate" option
If I go to Snippets (menu) => Training Place snippets I can see snipppets and have option to translate/create/sync translations, but when I click on change language button in admin I am getting a blank page (url points to a snippet with different ID) which may be a bug.
Can non snippet/page models be translated in admin when using TranslatableMixin on model ?

How to show a module that is used in many tabs in DotNetNuke

We are new to DNN and we plan to add a product module that is in charge of adding, editing, deleting, listing, and showing the details of the products.
We have written a UserControl named ProductsList.ascx, which has AddProducts.ascx and ShowPrdoctDetail.ascx defined in it, using Host => Extensions => ProductsList => Module Definition => Add Module Control.
In admin mode,we have created a page and dragged the module in it, so that the admin of the site can add, edit, delete, and see the details of each product.
Also there is a slideshow in the homepage that shows the latest products.In addition, the products are shown in the menu.
Now, we want to redirect user to the product detail page (ShowPrdoctDetail.ascx in our case) whenever he/she clicked the product shown in slideshow or in menu.
We are aware of Globals.NavigateUrl() method, but it needs tabid and mid to redirect to a specific page and module and in DNN every added page by admin will get different tabid and mid.
Since in DNN, admin can create many pages and add this module to them, we have no idea that what tabid and mid we should pass to Globals.NavigateUrl() in order to navigate user to product details page (ShowPrdoctDetail.ascx) when user clicked on a specific product in menu or slideshow.
Any kind of help is highly appreciated.
Try save current tabid to DB when adding product detail module into page. And with ProductId, you can grab tabid of product detail, and use it to redirect to correct page.
The way I would tackle this is to create another Module Definition for the details module and give it a Friendly name like "Product Details" and add the ShowProductDetail.ascx module control as the default view of this new module definition.
Then you can drag that new module onto a page for your product details page.
In your main Product Admin module, you can create a setting view with a dropdown list that contains a list of all tabs (pages) that the "Product Details" module on.
You can use the following method to get the list of tabs in the portal that has an instance of the module:
private List<TabInfo> GetAllModuleTabsbyModuleName(string friendlyName)
{
List<TabInfo> results = new List<TabInfo>();
Dictionary<int, int> dups = new Dictionary<int, int>();
ModuleController mc = new ModuleController();
ArrayList oModules = mc.GetModulesByDefinition(base.PortalId, friendlyName);
TabController tc = new TabController();
TabCollection oTabs = tc.GetTabsByPortal(base.PortalId);
foreach (ModuleInfo oModule in oModules)
{
foreach (KeyValuePair<int, TabInfo> oTab in oTabs)
{
if (oTab.Key == oModule.TabID && !dups.ContainsKey(oModule.TabID))
{
results.Add(oTab.Value);
dups.Add(oModule.TabID, oModule.TabID);
}
}
}
return results;
}
You can bind that to the dropdown list options and an administrator could select the page that will be redirected when a product is clicked on the main module.
ddlProdDetailsTab.DataSource = GetAllModuleTabsbyModuleName("Product Details");
ddlProdDetailsTab.DataValueField = "TabID";
ddlProdDetailsTab.DataTextField = "TabName";
ddlProdDetailsTab.DataBind();
So from the settings, you know the TabId you want to redirect to, then you need the moduleId and you can create the redirect using NavigateUrl().
var pdTab = TabController.Instance.GetTab(Convert.ToInt32(Settings["ProductDetailTabId"]), PortalId);
var pdModule = pdTab.Modules.Cast<ModuleInfo>().FirstOrDefault(m => m.ModuleName == "Product Details");
var productLink = Globals.NavigateURL(pdTab.TabId, "", "mid=" + pdModule.ModuleId, "productId=" + productId);

NG-Admin: Is there a way to create an "add new" button on a referenced_list?

I have a referenced_list in my ng-admin app:
nga.field('profiles', 'referenced_list') // display list of related profiles
.targetEntity(profiles)
.targetReferenceField('user_id')
.targetFields([
nga.field('id').isDetailLink(true),
nga.field('username'),
]),
nga.field('', 'template').label('')
.template('<span class="pull-right"><ma-filtered-list-button entity-name="profiles" filter="{ user_id: entry.values.id }" size="sm"></ma-filtered-list-button></span>')
The template field creates a "view all related profiles" link.
What I would like to do is create a "add new profile" button that links to the profile creation page, and pre-selects the current user_id.
Is there a hack to do this or a custom template / directive that can do this?
The <ma-create-button>directive has been added a few days ago (https://github.com/marmelab/ng-admin/pull/696). It allows exactly what you want:
<ma-create-button entity-name="comments" default-values="{ post_id: entry.values.id }" size="xs"></ma-create-button>
It's available in ng-admin 0.9-dev and higher.

bread crumbs for views drupal 7

Am working with views and am wondering if there is a way to get the view to update the breadcrumb trail. When on my first view called homme the breadcrumbs are not updated it still just says "home >" as if it is still on the homepage. When I click a post the breadcrumbs update to "Home › Blogs › admin's blog › ". I need it to say Home > Homme > Name of Article, basically what you would expect when going to a blog site or post.
Can I get the view to act like a blog?
One option is to try overriding the themeable output generated by the default breadcrumb function.
Assuming you've created your own theme - create a file called template.php at the root of your theme. Create a function named YOURTHEME_breadcrumb, where YOURTHEME is the name of the theme. The HTML returned by this function will be the breadcrumb. Modify the return values as necessary here to get what you want. Consider using Drupal's menu functions to build a more satisfactory breadcrumb.
Check the comments of this API article for more detail: http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_breadcrumb/7
Adding this to your template.php file should work with d7 sites:
function theme_breadcrumb($breadcrumb)
{
if (substr($_GET['q'], 0, 13) == 'news/category') {
$breadcrumb[] = l('News', 'news/');
}
if (count($breadcrumb) > 1) {
if ($breadcrumb) {
return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) ."</div>\n";
}
}
}

Resources