Accessing fields in alpaca forms from external source - python

I am trying to integrate an HTML page, built using alpaca forms, with an external python server. Ideally, I'd use websockets to pass a key and value, which would then populate the corresponding field in the alpaca form. I've not been able to find an example of how to do this, so 1) Is it possible? and 2) are there any examples floating around out there?
Thanks...

I think you should be able to do that with $("#form").alpaca("get"), that will provide you the form, then ou can access your field in the object, with something like : field.getControlByPath. Once you got your field you can easily modify his .data or something like that, you maybe will have to .refresh() your field after that.
Documentation :
- getControlByPath()

Related

How do I make a Python request for WordPress REST API to create a custom field?

For example, I have a post and I want to update it with tags and some custom field, like 'rating' or 'mood' (not using any plugin, only WP built-in options for custom fields and REST API).
r = requests.post(WP_url, params = {'tags': tags, 'rating': rating}, auth = wp_auth)
Something like this. It works great for updating existing post parameters and fields, but I cannot find a way to create a custom field using Python API requests only.
I don't think it is possible to create a new field from request. Its depend on you WP Rest API Server, how it handles the excess argument you, if you API create a new field for any excess provided then only it will be possible to create new field.

GraphQL: How do I define input parameters/constraints

I am looking for a way to include extra info in the schema so the API consumer knows what is expected. Think along the lines of a max length on a string or something. I expect this to be in the schema since that basically replaces the API documentation, right?
I have found this: https://github.com/confuser/graphql-constraint-directive which appears to be similar to what I want, however I don't need the implementation/enforcement since django does that already. I just want to communicate these constraints on input fields.
I am very new to this all, so is there maybe a concept of graphql I am missing? Or how do I add this kind of information in the schema?
EDIT: Maybe this is not only for documenting, but also to tell the frontend how to render fields and/or be able to do some frontend validation. Basically like an OPTIONS request or something.
If all you're looking to do is to document something about a specific field or type, you can set a description on either one. Adding a description doesn't seem to be outlined in the official docs, but there is this issue about it.
class MyType(graphene.ObjectType):
class Meta:
description = "Some description for MyType"
my_field = graphene.String(description="Some description for myField")

Is it possible to have a form built by a user?

For example:
I have a user that wants to create a contact form for their personal website. They want three input type=text and one textarea and they specify a label and an name/id for them on my site. Then they can use this form on their site, but I will handle it on mine?
Is it possible for django to spit out custom forms specified by the user?
Edit: If django is too "locked down" what would you recommend I do? I would like to stay with python.
something like http://code.google.com/p/django-forms-builder or one of the million similar addins?
(made into answer at OP's request)
For this you would have some kind of editor that would create a html string. This string would be stored into your database and then upon request you would display it on the user's site.
The editor should be very strict into what it can add and what the user has control over, there are some javascript editors available that will be able to provide this functionality.
The only issue I can think of is that you may run into django escaping the form when displayed to the page.

Storing/Retrieving/Editing project specific data with Django

I'm new to Django and I'm working on the public website for a small company.
I'm facing an issue that I guess has already been encountered by lots a django noobs,
but I can't manage to find a good solution.
My problem is that there some informations (contact address, office phone number, company description...) that I use in nearly all of my views and are by nature unique (undertand: a database table with only 1 row). I currently store these informations has a model in my databse, but I find it a bit weird issue an additional database request each time (each view)
I need to access them. However, I need my client to be able to edit these informations (by the admin interface).
So, please, is there a django idiom to handle such an use case ?
Thx in advance.
If you look into caching solutions, they will probably do what you need.
The general queryset caching solution I use in johnny-cache, but for what you need, you can probably just load it up from the db and store it in the cache.
What you want to do is use select_related('contact_profile','office_data') etc when you query the items in your view, and in the admin, instead of registering all the data separately just use the InlineAdmin class for the Admin site and you will be able to edit all the information as if it was a single entity.
Check out the django docs for more information.

cascading forms in Django/else using any Pythonic framework

Can anyone point to an example written in Python (django preferred) with ajax for cascading forms? Cascading Forms is basically forms whose field values change if and when another field value changes. Example Choose Country, and then States will change...
This is (mostly) front-end stuff.
As you may have noticed Django attempts to leave all the AJAX stuff up to you, so I don't think you'll find anything built in to do this.
However, using JS (which is what you'll have to do in order to do this without submitting a billion forms manually), you could easily have a django-base view your JS could communicate with:
def get_states(request, country):
# work out which states are available
#import simplesjon as sj
return sj....
Then bind your AJAX request to the onchange event of the select (I can't remember if that's right for select boxes) and populate the next field based on the return of the JSON query.
10 minute job with jquery and simplejson.
I would also suggest considering getting a mapping of all data once instead of requesting subfield values one by one. Unless the subfield choices change frequently (states/cities change?) or huge in numbers (>1000) this should offer best performance and it is less complex.
You don't even need to create a seperate view, just include a chunk of JavaScript (a JSON mapping more precisely) with your response containing the form.

Categories