A simpler way to view django projects
have the app stuff ready for tree
5 files changed, +25 -156
+0-68resources/models.svg
| @@ -1,68 +0,0 @@ | ||
| 1 | -<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| 2 | -<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> | |
| 3 | - | |
| 4 | -<svg | |
| 5 | - width="24" | |
| 6 | - height="24" | |
| 7 | - viewBox="0 0 0.72 0.72" | |
| 8 | - fill="none" | |
| 9 | - version="1.1" | |
| 10 | - id="svg12" | |
| 11 | - sodipodi:docname="models.svg" | |
| 12 | - inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)" | |
| 13 | - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | |
| 14 | - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | |
| 15 | - xmlns="http://www.w3.org/2000/svg" | |
| 16 | - xmlns:svg="http://www.w3.org/2000/svg"> | |
| 17 | - <defs | |
| 18 | - id="defs16" /> | |
| 19 | - <sodipodi:namedview | |
| 20 | - id="namedview14" | |
| 21 | - pagecolor="#ffffff" | |
| 22 | - bordercolor="#666666" | |
| 23 | - borderopacity="1.0" | |
| 24 | - inkscape:pageshadow="2" | |
| 25 | - inkscape:pageopacity="0.0" | |
| 26 | - inkscape:pagecheckerboard="0" | |
| 27 | - showgrid="false" | |
| 28 | - inkscape:zoom="1.0125" | |
| 29 | - inkscape:cx="400" | |
| 30 | - inkscape:cy="320.98765" | |
| 31 | - inkscape:window-width="1920" | |
| 32 | - inkscape:window-height="988" | |
| 33 | - inkscape:window-x="0" | |
| 34 | - inkscape:window-y="24" | |
| 35 | - inkscape:window-maximized="1" | |
| 36 | - inkscape:current-layer="svg12" /> | |
| 37 | - <g | |
| 38 | - id="g31" | |
| 39 | - transform="matrix(0.03348837,0,0,0.03348837,-0.04186044,-0.04186044)"> | |
| 40 | - <path | |
| 41 | - d="M 4,18 V 6" | |
| 42 | - stroke="#1c274c" | |
| 43 | - stroke-width="1.5" | |
| 44 | - stroke-linecap="round" | |
| 45 | - id="path2" /> | |
| 46 | - <path | |
| 47 | - d="M 20,6 V 18" | |
| 48 | - stroke="#1c274c" | |
| 49 | - stroke-width="1.5" | |
| 50 | - stroke-linecap="round" | |
| 51 | - id="path4" /> | |
| 52 | - <path | |
| 53 | - d="M 12,10 C 16.4183,10 20,8.20914 20,6 20,3.79086 16.4183,2 12,2 7.58172,2 4,3.79086 4,6 c 0,2.20914 3.58172,4 8,4 z" | |
| 54 | - stroke="#1c274c" | |
| 55 | - stroke-width="1.5" | |
| 56 | - id="path6" /> | |
| 57 | - <path | |
| 58 | - d="m 20,12 c 0,2.2091 -3.5817,4 -8,4 -4.41828,0 -8,-1.7909 -8,-4" | |
| 59 | - stroke="#1c274c" | |
| 60 | - stroke-width="1.5" | |
| 61 | - id="path8" /> | |
| 62 | - <path | |
| 63 | - d="m 20,18 c 0,2.2091 -3.5817,4 -8,4 -4.41828,0 -8,-1.7909 -8,-4" | |
| 64 | - stroke="#1c274c" | |
| 65 | - stroke-width="1.5" | |
| 66 | - id="path10" /> | |
| 67 | - </g> | |
| 68 | -</svg> |
+0-46resources/settings.svg
| @@ -1,46 +0,0 @@ | ||
| 1 | -<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| 2 | -<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> | |
| 3 | - | |
| 4 | -<svg | |
| 5 | - fill="#000000" | |
| 6 | - height="24" | |
| 7 | - width="24" | |
| 8 | - version="1.1" | |
| 9 | - id="Capa_1" | |
| 10 | - viewBox="0 0 1.62 1.62" | |
| 11 | - xml:space="preserve" | |
| 12 | - sodipodi:docname="settings.svg" | |
| 13 | - inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)" | |
| 14 | - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | |
| 15 | - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | |
| 16 | - xmlns="http://www.w3.org/2000/svg" | |
| 17 | - xmlns:svg="http://www.w3.org/2000/svg"><defs | |
| 18 | - id="defs11" /><sodipodi:namedview | |
| 19 | - id="namedview9" | |
| 20 | - pagecolor="#ffffff" | |
| 21 | - bordercolor="#666666" | |
| 22 | - borderopacity="1.0" | |
| 23 | - inkscape:pageshadow="2" | |
| 24 | - inkscape:pageopacity="0.0" | |
| 25 | - inkscape:pagecheckerboard="0" | |
| 26 | - showgrid="false" | |
| 27 | - inkscape:zoom="32.416667" | |
| 28 | - inkscape:cx="12" | |
| 29 | - inkscape:cy="12" | |
| 30 | - inkscape:window-width="1920" | |
| 31 | - inkscape:window-height="988" | |
| 32 | - inkscape:window-x="0" | |
| 33 | - inkscape:window-y="24" | |
| 34 | - inkscape:window-maximized="1" | |
| 35 | - inkscape:current-layer="Capa_1" /> | |
| 36 | -<g | |
| 37 | - id="g6" | |
| 38 | - transform="scale(0.03)"> | |
| 39 | - <path | |
| 40 | - d="m 51.22,21 h -5.052 c -0.812,0 -1.481,-0.447 -1.792,-1.197 -0.311,-0.75 -0.153,-1.54 0.42,-2.114 l 3.572,-3.571 c 0.525,-0.525 0.814,-1.224 0.814,-1.966 0,-0.743 -0.289,-1.441 -0.814,-1.967 L 43.815,5.632 c -1.05,-1.05 -2.881,-1.052 -3.933,0 L 36.311,9.203 C 35.737,9.776 34.945,9.936 34.197,9.624 33.447,9.313 33,8.644 33,7.832 V 2.78 C 33,1.247 31.753,0 30.22,0 H 23.78 C 22.247,0 21,1.247 21,2.78 v 5.052 c 0,0.812 -0.447,1.481 -1.197,1.792 -0.748,0.313 -1.54,0.152 -2.114,-0.421 L 14.118,5.632 c -1.052,-1.052 -2.883,-1.05 -3.933,0 l -4.553,4.553 c -0.525,0.525 -0.814,1.224 -0.814,1.967 0,0.742 0.289,1.44 0.814,1.966 l 3.572,3.571 c 0.573,0.574 0.73,1.364 0.42,2.114 C 9.314,20.553 8.644,21 7.832,21 H 2.78 C 1.247,21 0,22.247 0,23.78 v 6.439 C 0,31.753 1.247,33 2.78,33 h 5.052 c 0.812,0 1.481,0.447 1.792,1.197 0.311,0.75 0.153,1.54 -0.42,2.114 l -3.572,3.571 c -0.525,0.525 -0.814,1.224 -0.814,1.966 0,0.743 0.289,1.441 0.814,1.967 l 4.553,4.553 c 1.051,1.051 2.881,1.053 3.933,0 l 3.571,-3.572 c 0.574,-0.573 1.363,-0.731 2.114,-0.42 0.75,0.311 1.197,0.98 1.197,1.792 v 5.052 c 0,1.533 1.247,2.78 2.78,2.78 h 6.439 c 1.533,0 2.78,-1.247 2.78,-2.78 v -5.052 c 0,-0.812 0.447,-1.481 1.197,-1.792 0.751,-0.312 1.54,-0.153 2.114,0.42 l 3.571,3.572 c 1.052,1.052 2.883,1.05 3.933,0 l 4.553,-4.553 c 0.525,-0.525 0.814,-1.224 0.814,-1.967 0,-0.742 -0.289,-1.44 -0.814,-1.966 L 44.795,36.311 C 44.222,35.737 44.065,34.947 44.375,34.197 44.685,33.447 45.356,33 46.168,33 H 51.22 C 52.753,33 54,31.753 54,30.22 V 23.78 C 54,22.247 52.753,21 51.22,21 Z M 52,30.22 C 52,30.65 51.65,31 51.22,31 h -5.052 c -1.624,0 -3.019,0.932 -3.64,2.432 -0.622,1.5 -0.295,3.146 0.854,4.294 l 3.572,3.571 c 0.305,0.305 0.305,0.8 0,1.104 l -4.553,4.553 c -0.304,0.304 -0.799,0.306 -1.104,0 L 37.726,43.382 C 36.577,42.233 34.932,41.908 33.432,42.528 31.932,43.149 31,44.544 31,46.168 V 51.22 C 31,51.65 30.65,52 30.22,52 H 23.78 C 23.35,52 23,51.65 23,51.22 v -5.052 c 0,-1.624 -0.932,-3.019 -2.432,-3.64 -0.503,-0.209 -1.021,-0.311 -1.533,-0.311 -1.014,0 -1.997,0.4 -2.761,1.164 l -3.571,3.572 c -0.306,0.306 -0.801,0.304 -1.104,0 L 7.046,42.4 c -0.305,-0.305 -0.305,-0.8 0,-1.104 l 3.572,-3.571 c 1.148,-1.148 1.476,-2.794 0.854,-4.294 C 10.851,31.932 9.456,31 7.832,31 H 2.78 C 2.35,31 2,30.65 2,30.22 V 23.78 C 2,23.35 2.35,23 2.78,23 h 5.052 c 1.624,0 3.019,-0.932 3.64,-2.432 0.622,-1.5 0.295,-3.146 -0.854,-4.294 L 7.046,12.703 c -0.305,-0.305 -0.305,-0.8 0,-1.104 l 4.553,-4.553 c 0.304,-0.305 0.799,-0.305 1.104,0 l 3.571,3.571 c 1.147,1.147 2.792,1.476 4.294,0.854 C 22.068,10.851 23,9.456 23,7.832 V 2.78 C 23,2.35 23.35,2 23.78,2 h 6.439 C 30.65,2 31,2.35 31,2.78 v 5.052 c 0,1.624 0.932,3.019 2.432,3.64 1.502,0.622 3.146,0.294 4.294,-0.854 l 3.571,-3.571 c 0.306,-0.305 0.801,-0.305 1.104,0 l 4.553,4.553 c 0.305,0.305 0.305,0.8 0,1.104 l -3.572,3.571 c -1.148,1.148 -1.476,2.794 -0.854,4.294 0.621,1.5 2.016,2.432 3.64,2.432 H 51.22 C 51.65,23 52,23.35 52,23.78 Z" | |
| 41 | - id="path2" /> | |
| 42 | - <path | |
| 43 | - d="m 27,18 c -4.963,0 -9,4.037 -9,9 0,4.963 4.037,9 9,9 4.963,0 9,-4.037 9,-9 0,-4.963 -4.037,-9 -9,-9 z m 0,16 c -3.859,0 -7,-3.141 -7,-7 0,-3.859 3.141,-7 7,-7 3.859,0 7,3.141 7,7 0,3.859 -3.141,7 -7,7 z" | |
| 44 | - id="path4" /> | |
| 45 | -</g> | |
| 46 | -</svg> |
+15-5src/context.ts
| @@ -1,15 +1,16 @@ | ||
| 1 | 1 | import * as vscode from "vscode"; |
| 2 | 2 | import * as path from "path"; |
| 3 | 3 | import * as fs from "fs"; |
| 4 | +import DjangoProject from "./project"; | |
| 4 | 5 | |
| 5 | 6 | export const setDjangoContext = async () => { |
| 6 | 7 | const workspaceFolders = vscode.workspace.workspaceFolders; |
| 7 | - if (vscode.workspace.getConfiguration("django-overview").get("projectDir")) { | |
| 8 | - return; | |
| 9 | - } | |
| 10 | - if (workspaceFolders) { | |
| 8 | + let dir = vscode.workspace | |
| 9 | + .getConfiguration("django-overview") | |
| 10 | + .get("projectDir") as string; | |
| 11 | + if (workspaceFolders && !dir) { | |
| 11 | 12 | for (const folder of workspaceFolders) { |
| 12 | - const dir = folder.uri.fsPath; | |
| 13 | + dir = folder.uri.fsPath; | |
| 13 | 14 | const isDjango = await isDjangoProject(dir); |
| 14 | 15 | const inDjango = isDjango || (await isInDjangoProject(path.dirname(dir))); |
| 15 | 16 | if (isDjango || inDjango) { |
| @@ -27,6 +28,15 @@ export const setDjangoContext = async () => { | ||
| 27 | 28 | null |
| 28 | 29 | ); |
| 29 | 30 | } |
| 31 | + if (dir) { | |
| 32 | + const project = new DjangoProject(dir); | |
| 33 | + await project.read(); | |
| 34 | + vscode.commands.executeCommand( | |
| 35 | + "setContext", | |
| 36 | + "django-overview.project", | |
| 37 | + project | |
| 38 | + ); | |
| 39 | + } | |
| 30 | 40 | }; |
| 31 | 41 | |
| 32 | 42 | const isDjangoProject = async (dir: string): Promise<boolean> => { |
+6-13src/project.ts
| @@ -12,6 +12,7 @@ type Field = { | ||
| 12 | 12 | name: string; |
| 13 | 13 | type: string; |
| 14 | 14 | index: number; |
| 15 | + raw: string; | |
| 15 | 16 | }; |
| 16 | 17 | |
| 17 | 18 | type Model = { |
| @@ -48,14 +49,12 @@ if spec is not None and spec.origin is not None: | ||
| 48 | 49 | `; |
| 49 | 50 | try { |
| 50 | 51 | const result = childProcess |
| 51 | - .execSync(`${pythonPath} -c "${pythonScript}"`) | |
| 52 | + .execSync(`${pythonPath} -c "${pythonScript}" 2>/dev/null`) | |
| 52 | 53 | .toString(); |
| 53 | 54 | this.path = result.trim(); |
| 54 | 55 | } catch (error) { |
| 55 | - console.error(error); | |
| 56 | 56 | throw new Error(`Error getting path for app ${this.name}`); |
| 57 | 57 | } |
| 58 | - console.log(`Reading models.py for app ${this.name}`); | |
| 59 | 58 | try { |
| 60 | 59 | const data = fs.readFileSync(`${this.path}/models.py`, "utf-8"); |
| 61 | 60 | const models = data.matchAll(regex.model); |
| @@ -71,14 +70,13 @@ if spec is not None and spec.origin is not None: | ||
| 71 | 70 | name: fieldMatch[1], |
| 72 | 71 | type: fieldMatch[2], |
| 73 | 72 | index: fieldMatch.index || 0, |
| 73 | + raw: fieldMatch[0], | |
| 74 | 74 | }; |
| 75 | 75 | model.fields.push(field); |
| 76 | 76 | } |
| 77 | 77 | this.models.push(model); |
| 78 | 78 | } |
| 79 | - console.log(models); | |
| 80 | 79 | } catch (err) { |
| 81 | - console.error(`Error reading models.py for app ${this.name}`); | |
| 82 | 80 | // throw new Error(`Error reading models.py for app ${this.name}`); |
| 83 | 81 | } |
| 84 | 82 | } |
| @@ -119,14 +117,9 @@ export default class DjangoProject { | ||
| 119 | 117 | const appContainer = appContainerMatch ? appContainerMatch[1] : ""; |
| 120 | 118 | const apps = appContainer.matchAll(regex.module); |
| 121 | 119 | for (const app of apps ? apps : []) { |
| 122 | - this.apps.push(new App(app[1])); | |
| 120 | + try { | |
| 121 | + this.apps.push(new App(app[1])); | |
| 122 | + } catch {} | |
| 123 | 123 | } |
| 124 | - console.log(apps); | |
| 125 | 124 | } |
| 126 | 125 | } |
| 127 | - | |
| 128 | -export const getProject = async () => {}; | |
| 129 | - | |
| 130 | -export const getAvailableApps = async () => { | |
| 131 | - const projectDir = getDjangoProjectDir(); | |
| 132 | -}; |
+4-24src/providers/project.ts
| @@ -10,39 +10,19 @@ export default class ProjectDataProvider | ||
| 10 | 10 | getChildren(element?: vscode.TreeItem): Thenable<vscode.TreeItem[]> { |
| 11 | 11 | if (element === undefined) { |
| 12 | 12 | // Return the root items |
| 13 | - return Promise.resolve([ | |
| 14 | - new vscode.TreeItem( | |
| 15 | - "Item 1", | |
| 16 | - vscode.TreeItemCollapsibleState.Collapsed | |
| 17 | - ), | |
| 18 | - new vscode.TreeItem( | |
| 19 | - "Item 2", | |
| 20 | - vscode.TreeItemCollapsibleState.Collapsed | |
| 21 | - ), | |
| 22 | - new vscode.TreeItem( | |
| 23 | - "Item 3", | |
| 24 | - vscode.TreeItemCollapsibleState.Collapsed | |
| 25 | - ), | |
| 26 | - ]); | |
| 13 | + return Promise.resolve([this.createModelsTreeItem()]); | |
| 27 | 14 | } else { |
| 28 | 15 | // Return the child items for the given parent item |
| 29 | 16 | return Promise.resolve([ |
| 30 | - this.createSettingsTreeItem(), | |
| 31 | 17 | new vscode.TreeItem("Subitem 2"), |
| 32 | 18 | new vscode.TreeItem("Subitem 3"), |
| 33 | 19 | ]); |
| 34 | 20 | } |
| 35 | 21 | } |
| 36 | 22 | |
| 37 | - private createSettingsTreeItem(): vscode.TreeItem { | |
| 38 | - const treeItem = new vscode.TreeItem("Settings"); | |
| 39 | - treeItem.checkboxState = { | |
| 40 | - state: vscode.TreeItemCheckboxState.Checked, | |
| 41 | - }; | |
| 42 | - treeItem.command = { | |
| 43 | - command: "django-overview.openSettings", | |
| 44 | - title: "Open Settings", | |
| 45 | - }; | |
| 23 | + private createModelsTreeItem(): vscode.TreeItem { | |
| 24 | + const treeItem = new vscode.TreeItem("Models"); | |
| 25 | + treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed; | |
| 46 | 26 | return treeItem; |
| 47 | 27 | } |
| 48 | 28 | } |