model naming convention checker
diff --git a/planetstack/apigen/style.template b/planetstack/apigen/style.template
new file mode 100644
index 0000000..db80f55
--- /dev/null
+++ b/planetstack/apigen/style.template
@@ -0,0 +1,47 @@
+def is_camel_case(name):
+ for (i,char) in enumerate(name):
+ if (i>=1) and (name[i-1].islower()) and (char.isupper()):
+ return True
+ return False
+
+def is_missing_underscore(fieldName):
+ if (fieldName == "kuser_id"):
+ # this one is okay
+ return False
+
+ {% for model in generator.all %}
+ pos = fieldName.find("{{ model }}")
+ if (pos > 0) and (fieldName[pos-1] != "_"):
+ return True
+ {% endfor %}
+
+ return False
+
+def stylecheck_model_name(name):
+ if name.endswith("s"):
+ print "model '%s' name ends with 's'" % name
+
+def stylecheck_field_name(modelName, fieldName):
+ if is_camel_case(fieldName):
+ print "field '%s.%s' has camelcase" % (modelName, fieldName)
+ if is_missing_underscore(fieldName):
+ print "field '%s.%s' is missing underscore" % (modelName, fieldName)
+
+def stylecheck_field_plural(modelName, fieldName):
+ if is_camel_case(fieldName):
+ print "m2m field '%s.%s' has camelcase" % (modelName, fieldName)
+ if is_missing_underscore(fieldName):
+ print "m2m field '%s.%s' is missing underscore" % (modelName, fieldName)
+
+def main():
+{% for obj in generator.all %}
+ stylecheck_model_name("{{ obj.camel }}");
+{% for ref in obj.refs %}
+ stylecheck_field_plural("{{ obj.camel }}", "{{ ref.plural }}");
+{% endfor %}
+{% for prop in obj.props %}
+ stylecheck_field_name("{{ obj.camel }}", "{{ prop }}");
+{% endfor %}
+{% endfor %}
+
+main()