Inputfield for link to any contenttype in Bolt-cms - bolt-cms

is it possible to setup a field which links to a specific content of multiple content types?
So assuming there are 3 predefined contenttype CA, CB, CC. I would like to setup an input field, which allows to link to any content of the contenttypes CA, CB, CC.
Does anybody know how to do this or what section of bolt needs to be extended?
Thanks a lot!
I found the following three ways to link to other pages but they are always a link to one contenttype only.
By selectentry
selectentry:
type: select
values: entries/id
postfix: "Select an entry"
autocomplete: true
sort: title
Single relation
relations:
entries:
multiple: false
label: "Choose an entry"
order: -id
format: "{{ item.title|escape }} <span>(№ {{ item.id }})</span>"
postfix: "By selecting an Entry, you're creating a bi-directional relationship to that Entry."
Multiple relations
relations:
pages:
multiple: true
order: title
label: Select zero or more pages

this is currently not possible to do in a clean way. You could add a few type: select fields, and then in your template use {% if %} statements to display the right thing.

Related

query for empty array in "include" model field

Let’s say I have foo and I make it include bar model,They are many to many relationship.
While bar model contains a column called clients, which is an array in nodejs.
foo.findAll({
where : where,
include : [{ model: bar}]
})
How should I use foo.findAll to get all data which bar must be an empty array.
You can simply Do it like this I am suggesting this because your question is unclear
foo.findAll({
where: where,
include: [{
model: bar,
where: { name: { [Op.is]: null } }
}]
})
above code will return data of model bar where name as no value or the field is null

OctoberCMS BelongsTo (HasMany) Relation Issues

I have a Series model which $hasMany RainLab\Blog\Models\Posts and when I display this model with 'type' => 'relation', in Posts form it looks perfectly fine:
So, I can select one Series and assign it to a Post. What I wanted to do is to be able to create new series while being on Posts page. To do this I tried to use 'type' => 'partial' for Series field. Partial itself contains just:
<?= $this->relationRender('series', ['readOnly' => false]) ?>
config_relation.yaml contents:
series:
label: Series
view:
list: $/plugin/models/series/columns.yaml
form: $/plugin/models/series/fields_simple.yaml
toolbarButtons: link|unlink|create|add|remove
manage:
form: $/plugin/models/series/fields_simple.yaml
columns.yaml contents:
# ===================================
# List Column Definitions
# ===================================
columns:
title:
label: Title
searchable: true
post_count:
label: Posts
sortable: false
created_at:
label: Created At
type: date
invisible: true
updated_at:
label: Updated At
type: date
invisible: true
fields_simple.yaml:
# ===================================
# Form Field Definitions
# ===================================
fields:
title:
label: Title
span: left
required: true
slug:
label: Slug
span: right
placeholder: Slug
required: true
preset:
field: title
type: slug
So, basically, nothing special here. But:
As you see, it looks terrible by default. And one more issue - when deleting the series (or unlinking, I tried both) it does not refresh the form, values remain there, though the relation is removed in DB.
Am I doing anything wrong here? What is the proper way to nicely display this relation with ability to edit it?

Django admin: allowing some HTML in user input

By default, the Django admin strips away all HTML tags from user input. I'd like to allow a small subset of tags, say <a>. What's the easiest way to do this? I know about allow_tags, but it's deprecated. I also want to be careful about manually marking strings as safe that aren't.
If external library isn't a burden for you, then you must try django-bleach, it will suffice your requirement. It returns valid HTML that only contains your specified allowed tags.
Configuration:
in settings.py
BLEACH_ALLOWED_TAGS = ['p', 'b', 'i', 'u', 'em', 'strong', 'a']
BLEACH_ALLOWED_ATTRIBUTES = ['href', 'title', 'style']
BLEACH_STRIP_TAGS = True
Use cases:
1. In your models:
from django import models
from django_bleach.models import BleachField
class Post(models.Model):
title = models.CharField()
content = BleachField()
2. In your forms:
class PostForm(forms.ModelForm):
content = BleachField()
class Meta:
model = Post
fields = ['title', 'content']
In your templates:
{% load bleach_tags %}
{{ unsafe_html|bleach }}
for more usage, I suggest you must read the documentation. Its quite easy and straight forward.
documentation
You can use format_html() or mark_safe() in place of allow_tags. Although, like you were saying, mark_safe() probably isn't a good idea for user input.
format_html(): https://docs.djangoproject.com/en/1.9/ref/utils/#django.utils.html.format_html
mark_safe(): https://docs.djangoproject.com/en/1.9/ref/utils/#django.utils.safestring.mark_safe

Row level permissions in sails.js

I need row-level permissions in sails. I already looked at this and at other threads, but everybody says to just use policies.
But what I need isn't just limiting the ability to do e.g. find/update all elements of a table but to have permissions per database row that consider associations for permissions.
It would be great if the permissions support blueprints like the ember data adapter, nested create/update/find (with populate) and sockets.
So for example:
GET /:model/:id
should return and populate with such entries where certain associated conditions are met.
So for example, we have 4 models:
User (columns: id, name, email, pwd_hash, ...)
Project (columns: id, client, name, ...)
UserAssignment (columns: id, user, project, user_perms, ...)
Client (columns: id, name, ...)
User and Project are linked through UserAssignment - an advanced MM-Table. (Users may have special user_perms to different projects, such as read,write,manage). And a Project always has one Client.
Here's the corresponding sails models:
// User.js
attributes: {
name: 'string'
}
// Project.js
attributes: {
name: 'string',
client: {
model: 'client'
},
userAssignments: {
collection: 'userAssignment',
via: 'project'
}
}
// UserAssignment.js
attributes: {
userPerms: 'integer',
user: {
model:'user'
},
project: {
model:'project'
}
}
// Client.js
attributes: {
name: 'string',
projects: {
collection: 'project',
via: 'client'
}
}
So lets say the User with the ID=1 wants to access a list of Clients he is allowed to see, he calls
GET /clients/
Speaking in SQL:
SELECT client.*
FROM client
INNER JOIN project ON project.client = client.id
INNER JOIN user_assignment ON project.id = user_assignment.project
WHERE user_assignment.user = 1 and user_perms > 4
GROUP BY client.id;
And then also if we have certain Project managers, they can update associated UserAssignments etc.
Basically I thought the permissions could be based on role associations.
I tried several ways to implement this functionality. I tried _permission_read, _permission_write columns for all rows and other stuff like using populates for this but nothing seems to work right.
The above example is just a excerpt of many different kinds of models which I can filter based on SQL couldn't do nicely with Sails/Waterline.
Do I need custom SQL queries for this?
Is it possible to do this neatly with Sails?
Do I misunderstand policies and is there a way to implement such requirements with them?
Or shall I use SQL views instead of tables?
Thanks in advance!

How to update a div in a View, by class, from another View?

In my main view, I have an empty placeholder div that I fill with an inner view on a user click. I want to be able to have several copies of the same inner view in my main view, with different data tied to each inner view.
The main view has its own model and controller, and the inner view has its own model and controller. When an item is selected in the main view, the inner view fills with data pertaining to the selection. I get this data from a web service based on the id of the item that was selected, so I can't fill the inner view's model with data, until that point.
Since the multiple view divs can't all have the same ID, I can't use something like #Ajax.ActionLink with UpdateTargetId. Instead, I declared it <div class='placeholderDiv' title='#[some_unique_id]'>, and I can draw the multiple divs successfully using the following in my main view:
$.ajax(
{
type: 'POST',
data: { 'id': id },
dataType: 'html',
url: '/MyController/MyMethod',
success: function (result) {
$(".placeholderDiv[title=" + id + "]").html(result);
}
});
Now, I want the user to be able to update the model in the inner view. I am able to do this in the inner view's controller, but I can't get the changes to display. How am I supposed to access the div with the class placeholderDiv in the main view, from the inner view?
This sounds like a good candidate for "outsourcing" your "inner view" to client-side templates. That way, you can have a standard template defined somewhere (maybe in your main view?), and all you do is fetch your model from your services, bind it to a copy of your template/s, and then render that onto the page.
A great templating library I'm looking at right now is DustJS. Using it, I can define a template like so (note that this has to be defined only once in your page):
<div id="{id}">
<h1>{name}</h1>
{?accounts}
<ul>
{#accounts}
<li>Account Number : {accountNumber}</li>
{/accounts}
</ul>
{:else}
<p class="error">No accounts for this user.</p>
{/accounts}
</div>
... then bind a model such as the following (which can be returned by your service):
{
id : '123456',
name : 'TheBeatlemaniac',
accounts : [
{ accountNumber : 'FOO1234' },
{ accountNumber : 'BAR1234' },
{ accountNumber : 'FOB1234' }
]
}
... and that will automatically render markup like so:
<div id="123456">
<h1>TheBeatlemaniac</h1>
<ul>
<li>Account Number : FOO1234</li>
<li>Account Number : BAR1234</li>
<li>Account Number : FOB1234</li>
<ul>
</div>
... and finally, you can slap that onto your main view container as you so please.
There are definitely other ways to do what you want to do, but I'm recommending this on the rationale that it's (generally) lighter on your bandwidth, because all you have to return back is (for example) JSON data corresponding to your model. If you request data from the service, and it returns fixed HTML markup with just key changes, the redundancy quickly adds up. You let the server-side code release some of its supposedly necessary processing, so that may be a good thing.