Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No en in laguages raise exception when syncing #8

Open
windman83 opened this issue Nov 17, 2014 · 0 comments
Open

No en in laguages raise exception when syncing #8

windman83 opened this issue Nov 17, 2014 · 0 comments

Comments

@windman83
Copy link

If I have the following settings

LANGUAGE_CODE = 'it'

LANGUAGES = (
('it', 'Italian'),
('en', 'English'),
)

there are no problems, but removing the ('en', 'English'), language raise an exception on nullable fields
when launcing sync_transmeta_db

with the following trace

Traceback (most recent call last):
File "Z:\Exprivia\Programmi_e_configurazioni\workspaceEclipseLuna\Consumattori\manage.py", line 10, in
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(_args, *_options.dict)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 338, in execute
output = self.handle(_args, *_options)
File "c:\python27\lib\site-packages\django_transmeta-0.7.3-py2.7.egg\transmeta\management\commands\sync_transmeta_db.py", line 88, in handle
sql_sentences = self.get_sync_sql(field_name, db_change_langs, model, db_table_fields)
File "c:\python27\lib\site-packages\django_transmeta-0.7.3-py2.7.egg\transmeta\management\commands\sync_transmeta_db.py", line 197, in get_sync_sql
col_type = self.get_type_of_db_field(field_name, model)
File "c:\python27\lib\site-packages\django_transmeta-0.7.3-py2.7.egg\transmeta\management\commands\sync_transmeta_db.py", line 171, in get_type_of_db_field
field = model._meta.get_field(get_real_fieldname(field_name))
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 398, in get_field
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, name))
django.db.models.fields.FieldDoesNotExist: Question has no field named 'extra_en'

the model is:

class Question(models.Model):
    __metaclass__ = TransMeta

    questionset = models.ForeignKey(QuestionSet)
    number = models.CharField(max_length=8, help_text=
        "eg. <tt>1</tt>, <tt>2a</tt>, <tt>2b</tt>, <tt>3c</tt><br /> "
        "Number is also used for ordering questions.")
    text = models.TextField(blank=True, verbose_name=_("Text"))
    type = models.CharField(u"Type of question", max_length=32,
        choices = QuestionChoices,
        help_text = u"Determines the means of answering the question. " \
        "An open question gives the user a single-line textfield, " \
        "multiple-choice gives the user a number of choices he/she can " \
        "choose from. If a question is multiple-choice, enter the choices " \
        "this user can choose from below'.")
    extra = models.CharField(u"Extra information", max_length=512, blank=True, null=True, help_text=u"Extra information (use  on question type)")
    checks = models.CharField(u"Additional checks", max_length=512, blank=True,
        null=True, help_text="Additional checks to be performed for this "
        "value (space separated)  <br /><br />"
        "For text fields, <tt>required</tt> is a valid check.<br />"
        "For yes/no choice, <tt>required</tt>, <tt>required-yes</tt>, "
        "and <tt>required-no</tt> are valid.<br /><br />"
        "If this question is required only if another question's answer is "
        'something specific, use <tt>requiredif="QuestionNumber,Value"</tt> '
        'or <tt>requiredif="QuestionNumber,!Value"</tt> for anything but '
        "a specific value.  "
        "You may also combine tests appearing in <tt>requiredif</tt> "
        "by joining them with the words <tt>and</tt> or <tt>or</tt>, "
        'eg. <tt>requiredif="Q1,A or Q2,B"</tt>')
    footer = models.TextField(u"Footer", help_text="Footer rendered below the question interpreted as textile", blank=True)


    def questionnaire(self):
        return self.questionset.questionnaire

    def getcheckdict(self):
        """getcheckdict returns a dictionary of the values in self.checks"""
        if(hasattr(self, '__checkdict_cached')):
            return self.__checkdict_cached
        try:
            self.__checkdict_cached = d = parse_checks(self.sameas().checks or '')
        except ParseException:
            raise Exception("Error Parsing Checks for Question %s: %s" % (
                self.number, self.sameas().checks))
        return d

    def __unicode__(self):
        return u'{%s} (%s) %s' % (unicode(self.questionset), self.number, self.text)

    def sameas(self):
        if self.type == 'sameas':
            try:
                kwargs = {}
                for check, value in parse_checks(self.checks):
                    if check == 'sameasid':
                        kwargs['id'] = value
                        break
                    elif check == 'sameas':
                        kwargs['number'] = value
                        kwargs['questionset__questionnaire'] = self.questionset.questionnaire
                        break

                self.__sameas = res = getattr(self, "__sameas", Question.objects.get(**kwargs))
                return res
            except Question.DoesNotExist:
                return Question(type='comment') # replace with something benign
        return self

    def display_number(self):
        "Return either the number alone or the non-number part of the question number indented"
        m = _numre.match(self.number)
        if m:
            sub = m.group(2)
            return "&nbsp;&nbsp;&nbsp;" + sub
        return self.number

    def choices(self):
        if self.type == 'sameas':
            return self.sameas().choices()
        res = Choice.objects.filter(question=self).order_by('sortid')
        return res

    def is_custom(self):
        return "custom" == self.sameas().type

    def get_type(self):
        "Get the type name, treating sameas and custom specially"
        t = self.sameas().type
        if t == 'custom':
            cd = self.sameas().getcheckdict()
            if 'type' not in cd:
                raise Exception("When using custom types, you must have type=<name> in the additional checks field")
            return cd.get('type')
        return t

    def questioninclude(self):
        return "questionnaire/" + self.get_type() + ".html"

#     def __cmp__(a, b):
#         anum, astr = split_numal(a.number)
#         bnum, bstr = split_numal(b.number)
#         cmpnum = cmp(anum, bnum)
#         return cmpnum or cmp(astr, bstr)

    class Meta:
        translate = ('text', 'extra', 'footer')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant