is there any way to add a description / hint to the field in the mongoengine model?
I have a situation when inline comments are entered before the line with the definition of the field, because it is not possible to explain the full meaning of this field only with name.
I'm not sure if that's really better but you can take advantage of the **kwargs of the Field constructor like this
class FunkyDoc(Document):
s = StringField(required=True, custom_doc="Lorem ipsum blablablablabla")
Unknown parameters aren't taken into account so this won't interfer with MongoEngine internals
Related
I'm wondering if it's possible to describe a format, that an interface property should have. For example:
interface User {
age?: number,
name: string,
birthdate: string // should have format 'YYYY-MM-DD'
}
I read about decorators but it seems to only apply to classes, not interfaces.
I'm building an API with node/express and want to have input validation. So I'm considering Celebrate which can take joi type Schema to validate input. But I would like to use TypeScript instead to define my Schema / view model... As you see I try to use an Interface to define how the input of a given end point should look like:
age: number, optional
name: string
birthdate: string in format "YYYY-MM-DD"
Any hints and help much appreciated :)
Any hints and help much appreciated :)
First and foremost : you will have to write code for the validation. It will not happen magically.
Two approaches:
Out of band validation
You use validate(obj) => {errors?}. You create a validate function that takes and object and tells you any errors if any. You can write such a function yourself quite easily.
In band validation
Instead of {birthdate:string} you have something like {birthdate:FieldState<string>} where FieldState maintains validations and errors for a particular field. This is approach taken by https://formstate.github.io/#/ but you can easily create something similar yourself.
A note on validators
I like validators as simple (value) => error? (value to optional error) as they can be framework agnostic and used / reused to death. This is the validator used by formstate as well. Of course this is just my opinion and you can experiment with what suits your needs 🌹
I am confused about wiring up my own datasource to the Kendo Scheduler. I looked at their API and I'm still confused. For instance, I see it says the start and the end are required, but are they the names of the fields in my dataset? They can't be mapped to another name?
My dataset has some other details as well as a date in the format, "2016-10-20T00:00:00." Is this going to work?
Can someone tell me if the actual field names from the DB/JSON are literally the same as in Telerik's docs? For instance, my date field isn't called "Start" and End. It's something else, and I don't even have an end, and I don't have starttimezone and endtimezone, are these all needed?
Another question I have is: I'm not limited to just the fields from their documentation am I? I have a datasource that has other things, for instance, we don't have "title," we have something else. And riding off that question, I'm hoping that when I call the pop up when the user double clicks on a time/day or event, that I can customize what fields I want to appear.
The other question is: What is the "from" attribute/property for? For instance
end: { type: "date", from: "End" },
Thanks
My two cents on this:
I think the options "Title", "Start" and "End" are the ones that are always needed on the dataSource. "startTimezone" and "endTimezone" are not always needed.
I also think that the "from" attribute/property is a reference to from where you are getting that data. I mean, which field from the database guards a specific information.
You can also have your own custom fields to the model, as long as they came from a valid field from the database and as long as they have an correspondent and valid datatype value.
At last but not the least, you can also customize what fields you can make appear once you do double-click and the pop-up window shows up. For that, you must use your own template for a custom pop-up editor.
Hope this gives you some insight.
Thanks for the help. I figured out the core issue with the error. It was a matter of me tweaking my schema model.
I finished tutorial 1-4 at http://django-rest-framework.org/tutorial/4-authentication-and-permissions.html and got the code run.
However, I am not fully understand the explanation around:
owner = serializers.Field(source='owner.username')
I am confused by which field refering to which field.
1.For example, there is an owner field defined in Snippet class in models.py. After looking it up at https://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey, it says ForeignKey() returns a class. Does it return the auth.User class?
2.If it does, what "owner" does the
owner = serializers.Field(source='owner.username')
refer to? I do not found owner in the import part of serializers.py.
3.What does serializers.Field(source='owner.username') returns? Does it return the username in the auth.User?
4.Should we add the corresponding field in a serializer class if the corresponding model has a field reference to another table?
source = 'owner.username' will translate to 'user.username' since owner is nothing but FK-User.
Please note that 'owner' on the left side of field is not important here, in your case. i.e, you can still add custom fields like,
xyz = serializers.Field(source='owner.username')
I have a content type called Author which is referred in another two content types called Novel and Book via Node Reference Module.So we can add author entity to both Book and Novel content types.
Both Novel and Book contain another field called Release Date.
Now I want to show a block which will display the name of book and name of novel in chronological order based upon the release date when user come to that corresponding Author Page.
Ex. Suppose A is an author who is author of BookA(Release Yr-2006), NovelB(Release Yr-2004),BookC(Release Year-2009). When user come to Author A page then he will be shown a block which will show the Books/Albums in chronological order like this:-
NovelB--BookA--BookC
Please suggest as how to achieve in Drupal 7.
You want to display the following field title (I assume the book name is the node title)
For the sorting you can use the sort option in views, it is pretty self-explaining. Choose the name of your release date field.
For the connection between author and books you will have to use a contextual filter (advanced).
Add the author-reference-field from your book/novel (the field you use to refer to the author). Then choose to use a default value (2nd option) and choose content id from url. Now your block will find all nodes that refer to the page with the current page-id. Since we chose to display the title fields, you should see a list.
Note that live preview does not work here, so you will have to go to the actual page to see the result.
UPDATE:
This works when you have re-used the same field for both content types. If you have uses more then one field you will have to use an OR operator to make the contextual filter work. Thanks to d34dman the following page was given to do just that.
Although for new implementations I would recommend using the same field (eg. reference_to_author) for all references from all content types.
Yah..I am able to solve this problem by adding custom code. I have used hook_views_query_alter method and then added join relationship and where clause as per requirement. Please refer to following article for more clarity..
http://www.midwesternmac.com/blogs/jeff-geerling/filtersearch-multiple-fields
Thanks for posting the reply and keeping my hope alive.
I've created a dexterity content type that has a NamedBlobFile as one of the fields (users will upload a .pdf). I'd like to have full-text indexing on that pdf -- like the ATFile type -- but not sure what I have to do to make that happen.
I've installed collective.dexteritytextindexer and have gotten some of the other fields added to searchable text by doing this:
searchable('paper_author')
paper_author = schema.Text(title=_(u"Author"), required=False)
I'm not sure what to do for the file field. Suggestions?
I think using the searchable() directive should work for NameBlobFiles too.
There is a converter in collective.dexteritytextindexer taking care of transforming the file contents into text so that it is indexable (see the code at github), which also applies for blobs (since the INamedBlobFileField subclasses INamedFileField for which the adapter is registered).
If it does not work its a bug, so please create an issue at the collective.dexteritytextindexer issue tracker.
If the problem is that the field is not defined in your code and you cannot use the searchable directive, there is also a searchable function (import from .utils!) which can be used outside the scope of the schema like this:
from plone.app.dexterity.behaviors.metadata import IBasic
from collective.dexteritytextindexer.utils import searchable
searchable(IBasic, 'title')
searchable(IBasic, 'description')