I have a django site onto which I have added wagtail following these instructions.
I have set up Social Media setting using these instructions
I have sucessfully added details on the admin page ad I can return and edit these details
However I cannot access them in a template
If I display
{{settings.site_settings.SiteSettings.facebook}}
I get '' (tested using {% if settings.site_settings.SiteSettings.facebook == '' ...)
However
{{settings.site_settings.SiteSettings}}
returns None
and
{{settings.site_settings}}
returns SettingsModuleProxy(site_settings)
What am I doing wrong?
The problem was simply that I had misspelt the SiteSettings class name in models.py (very red-face)
For the group of users I want to disable some menu items. I thought I will use the following:
from wagtail.contrib.modeladmin.options import ModelAdmin as WModelAdmin
class WPartnerAdmin(WModelAdmin):
...
def get_menu_item(self, order=None):
menu_item = super().get_menu_item(order=order)
# if (user_discrimination_logic):
# menu_item.is_shown = lambda *a: False
return menu_item
But it seems that I don’t have access to the request object in the Wagtail ModelAdmin, therefore don’t know how to extract the user data. Is there a way?
You can use Wagtail's Hooks functionality, particularly the construct_main_menu hook:
Create a wagtail_hooks.py file in your corresponding application, with something like the following (from the Wagtail Docs):
from wagtail.core import hooks
#hooks.register('construct_main_menu')
def hide_explorer_menu_item_from_frank(request, menu_items):
if request.user.username == 'frank':
menu_items[:] = [item for item in menu_items if item.name != 'explorer']
Wagtail's built in permission system stops the user from viewing the actual modeladmin objects, but the available options still show up in the menu even for groups without permission to view them. When they try to view the objects, people without view permission are sent to the login screen and told they have insufficient permission.
If you want to hide admin menu items for particular users that are all part of a specific group, or even multiple groups, you can do it using wagtail's construct_main_menu hook. Add a wagtail_hooks.py file in the app folder. Menu items are edited in place.
To remove two menu items called "secrets1" and "secrets2" for users that are in any of "regular_user" or "bad_user" groups, you could do something like this:
from wagtail.core import hooks
#hooks.register('construct_main_menu')
def hide_explorer_items_from_users(request, menu_items):
if request.user.groups.filter(name__in=["regular_user", "bad_user"]):
menu_items[:] = [
item for item in menu_items if item.name not in ['secrets1', 'secrets2']
]
This is fine for removing items, but if plan on adding menu items this way, Wagtail's Hooks Documentation warns you that menu items added this way will be missing associated javascript includes, so you should use the #register_admin_menu_item hook for adding items instead.
For most purposes, this can be done without any code changes, through the permissions system.
Under Settings -> Groups, define a group with permissions over the objects they should be able to edit (such as pages, images and documents), and ensure the 'Can access Wagtail admin' permission is checked. Then, in Settings -> Users, go to the Roles tab for each user and add them to that group (and ensure Administrator is unchecked). Any menu items that the user doesn't have permission over will be hidden.
I am supporting an ember site that was build by someone else. The frontend is Emberjs with a Drupal 7 backend.
The site has a user profile where they can enter a bio. The initial bio entry is fine, but if the user edits the profile (changes some other field for example) but does not change the bio text, then it saves something like <p>My bio</p>as the value of the field where the html tags are saved as text.
The component.js for the form has this in it:
bodyChanged(newValue) {
this.get('profile').set('bio', newValue);
},
Suspecting this is the culprit but not sure what to do to fix.
Thanks
I found the problem. My deserializing function that sucks in the drupal json was using json[fieldName]['und'][0]['safe_value']; as the value. When I switched it to use the json[fieldName]['und'][0]['value']; the problem went away.
I am developing cmdb application and trying to create a link to admin page of the device ( /admin/cmdb/device/device_id/) in django-tables2 LinkColumn with the following syntax:
id = tables.LinkColumn('admin:cmdb:device', args=[A('pk')])
This fails with error
NoReverseMatch at /cmdb/emp/171/
'cmdb' is not a registered namespace inside 'admin'
(/cmdb/emp/171/ - is the page on which the table is rendered)
How can I write the correct path in LinkColumn argument to Django admin page?
The goal could be achieved by using TemplateColumn:
id2 = tables.TemplateColumn('{{record.id}}')
but possibly someone could advise how to use LinkColumn?
Your question is not about the LinkColumn but about finding out the url names of the django admin pages.
In any case, you can find your answer here: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls
So if the name of your application is cmdb and the name of your model is device, the url name of the device edit page would be admin:cmdb_device_change which could be used in the LinkColumn (also it can be used in the TemplateColumn using {% url "admin:cmdb_device_chang" record.id %}).
Where did I miss to add a line of code if I try to echo php variable inside OPENCART product.tpl file and it doesn't show up on site?
Notes: there is a field in database. I am able to save to this field from admin panel ( i added a custom field there).
Did You edit also the product controller to load the variable and pass it to the template? I guess not... Edit catalog/controller/product/product.php and add $this->data['MYVARIABLE'] = $product_info['MYVARIABLE']; somewhere before $this->render() is called.