<commit_before>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4 encoding=utf-8

import os, re, sys
from xml.dom.minidom import parseString, Element
from django.db import models
from django.db.models.signals import pre_save
from django.conf import settings
from . import utils

FORM_PATH = "odk/forms"
INSTANCE_PATH = "odk/instances"

def _drop_xml_extension(filename):
    """
    Return the filename having dropped the 'xml' extension. If the
    filename didn't end with '.xml' raise an exception.
    """    
    m = re.search(r"(.*)\.xml$", filename)
    if m:
        return m.group(1)
    else:
        raise Exception("Filename must end with '.xml'", filename)

class Form(models.Model):
    xml_file = models.FileField(
        upload_to=FORM_PATH, verbose_name="XML File"
        )
    id_string = models.CharField(
        unique=True, blank=True, max_length=32, verbose_name="ID String"
        )
    active = models.BooleanField()

    class Meta:
        verbose_name = "XForm"
        verbose_name_plural = "XForms"
        ordering = ("id_string",)
        app_label = "ODK"
        db_table = "odk_dropbox_form"

    def __unicode__(self):
        return getattr(self, "id_string", "")

    def path(self):
        return settings.MEDIA_ROOT + self.xml_file.name

    def name(self):
        folder, filename = os.path.split(self.path())
        return _drop_xml_extension(filename)

    def url(self):
        return self.xml_file.url

    def _set_id_from_xml(self):
        form_parser = utils.FormParser(self.xml_file)
        self.id_string = form_parser.get_id_string()

# before a form is saved to the database set the form's id string by
# looking through it's xml.
def _set_form_id(sender, **kwargs):
    kwargs["instance"]._set_id_from_xml()
<commit_msg>fixed error i introduced<commit_after>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4 encoding=utf-8

import os, re, sys
from xml.dom.minidom import parseString, Element
from django.db import models
from django.db.models.signals import pre_save
from django.conf import settings
from . import utils

FORM_PATH = "odk/forms"
INSTANCE_PATH = "odk/instances"

def _drop_xml_extension(filename):
    """
    Return the filename having dropped the 'xml' extension. If the
    filename didn't end with '.xml' raise an exception.
    """    
    m = re.search(r"(.*)\.xml$", filename)
    if m:
        return m.group(1)
    else:
        raise Exception("Filename must end with '.xml'", filename)

class Form(models.Model):
    xml_file = models.FileField(
        upload_to=FORM_PATH, verbose_name="XML File"
        )
    id_string = models.CharField(
        unique=True, blank=True, max_length=32, verbose_name="ID String"
        )
    active = models.BooleanField()

    class Meta:
        verbose_name = "XForm"
        verbose_name_plural = "XForms"
        ordering = ("id_string",)

    def __unicode__(self):
        return getattr(self, "id_string", "")

    def path(self):
        return settings.MEDIA_ROOT + self.xml_file.name

    def name(self):
        folder, filename = os.path.split(self.path())
        return _drop_xml_extension(filename)

    def url(self):
        return self.xml_file.url

    def _set_id_from_xml(self):
        form_parser = utils.FormParser(self.xml_file)
        self.id_string = form_parser.get_id_string()

# before a form is saved to the database set the form's id string by
# looking through it's xml.
def _set_form_id(sender, **kwargs):
    kwargs["instance"]._set_id_from_xml()

{'fraction_non_alphanumeric': 0.1093705497009399, 'fraction_numerical': 0.003987467957846767, 'mean_word_length': 3.064814814814815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2719507', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1120, 'n_words': 297}