This repo is going to be archived and later versions built in purely typescript. Repository found here.
Reads all urls configurations (urls.py
) declared in all Django projects within a VSCODE workspace and copy to clipboard.
✨✨Introducing settings for the extension ✨✨
Models in the project are now automatically detected by the extension.
You can now switch between keyword and positional arguments in settings for your urls. Built-in auth/django.contrib.auth
URL configurations can be included or not depending on settings usingbuiltInAuth: true
Gives the option of copying the url as reverse, reverse_lazy or as a template tag to your clipboard.
Install from here.
Jump to:
• Usage.
• Settings.
• Custom Url configurations.
• Creating Custom URL configurations.
• Using ModelAdmin
urls.
• Multiple Django folders support.
The extension adds a view on your side bar with an icon like a chain 🔗. Navigate to that view and click to open it and activate the extension.
Give it a few moments to read all urls and populate the view. Once done it will populate the view with your URL configurations.
Each app will be a collapsable tree with its urls as the children. App names are in ALL CAPS. If an app has no app_name
it will be displayed in the following format PARENT_FOLDER\URLS.PY
.
A url may have children if it's arguments are defined.
If not the it's a single item.
On hovering over a url name, there are three buttons (from left to right).
- Copy 'reverse' url.
- Copy 'reverse_lazy' url.
- Copy as a template tag.
All three copy to clipboard and can be pasted in your code, all you need to change is names of the arguments to match you namespace (The arguments are surrounded by '%' to make sure your editor or linter catches it to remind you to change it).
The three are copied using keyword arguments i.e. kwargs to switch to positional arguments i.e. args add urlWithKeywords: false
to settings.
The extension now has settings. They live inside .vscode/urlConfigs/settings.json
inside in your project. They are on a project by project basis. If you have two projects in one workspace, each project shall have it's own sets of settings.
Options for settings are explained below showing an example .vscode/urlConfigs/settings.json
file;
{
"adminUrls": true,
"autoLoadModels": true,
"registeredAppsOnly": false,
"builtInAuth": false,
"expandApps": "normal",
"urlWithKeywords": true
}
adminUrls
[Boolean]:true
to show admin site urls configurations andfalse
to not show.autoLoadModels
[Boolean]:true
to automatically discover models andfalse
to use just.vscode/urlConfigs/models.json
(the traditional approach).registeredAppsOnly
[Boolean]: Automatically detect models from registered apps only. Default isfalse
.builtInAuth
[Boolean]:true
to show url configurations from the built-in authentication sytem i.e.django.contrib.auth.urls
orfalse
to not.expandApps
[String]: Collapse or expand the Apps to show urls. Choices are 3;collapsed
,expanded
ornormal
. normal is the default.urlWithKeywords
[Boolean]: The reverse & reverse_lazy functions and url template tag use keywords arguments iftrue
and positional arguments iffalse
i.e. args or kwargs. The default is true.
expandApps
requires a window reload to show changes
Sometimes you need 3rd party apps in your project which may have URL configurations. These configurations can be described in a JSON file named in the format; 'app.conf.json
'. These files are saved in '.vscode/urlConfigs/
' folder in the root of your project to allow the extension to find them. They are combined with your project's configurations. To describe the URL configurations click here.
The extension comes pre-loaded with the
AdminSite
,ModelAdmin
,django.contrib.auth
andUserAdmin
configurations.
To turn off AdminSite, ModelAdmin and UserAdmin, addadminUrls: false
to settings. To turn ondjango.contrib.auth
URL configurations, addbuiltInAuth: true
to settings.
The JSON file, named in the format described in the previous section, contains a list/array of Whole app configurations. i.e. Your whole project, no matter home many apps/urls.py there are, would be added to one *.conf.json
file. Say there are three apps in your project, api
, store
, billing
, they can be described in one file or a separate file for each.
Custom configurations appear at the top and are collapsed by default.
Each app entry, in the array of apps, is an object with two properties:
-
appName
[String]: A string with the name of the app. (Note this is not the usualapp_name
declared in theurls.py
. It will just appear as the title in our URl configurations view). -
urls
[Array]: An array of url configurations objects for that app. If no URL configurations leave as an empty array[]
. A url configuration object is in the following format:-
reverseName
[String]: This is the actual reverse name. If the app has anapp_name
and the name of the url isindex
, enter this asapp_name:index
. If noapp_name
enter asindex
. -
arguments
[Array]: An array of a URL configuration parameters object. If there are no arguments leave this an empty array[]
. These objects are in the format:name
[String]: The name of the parameter as described in theurls.py
file.argType
[String]: The type of the parameter. Options are either: string, slug, uuid, integer.
-
viewName
[String]: The name of the view that handles that URL. -
hasArgs
[Boolean]:false
ifarguments
/ entry 2 above is empty and vice versa.
-
To load changes click the reload button.
[
{
"appName": "example",
"urls": [
{
"reverseName": "url1",
"arguments": [
{
"name": "name",
"argType": "string"
},
{
"name": "name_2",
"argType": "slug"
}
],
"viewName": "views.example_1",
"hasArgs": true
},
{
"reverseName": "url2",
"arguments": [],
"viewName": "views.example_2",
"hasArgs": false
}
]
},
{
"appName": "example_app_2",
"urls": [
{
"reverseName": "url3",
"arguments": [],
"viewName": "views.example_3",
"hasArgs": false
}
]
}
]
Incase of incorrect configurations, the file is ignored.
Check out the admin configurations file🧐.
Models in your project are AUTOMATICALLY detected by the extension. This option is enabled by default, to turn off add autoLoadModels: false
to settings. To add more models, third party models or others, add an object in .vscode/urlConfigs/models.json
with properties as app_labels (peak into apps.py
) and a list of model names.
To load changes click the reload button.
Changes to detect models automatically are in development.
Models can now be automatically detected.
{
"app_label": ["model1", "model2"],
"app_label_2": ["model3"]
}
*The extension detects models if you use the built-in django.contrib.admin
and have admin.py
or /admin/__init__.py
in your apps. Support for others coming soon :)
The extension now supports multiple projects in one workspace. Once you add a folder to the workspace, reload the window to view changes.
• Created by Muremwa.
• Copying to clipboard made possible by clipboardy.
• Released under the MIT License.