blob: db80f55631727baa1db9d8f4360b406b1f1e428d [file] [log] [blame]
Scott Baker0edb43f2014-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
12 {% for model in generator.all %}
13 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():
37{% for obj in generator.all %}
38 stylecheck_model_name("{{ obj.camel }}");
39{% for ref in obj.refs %}
40 stylecheck_field_plural("{{ obj.camel }}", "{{ ref.plural }}");
41{% endfor %}
42{% for prop in obj.props %}
43 stylecheck_field_name("{{ obj.camel }}", "{{ prop }}");
44{% endfor %}
45{% endfor %}
46
47main()