Django Autocomplete-light with mutiple apps - django-autocomplete-light

I'm using Python 3.4 Django 1.7. My project includes 3 applications that have similar models for example:
I have an ElectricityBill application with:
Account, Meter, Invoice models.
I also have a NaturalGasBill application with:
Account, Meter, Invoice models.
When I register my autocompletes, (Same with both applications), the second will always replace the first.. for example.. when I goto localhost/autocomplete I get this:
InvoiceAutocomplete /autocomplete/InvoiceAutocomplete/
AccountAutocomplete /autocomplete/AccountAutocomplete/
MeterAutocomplete /autocomplete/MeterAutocomplete/
Obviously, there is nothing unique about these urls to indicate which application the url should apply.
Does anyone have a solution for this?

Found this in the documentation:
# Extra **kwargs are used as class properties in the subclass.
autocomplete_light.register(SomeModel,
# SomeModel is already registered, re-register with custom name
name='AutocompleSomeModelNew',
# Filter the queryset
choices=SomeModel.objects.filter(new=True))
A link to the documentation is here: https://django-autocomplete-light.readthedocs.org/en/docs_rewrite/cookbook.html
Registering the autocomplete with a custome name is exactly what I was looking for. It is unfortunate this was so difficult to find in the documentation.

Related

Shopware 6 add entity extension fields to admin search

I wonder how to make some fields of an entity extension searchable in the administration through the "/api/search/my-entity" api-endpoint. By default they are not considered during search as it looks like.
I found the answer by debugging the search-endpoint:
The association-Field of the EntityExtension needs to have a SearchRanking-flag:
...->addFlags(new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING))
Then you can add SearchRanking-flags in the EntityExtensionDefinition as you like, e.g.:
(new StringField('test', 'test'))->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
After that the fields are searchable via the search-endpoint :)
As far as the API is concerned, search functionality should automatically be generated following your custom entity definitions.
When it comes to facilitate Admin search for your entity, you need to add some code to the administration component as described in the docs: https://developer.shopware.com/docs/guides/plugins/plugins/administration/search-custom-data (even though it looks not fully up-to-date w.r.t to the current Shopware versions).

document multiple version of API using swaggydoc on grails with same controller name under separate directory

I'm using swaggydoc plugin on my grails application to document the REST APIs. I have two versions of API, v0 and v1 and corresponding controllers with same name, one for each version like:
directory structure
and i have the Url mapping like "/my2api/v1"(controller:"api",namespace:'v1')
"/myapi/v0" (controller:"api", namespace:'v0')
and getting both versions of the API endpoints listed as /myapi/v0/activeContracts like here.
So my question is, how can I get the API end point listed with correct URLs with corresponding versions like /myapi/v0/activeContracts & /myapi/v1/activeContracts as i mentioned I've tried the mapping but it ill just pickup the first the last mapping and assign it to both versions.
Any help would be greatly appreciated.
For people facing the same prob, I couldn't find a solution using swaggyDocs and also came across some post suggesting it doesn't support API versioning so ended up switching to Grails RestApiDoc which provides a lot more control (changing the API conf by just editing the json) than I was able to get on swaggyDocs. But please do post if someone knows a way to work it out in swaggyDoc.

URI-based Versioning for AWS API Gateway

I am struggling to understand how AWS API Gateway wants me to organise my APIs such that versioning is straightforward. For example, let's say I have a simple API for getting words from a dictionary, optionally filtering the results by a query parameter. I'd like to have v1 of this be available at:
https://<my-domain>/v1/names?starts-with=<value>
However, the closest I can get API Gateway is at
https://<my-domain>/names/v1?starts-with=<value>
... which is quite backwards.
What I've got in the console is "Names API" with a "v1" resource supporting a GET method. I also have my custom domain setup to map a base path of "names" to "Names API" and stage "test". The Base path must be unique so putting "v1" there is only a short-term win; once I create my second API (e.g. Numbers API) it'll have a v1, too, and I won't be able to create a second mapping.
Any and all help is greatly appreciated as I'm out of ideas now.
Do not create the version path (/v1) as a resource in your API. Instead, simply call you API "Names V1" and start creating the resources (/names). When you want to make a breaking change and create a new version of the API, we recommend you create an entirely new API called "Names V2". Once again, simply create your resources without the version path.
To bring the two APIs together, you can use custom domain names. A custom domain name in API Gateway includes both a fully qualified domain name and a base path. Create two custom domain names:
myapi.com/v1 -> points to the prod stage of the Names V1 API
myapi.com/v2 -> points to the prod stage of the Names V2 API
This way you can keep bug-fixing v1 while making changes to v2 and deploy the two APIs independently. The custom domain name will bring them together and make them appear under the same domain (myapi.com/v2/names).
Hope this helps.

Jira SOAP API custom field

Hi I'm am trying to get the list of issues from a JIRA server using the SOAP API provided by JIRA.
I'm trying to filter the issues based on a custom field (and latter I will want to set that custom field).
If I get the list of issue it returns the custom fields for those issues along with them (I get customfieldId, key, values for each custom field) and I can get the custom field with getCustomFields methods provided by the API (to look for the ID of the field with a given name).
The issue I have is that if I login with an account that is not an admin (using the API) I can't call the getCustomFields method (it throws an exception saying I have to be an admin to do that).
My question is: Is there any other way to know which is the ID of the custom field I desire that can be done using a normal user account?
Also if you know how to set a custom field for an issue, it would also be very helpful :) (I would also like to be able to do it with a regular user account).
You have to be an admin to get a list of custom fields. Any 'normal' account can act on the custom fields via the API provided the user knows the customfield ID.
You can set the value of a custom field too, even with a 'normal' account. Again, the user needs the appropriate permissions to do this. Example provided here.
More here and here.
You can also use getFieldsForEdit(token, issueKey), which will return RemoteField[] for all fields available for edit on that issue (even if it has not yet been defined on the issue). It does not require admin permissions, but because it has the word "Edit" in the method, it does require that you have permission to edit the issue (which means, e.g., if the issue is status=Closed, it will raise an exception unless you allow editing closed issues. Unfortunately, I have yet to find a way to retrieve the RemoteField[] list (in order to map id to name), so getCustomFields() and getFieldsForEdit() appear to be the only options.
Have you tried getting a list of issues from the project, picking one, zeroing out the data, and using that as a template? That might work.
SOAP is being deprecated in favor of the REST API, which also has a better method to get this information

How is the Trac Project List page customised?

We've been using Trac for a while now for our developers only. However we are now opening it up for our (internal) clients. We have a project listing page (based on the default one that comes with Trac). What we'd like to do, is display more information about the project than what is currently available.
I have searched google and here, to see if I can find how to get more information. There seems to be a variable called $project which has .name, .description and .href as attributes.
Is there somewhere, a list of the attributes available? Or perhaps a different solution altogether that will allow us to display more information on the project list page. Such as the number of open tickets etc.
As far as I known, you can use $project.env as well. It is an object, which provides a number of attributes:
$project.env.base_url
$project.env.base_url_for_redirect
$project.env.secure_cookies
$project.env.project_name
$project.env.project_description
$project.env.project_url
$project.env.project_admin
$project.env.project_admin_trac_url
$project.env.project_footer
$project.env.project_icon
$project.env.log_type
$project.env.log_file
$project.env.log_level
$project.env.log_format
More detail is available at env.py
On the project page customization page there is not much variables, indeed. Looking at the source code there is also trac.version, trac.time, but that's all. There is also project.env that may hold more information. I do not have a multiproject setup at hand, so you might be interested to see for yourself what variables are available with TracDeveloper plugin. It dumps variables if enabled and you add debug=true in the URL.