<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -86,10 +86,22 @@ def add_charge(request,slugs=&quot;&quot;):
         slugs = slugs[:-1]
     f = AddChargeForm(request.POST)
     snapshot = working_snapshot()
+    slug = slugify(request.POST['penal_code'] + &quot; &quot; + request.POST['label'])[:50]
+    # need to check for duplicate slugs and fix
+    try:
+        ct = Charge.objects.get(slug=slug)
+        # uh oh. there's already a charge with that slug
+        # need to come up with a relatively unique new one
+        # this is the most reasonable approach I can think of
+        slug = slug[:-3] + &quot;%03d&quot; % (Charge.objects.count() % 1000)
+        # any better ideas?
+    except Charge.DoesNotExist:
+        # that's good
+        pass
     c = Charge.objects.create(snapshot=snapshot,
                               label=request.POST['label'],
                               penal_code=request.POST['penal_code'],
-                              name=slugify(request.POST['penal_code'] + &quot; &quot; + request.POST['label'])[:50])
+                              name=slug)
     slugs = slugs.split(&quot;/&quot;)
     description = &quot;charge %s added&quot; % str(c)
     if len(slugs) &gt; 0 and slugs != ['']:</diff>
      <filename>law/views.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cb17534ccfa7447749dcc6c0484e98b325d1241d</id>
    </parent>
  </parents>
  <author>
    <name>Anders Pearson</name>
    <email>anders@columbia.edu</email>
  </author>
  <url>http://github.com/thraxil/ccdb/commit/843b744312b2e47c3af7f122eb30acc6d08e75fc</url>
  <id>843b744312b2e47c3af7f122eb30acc6d08e75fc</id>
  <committed-date>2009-05-04T11:43:03-07:00</committed-date>
  <authored-date>2009-05-04T11:43:03-07:00</authored-date>
  <message>attempt to prevent slug collisions on charges</message>
  <tree>6ea2cf223a3d3efe011b2eb040aa8602488b9a07</tree>
  <committer>
    <name>Anders Pearson</name>
    <email>anders@columbia.edu</email>
  </committer>
</commit>
