heya,
The sample code request was just me being lazy =). Hmm, so you think
the csv parsing code should be in the upload processing? This would
just be a form with two boxes for the user to select the .csv files,
and an upload button. Better putting it here than in the model?
In terms of processing, well, there's only a little bit. One of the
files is a dump from a Lotus Notes view. It looks a little like this
Date Region Arrival Time Duration Sites
For
2008-12-1
Australia
7:30 AM - 1.25 [HR]
/SYD/225 G John Smith
/GER/115 A Nolan Smith
7:30 AM - 1.25 [HR]
/SYD/225 G Bob Smith
7:30 AM - 1.25 [HR]
/SYD/225 G Joe Smith
NZ
7:30 AM - 1.25 [HR]
/SYD/225 G Jane Smith
/SYD/
7:30 AM - 1.0 [HR]
/SYD/225 G Mary Smith
7:30 AM - 5.0 [HR]
/SYD/225 G Brown Smith
2008-12-2
NZ
7:30 AM - 1.25 [HR]
/SYD/225 G Jane Smith
/SYD/
7:30 AM - 1.25 [HR]
/SYD/225 G Mary Smith
7:30 AM - 1.25 [HR]
/SYD/225 G Brown Smith
Firstly, there were dropdowns (e.g. for Date, and Region) - those date
and regions apply to the rows below them - annoying, but easy to deal
with.
Also, the time is given as a start time and duration - I converted
this into a start_time and end_time.
Finally, the Sites and For columns can each contain multiple entries.
After parsing, I'm storing it as a list of users, each with a list of
access periods granted (containing the start_time, end_time and site -
and a few other things). So you go through, and create entries for
each user, for each of the sites, per line. Not too bad.
Heck, I'll just post the code (I'm halfway through working on it - may
not compile cleanly right now, but you get the idea).
http://dl.getdropbox.com/u/281283/access_requests.py
I guess the important thing is just the users being able to upload
the .csv files themselves, and dealing with weirdness in the input.
Cheers,
Victor
On Jan 8, 2:01 am, Keyton Weissinger <[email protected]> wrote:
> Hey Victor,
>
> I did the django-batchimport mentioned earlier. I think it will
> address your need but is definitely aimed at XLS. However, it does
> already handle duplicates (it will either update them or ignore them
> based on setting). You can also specify a subset of model fields to
> use to determine whether a given row represents a duplicate. This
> allows for "batch update" too.
>
> If you get into it and have any problems, drop me a note.
>
> Keyton
>
> On Jan 6, 12:02 am, Victor Hooi <[email protected]> wrote:
>
> > heya,
>
> > This question might seem a bit simple, but what's the best way to
> > instantiate models from .csv files?
>
> > Essentially, I have two .csv files. One contains a list of people, and
> > their access rights (one-to-many). The second .csv file contains a log
> > of doorway access (just a bunch of sequential lines). I have a simple
> > python script which imports these two .csv files, does some processing
> > (the files are quite messy), creates user and access-entry objects,
> > and produces a reconciliation with a list of exceptions (basically
> > door entries which aren't in the list of user/access rights). Each
> > user is just a dictionary, with their username as key, and a tuple of
> > dictionary objects for their various access rights.
>
> > I would like a simple django project to import these logs, instantiate
> > models, and then basically manage it via the in-built admin interface,
> > hopefully saving a lot of time =). (will also need to deal with
> > duplicates). Is there a smart way to go about doing this project, or
> > any existing addons I can leverage off?
>
> > Thanks,
> > Victor
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---