blob: 2f238c1d0498d3cf2c2e113042a12aaa1a4bef65 [file] [log] [blame]
Scott Baker5e694cd2014-12-26 11:36:55 -08001def is_camel_case(name):
2 for (i,char) in enumerate(name):
3 if (i>=1) and (name[i-1].islower()) and (char.isupper()):
4 return True
5 return False
6
7def is_missing_underscore(fieldName):
8 if (fieldName == "kuser_id"):
9 # this one is okay
10 return False
11
Scott Bakerbe53ac12017-01-04 15:41:10 -080012 {% for model in generator.all() %}
Scott Baker5e694cd2014-12-26 11:36:55 -080013 pos = fieldName.find("{{ model }}")
14 if (pos > 0) and (fieldName[pos-1] != "_"):
15 return True
16 {% endfor %}
17
18 return False
19
20def stylecheck_model_name(name):
21 if name.endswith("s"):
22 print "model '%s' name ends with 's'" % name
23
24def stylecheck_field_name(modelName, fieldName):
25 if is_camel_case(fieldName):
26 print "field '%s.%s' has camelcase" % (modelName, fieldName)
27 if is_missing_underscore(fieldName):
28 print "field '%s.%s' is missing underscore" % (modelName, fieldName)
29
30def stylecheck_field_plural(modelName, fieldName):
31 if is_camel_case(fieldName):
32 print "m2m field '%s.%s' has camelcase" % (modelName, fieldName)
33 if is_missing_underscore(fieldName):
34 print "m2m field '%s.%s' is missing underscore" % (modelName, fieldName)
35
36def main():
Scott Bakerbe53ac12017-01-04 15:41:10 -080037{% for obj in generator.all() %}
38 stylecheck_model_name("{{ obj.camel() }}");
Scott Baker5e694cd2014-12-26 11:36:55 -080039{% for ref in obj.refs %}
Scott Bakerbe53ac12017-01-04 15:41:10 -080040 stylecheck_field_plural("{{ obj.camel() }}", "{{ ref.plural }}");
Scott Baker5e694cd2014-12-26 11:36:55 -080041{% endfor %}
42{% for prop in obj.props %}
Scott Bakerbe53ac12017-01-04 15:41:10 -080043 stylecheck_field_name("{{ obj.camel() }}", "{{ prop }}");
Scott Baker5e694cd2014-12-26 11:36:55 -080044{% endfor %}
45{% endfor %}
46
47main()