Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 484 lines (401 sloc) 18.75 kB
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
1 from os import path, remove, system, listdir, sys, mkdir
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
2
3 # VIEW CONSTS
4
5 LIST_VIEW = """
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
6 from %(app)s.forms import %(model)sForm
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
7 def %(lower_model)s_list(request, template='%(lower_model)s/list.html'):
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
8 d = {}
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
9 d['form'] = %(model)sForm()
10 if request.method == 'POST':
11 form = %(model)sForm(request.POST)
12 if form.is_valid():
13 form.save()
14 else:
15 d['form'] = form
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
16 d['%(lower_model)s_list'] = %(model)s.objects.all()
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
17 return render(request, template, d)
18 """
19
20 DETAILS_VIEW = """
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
21 from %(app)s.forms import %(model)sForm
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
22 def %(lower_model)s_details(request, id, template='%(lower_model)s/details.html'):
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
23 d = {}
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
24 item = get_object_or_404(%(model)s, pk=id)
25 d['form'] = %(model)sForm(instance=item)
26 if request.method == 'POST':
27 form = %(model)sForm(request.POST, instance=item)
28 if form.is_valid():
29 form.save()
30 else:
31 d['form'] = form
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
32 d['%(lower_model)s'] = %(model)s.objects.get(pk=id)
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
33 return render(request, template, d)
34 """
35
36 DELETE_VIEW = """
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
37 def %(lower_model)s_delete(request, id):
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
38 item = %(model)s.objects.get(pk=id)
39 item.delete()
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
40 return redirect(reverse('%(lower_model)s-list'))
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
41 """
42 # MODELS CONSTS
43
44 SCAFFOLD_APPS_DIR = 'apps'
45
46 MODEL_TEMPLATE = """
47 class %s(models.Model):
48 %s
49 update_date = models.DateTimeField(auto_now=True)
50 create_date = models.DateTimeField(auto_now_add=True)
51
52 class Meta:
53 ordering = ['-id']
54 """
55
56 IMPORT_MODEL_TEMPLATE = """from %(app)s.models import %(model)s"""
57
58 CHARFIELD_TEMPLATE = """
59 %(name)s = models.CharField(max_length=%(length)s, null=%(null)s, blank=%(null)s)
60 """
61
62 TEXTFIELD_TEMPLATE = """
63 %(name)s = models.TextField(null=%(null)s, blank=%(null)s)
64 """
65
66 INTEGERFIELD_TEMPLATE = """
67 %(name)s = models.IntegerField(null=%(null)s, default=%(default)s)
68 """
69
70 DECIMALFIELD_TEMPLATE = """
71 %(name)s = models.DecimalField(max_digits=%(digits)s, decimal_places=%(places)s, null=%(null)s, default=%(default)s)
72 """
73
74 DATETIMEFIELD_TEMPLATE = """
75 %(name)s = models.DateTimeField(null=%(null)s, default=%(default)s)
76 """
77
78 FOREIGNFIELD_TEMPLATE = """
79 %(name)s = models.ForeignKey(%(foreign)s)
80 """
81
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
82 TEMPLATE_LIST_CONTENT = """
83 {%% extends "base.html" %%}
84
85 {%% block page-title %%}%(title)s{%% endblock %%}
86
87 {%% block content %%}
88 <h1>%(title)s list</h1>
89 <table>
90 {%% for item in %(model)s_list %%}
91 <tr>
92 <td>{{ item.id }}</td>
93 <td>{{ item }}</td>
94 <td><a href="{%% url %(model)s-details item.id %%}">show</a></td>
95 </tr>
96 {%% endfor %%}
97 </table>
98 <br />
99 <form action="{%% url %(model)s-list %%}" method="POST">
100 {%% csrf_token %%}
101 {{ form }}
102 <input type="submit" value="Submit" />
103 </form>
104 {%% endblock %%}
105 """
106
107 TEMPLATE_DETAILS_CONTENT = """
108 {%% extends "base.html" %%}
109
110 {%% block page-title %%}%(title)s - {{ %(model)s }} {%% endblock %%}
111
112 {%% block content %%}
113 <h1>%(title)s - {{ %(model)s }} </h1>
114 <table>
115 <tr>
116 <td>{{ %(model)s.id }}</td>
117 <td>{{ %(model)s }}</td>
118 <td><a href="{%% url %(model)s-delete %(model)s.id %%}">delete</a></td>
119 </tr>
120 </table>
121 <br />
122 <br />
123 <form action="{%% url %(model)s-details %(model)s.id %%}" method="POST">
124 {%% csrf_token %%}
125 {{ form }}
126 <input type="submit" value="Save" />
127 </form>
128 <br />
129 <a href="{%% url %(model)s-list %%}">back to list</a>
130 {%% endblock %%}
131 """
132
133 URL_CONTENT = """
134 from django.conf.urls.defaults import *
135 from django.contrib.auth import views as auth_views
136
137 urlpatterns = patterns('%(app)s.views',
138 url(r'^%(model)s/$', '%(model)s_list', name='%(model)s-list'),
139 url(r'^%(model)s/(?P<id>\d+)/$', '%(model)s_details', name='%(model)s-details'),
140 url(r'^%(model)s/(?P<id>\d+)/delete/$', '%(model)s_delete', name='%(model)s-delete'),
141 )
142 """
143
144 ADMIN_CONTENT = """
145 from %(app)s.models import %(model)s
146 admin.site.register(%(model)s)
147 """
148
149 FORM_CONTENT = """
150 from %(app)s.models import %(model)s
151
152 class %(model)sForm(forms.ModelForm):
153 class Meta:
154 model = %(model)s
155 """
156
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
157 class Scaffold(object):
158
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
159 def _info(self, msg, indent=0):
160 print "%s %s" % ("\t"*int(indent), msg)
161
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
162 def __init__(self, app, model, fields):
163 self.app = app
164 self.model = model
165 self.fields = fields
166
167 def get_import(self, model):
168 for dir in listdir(SCAFFOLD_APPS_DIR):
169 if path.isdir('%s/%s' % (SCAFFOLD_APPS_DIR,dir)) and path.exists('%s/%s/models.py' % (SCAFFOLD_APPS_DIR,dir)):
170 dir_models_file = open('%s/%s/models.py' % (SCAFFOLD_APPS_DIR,dir), 'r')
171 # Check if model exists
172 for line in dir_models_file.readlines():
173 if 'class %s(models.Model)' % model in line:
174 #print "Foreign key '%s' was found in app %s..." % (model, dir)
175 return IMPORT_MODEL_TEMPLATE % {'app': dir, 'model': model }
176 return None
177
178 def is_imported(self, path, model):
179 import_file = open(path, 'r')
180 for line in import_file.readlines():
181 if 'import %s' % model in line:
182 #print "Foreign key '%s' was found in models.py..." % (foreign)
183 return True
184 return False
185
186 def add_global_view_imports(self, path):
187 #from django.shortcuts import render, redirect, get_object_or_404, get_list_or_404
188 import_list = list()
189 import_file = open(path, 'r')
190
191 need_import_shortcut = True
192 need_import_urlresolvers = True
193
194 for line in import_file.readlines():
195 if 'from django.shortcuts import render, redirect, get_object_or_404' in line:
196 need_import_shortcut = False
197 if 'from django.core.urlresolvers import reverse' in line:
198 need_import_urlresolvers = False
199
200 if need_import_shortcut:
201 import_list.append('from django.shortcuts import render, redirect, get_object_or_404')
202 if need_import_urlresolvers:
203 import_list.append('from django.core.urlresolvers import reverse')
204
205 return import_list
206
207 def view_exists(self, path, view):
208 # Check if view already exists
209 view_file = open(path, 'r')
210 for line in view_file.readlines():
211 if 'def %s(' % view in line:
212 return True
213 return False
214
215 def get_field(self, field):
216 field = field.split(':')
217 field_type = field[0]
218 if field_type.lower() == 'char':
219 try:
220 length = field[2]
221 except:
222 length = 255
223 try:
224 null = field[3]
225 null = 'False'
226 except:
227 null = 'True'
228 return CHARFIELD_TEMPLATE % {'name': field[1], 'length': length, 'null': null}
229 elif field_type.lower() == 'text':
230 try:
231 null = field[2]
232 null = 'False'
233 except:
234 null = 'True'
235 return TEXTFIELD_TEMPLATE % {'name': field[1], 'null': null}
236 elif field_type.lower() == 'int':
237 try:
238 null = field[2]
239 null = 'False'
240 except:
241 null = 'True'
242 try:
243 default = field[3]
244 except:
245 default = None
246 return INTEGERFIELD_TEMPLATE % {'name': field[1], 'null': null, 'default': default}
247 elif field_type.lower() == 'decimal':
248 try:
249 null = field[4]
250 null = 'False'
251 except:
252 null = 'True'
253 try:
254 default = field[5]
255 except:
256 default = None
257 return DECIMALFIELD_TEMPLATE % {'name': field[1], 'digits': field[2], 'places':field[3], 'null': null, 'default': default}
258 elif field_type.lower() == 'datetime':
259 try:
260 null = field[2]
261 null = 'False'
262 except:
263 null = 'True'
264 try:
265 default = field[3]
266 except:
267 default = None
268 return DATETIMEFIELD_TEMPLATE % {'name': field[1], 'null': null, 'default': default}
269 elif field_type.lower() == 'foreign':
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
270 foreign = field[1]
271 name = foreign.lower()
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
272 # Check if this foreign key is already in models.py
273 if self.is_imported('%s/%s/models.py' % (SCAFFOLD_APPS_DIR, self.app), foreign):
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
274 return FOREIGNFIELD_TEMPLATE % {'name': name, 'foreign': foreign}
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
275 # Check imports
276 if self.get_import(foreign):
277 self.imports.append(self.get_import(foreign))
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
278 return FOREIGNFIELD_TEMPLATE % {'name': name, 'foreign': foreign}
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
279
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
280 self._info('error\t%s/%s/models.py\t%s class not found' % (SCAFFOLD_APPS_DIR, self.app, field[1]), 1)
281 return None
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
282
283 def create_app(self):
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
284 self._info(" App ")
285 self._info("===========")
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
286 if not path.exists('%s/%s' % (SCAFFOLD_APPS_DIR, self.app)):
287 system('python manage.py startapp %s' % self.app)
288 system('mv %s %s/%s' % (self.app, SCAFFOLD_APPS_DIR, self.app))
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
289 self._info("create\t%s/%s" % (SCAFFOLD_APPS_DIR, self.app), 1)
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
290 else:
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
291 self._info("exists\t%s/%s" % (SCAFFOLD_APPS_DIR, self.app), 1)
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
292
293 def create_views(self):
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
294 self._info(" Views ")
295 self._info("===========")
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
296 # Open models.py to read
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
297 view_path = '%s/%s/views.py' % (SCAFFOLD_APPS_DIR, self.app)
298
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
299 # Check if urls.py exists
300
301 if path.exists('%s/%s/views.py' % (SCAFFOLD_APPS_DIR, self.app)):
302 self._info('exists\t%s/%s/views.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
303 else:
304 file = open("%s/%s/views.py" % (SCAFFOLD_APPS_DIR, self.app), 'w')
305 self._info('create\t%s/%s/views.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
306
307 import_list = list()
308 view_list = list()
309
310 # Add global imports
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
311 import_list.append('\n'.join(imp for imp in self.add_global_view_imports(view_path)))
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
312
313 # Add model imports
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
314 if not self.is_imported(view_path, self.model):
315 import_list.append(self.get_import(self.model))
316
317 lower_model = self.model.lower()
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
318
319 # Check if view already exists
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
320 if not self.view_exists(view_path, "%s_list" % lower_model):
321 view_list.append(LIST_VIEW % {'lower_model': lower_model, 'model': self.model, 'app': self.app})
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
322 self._info("added \t%s\t%s_view" % (view_path,lower_model), 1)
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
323 else:
324 self._info("exists\t%s\t%s_view" % (view_path,lower_model), 1)
325
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
326 if not self.view_exists(view_path, "%s_details" % lower_model):
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
327 view_list.append(DETAILS_VIEW % {'lower_model': lower_model, 'model': self.model, 'app': self.app})
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
328 self._info("added \t%s\t%s_details" % (view_path,lower_model), 1)
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
329 else:
330 self._info("exists\t%s\t%s_details" % (view_path,lower_model), 1)
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
331
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
332 if not self.view_exists(view_path, "%s_delete" % lower_model):
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
333 view_list.append(DELETE_VIEW % {'lower_model': lower_model, 'model': self.model})
334 self._info("added \t%s\t%s_delete" % (view_path,lower_model), 1)
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
335 else:
336 self._info("exists\t%s\t%s_delete" % (view_path,lower_model), 1)
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
337
338 # Open views.py to append
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
339 view_file = open(view_path, 'a')
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
340
341 view_file.write('\n'.join(import_line for import_line in import_list))
342 view_file.write(''.join(view for view in view_list))
343
344
345 def create_model(self):
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
346 self._info(" Model ")
347 self._info("===========")
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
348 # Open models.py to read
349 self.models_file = open('%s/%s/models.py' % (SCAFFOLD_APPS_DIR, self.app), 'r')
350
351 # Check if model already exists
352 for line in self.models_file.readlines():
353 if 'class %s' % self.model in line:
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
354 self._info('exists\t%s/%s/models.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
355 return
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
356
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
357 self._info('create\t%s/%s/models.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
358 # Prepare fields
359 self.imports = list()
360 fields = list()
361 for field in self.fields:
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
362 new_field = self.get_field(field)
363 if new_field:
364 fields.append(new_field)
365 self._info('added\t%s/%s/models.py\t%s field' % (SCAFFOLD_APPS_DIR, self.app, field.split(':')[1]), 1)
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
366
367 # Open models.py to append
368 models_file = open('%s/%s/models.py' % (SCAFFOLD_APPS_DIR, self.app), 'a')
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
369
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
370 models_file.write(''.join(import_line for import_line in self.imports))
371 models_file.write(MODEL_TEMPLATE % (self.model, ''.join(field for field in fields)))
372
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
373 def create_templates(self):
374 self._info(" Templates ")
375 self._info("===========")
376
377 # Check if template dir exists
378
379 if path.exists('%s/%s/templates/' % (SCAFFOLD_APPS_DIR, self.app)):
380 self._info('exists\t%s/%s/templates/' % (SCAFFOLD_APPS_DIR, self.app), 1)
381 else:
382 mkdir("%s/%s/templates/" % (SCAFFOLD_APPS_DIR, self.app))
383 self._info('create\t%s/%s/templates/' % (SCAFFOLD_APPS_DIR, self.app), 1)
384
385 # Check if model template dir exists
386
387 if path.exists('%s/%s/templates/%s/' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower())):
388 self._info('exists\t%s/%s/templates/%s/' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
389 else:
390 mkdir("%s/%s/templates/%s/" % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()))
391 self._info('create\t%s/%s/templates/%s/' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
392
393 # Check if list.html exists
394
395 if path.exists('%s/%s/templates/%s/list.html' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower())):
396 self._info('exists\t%s/%s/templates/%s/list.html' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
397 else:
398 file = open("%s/%s/templates/%s/list.html" % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 'w')
399 file.write(TEMPLATE_LIST_CONTENT % {'model': self.model.lower(), 'title': self.model.lower()})
400 self._info('create\t%s/%s/templates/%s/list.html' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
401
402 # Check if details.html exists
403
404 if path.exists('%s/%s/templates/%s/details.html' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower())):
405 self._info('exists\t%s/%s/templates/%s/details.html' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
406 else:
407 file = open("%s/%s/templates/%s/details.html" % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 'w')
408 file.write(TEMPLATE_DETAILS_CONTENT % {'model': self.model.lower(), 'title': self.model.lower()})
409 self._info('create\t%s/%s/templates/%s/details.html' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
410
411 def create_urls(self):
412 self._info(" URLs ")
413 self._info("===========")
414
415 # Check if urls.py exists
416
417 if path.exists('%s/%s/urls.py' % (SCAFFOLD_APPS_DIR, self.app)):
418 self._info('exists\t%s/%s/urls.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
419 else:
420 file = open("%s/%s/urls.py" % (SCAFFOLD_APPS_DIR, self.app), 'w')
421 file.write(URL_CONTENT % {'app': self.app, 'model': self.model.lower()})
422 self._info('create\t%s/%s/urls.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
423
424 def create_admin(self):
425 self._info(" Admin ")
426 self._info("===========")
427
428 # Check if admin.py exists
429
430 if path.exists('%s/%s/admin.py' % (SCAFFOLD_APPS_DIR, self.app)):
431 self._info('exists\t%s/%s/admin.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
432 else:
433 file = open("%s/%s/admin.py" % (SCAFFOLD_APPS_DIR, self.app), 'w')
434 file.write("from django.contrib import admin\n")
435 self._info('create\t%s/%s/urls.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
436
437 # Check if admin entry already exists
438
439 content = open("%s/%s/admin.py" % (SCAFFOLD_APPS_DIR, self.app), 'r').read()
440 if "admin.site.register(%s)" % self.model in content:
441 self._info('exists\t%s/%s/admin.py\t%s' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
442 else:
443 file = open("%s/%s/admin.py" % (SCAFFOLD_APPS_DIR, self.app), 'a')
444 file.write(ADMIN_CONTENT % {'app': self.app, 'model': self.model})
445 self._info('added\t%s/%s/admin.py\t%s' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
446
447 def create_forms(self):
448 self._info(" Forms ")
449 self._info("===========")
450
451 # Check if forms.py exists
452
453 if path.exists('%s/%s/forms.py' % (SCAFFOLD_APPS_DIR, self.app)):
454 self._info('exists\t%s/%s/forms.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
455 else:
456 file = open("%s/%s/forms.py" % (SCAFFOLD_APPS_DIR, self.app), 'w')
457 file.write("from django import forms\n")
458 self._info('create\t%s/%s/forms.py' % (SCAFFOLD_APPS_DIR, self.app), 1)
459
460 # Check if form entry already exists
461
462 content = open("%s/%s/forms.py" % (SCAFFOLD_APPS_DIR, self.app), 'r').read()
463 if "class %sForm" % self.model in content:
464 self._info('exists\t%s/%s/forms.py\t%s' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
465 else:
466 file = open("%s/%s/forms.py" % (SCAFFOLD_APPS_DIR, self.app), 'a')
467 file.write(FORM_CONTENT % {'app': self.app, 'model': self.model})
468 self._info('added\t%s/%s/admin.py\t%s' % (SCAFFOLD_APPS_DIR, self.app, self.model.lower()), 1)
469
470
cbf5963 @dfryta Very first version of scaffold. Generating models and some views.
dfryta authored
471
472 def run(self):
95ad3e8 @dfryta Added detail info about creating objects
dfryta authored
473 if not self.app:
474 sys.exit("No application name found...")
475 if not self.model:
476 sys.exit("No model name found...")
477
975bf70 @dfryta Enabled models generating
dfryta authored
478 self.create_app()
479 self.create_model()
ab6e170 @dfryta Added full templates, admin, forms, views, urls and models
dfryta authored
480 self.create_views()
481 self.create_admin()
482 self.create_forms()
483 self.create_urls()
484 self.create_templates()
Something went wrong with that request. Please try again.