Tweaking Django and pdf script progress

I have to put this up here. I was tweaking up timepass and at a particular stage when I was working on the CRUD (admin interface that django provides), I was faced with the situation of throwing in 7 BooleanFields one after the other. It looked disgusting. I then modded Django a bit to ease things out. I am not going to explain the stuff over here as I have to rush, but the code is commented well enough :)

from django import oldforms

from django.db import models

from django.utils.functionalimport curryclass CheckBoxManyToMany(models.ManyToManyField):

    def get_manipulator_field_objs(self):

        if self.rel.raw_id_admin:

            return [oldforms.RawIdAdminField]

        else:

            choices = self.get_choices_default()

            return [curry(oldforms.CheckboxSelectMultipleField, choices=choices)]

def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):

        """

        Returns a list of oldforms.FormField instances for this field. It

        calculates the choices at runtime, not at compile time.

name_prefix is a prefix to prepend to the "field_name" argument.

        rel is a boolean specifying whether this field is in a related context.

        """

        field_objs, params = self.prepare_field_objs_and_params(manipulator, name_prefix)

# BooleanFields (CheckboxFields) are a special case. They don't take

        # is_required.

        if 'is_required' in params:

            del params['is_required']

# Finally, add the field_names.

        field_names = self.get_manipulator_field_names(name_prefix)

        return [man(field_name=field_names[i], **params) for i, man in enumerate(field_objs)] 

There !

Now, let me elaborate upon the pdf script that I was making to ease out stuff for my dad.

My plan is to create new ebooks out of each chapter. Each chapter is obviously going to be smaller than 1.5 MB and that should be it !

The route I am taking involves creation of a html file from the pdf file. This html is parsed and the required data obtained and so on. I promise to put up a working version soon.

I am going to spend the rest of the day reading Prashanth Mohan’s Final Year Project. See you later !

1 comment so far ↓

#1 Prashanth on 01.08.08 at 12:33 pm

Haha! Do let me know what you make of it :-)

Leave a Comment