Skip to content

Commit 4a7bb16

Browse files
author
Chris Proto
committed
Add a startplugin management command
To use:: >>> python manage.py startplugin {{ valid_app_name }} This command generates the following app structure: - plugin_name/__init__.py - plugin_name/admin.py - plugin_name/models.py - plugin_name/static/widgy/js/components/widgy.example/component.js - plugin_name/templates/widgy/widgy.example/example.html - plugin_name/tests.py
1 parent e1ea99b commit 4a7bb16

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

widgy/conf/plugin_template/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from {{ plugin_name }}.models import *
2+
from widgy.admin import WidgyAdmin
3+
4+
## Register Here ##
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
Models for Widgy plugin: {{ plugin_name }}
3+
"""
4+
from django.db import models
5+
from widgy.models import Content
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
define([ 'widgy.contents', 'widgets/widgets'
2+
], function(
3+
contents,
4+
widgets) {
5+
6+
var ContentView = widgets.WidgetView.extend({
7+
editorClass: widgets.EditorView
8+
});
9+
10+
var ExampleContent = contents.Content.extend({
11+
viewClass: ContentView
12+
});
13+
14+
return ExampleContent;
15+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="example">
2+
{{ content.content }}
3+
</div>

widgy/conf/plugin_template/tests.py

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from django.utils.importlib import import_module
2+
from django.core.management.templates import TemplateCommand
3+
from django.core.management.base import CommandError
4+
5+
6+
class Command(TemplateCommand):
7+
help = 'Create a new widgy plugin.'
8+
9+
def handle(self, app_name=None, target=None, **options):
10+
if app_name is None:
11+
raise CommandError("you must provide an app name")
12+
13+
# Check that the app_name cannot be imported.
14+
try:
15+
import_module(app_name)
16+
except ImportError:
17+
pass
18+
else:
19+
raise CommandError("%r conflicts with the name of an existing "
20+
"Python module and cannot be used as an app "
21+
"name. Please try another name." % app_name)
22+
23+
super(Command, self).handle('plugin', app_name, target, **options)

0 commit comments

Comments
 (0)