Re: Use Python to parse HTML and integrating said script into Django

2009-04-18 Thread Tonne

> But it sounds to me like you might want to look into creating your own
> template tag to generate the calendar HTML. I'd rather do that than go
> nuts with nested loops inside a template.

Just to follow up on this...

I have a working solution. Right or wrong, my answer was to create a
template tag that generates the calendar, html and all.

As the looping I need to do is beyond the default Django template
conditionals, I patched together a  multiline block type """string"""
which included the html formatting. Not very elegant, but it does the
job.

I'd still be interested to know if there would be a better way of
doing this though. As I explained, I need to build up a set of nest
lists (which forms the Calendar). In order to do that, I need to fetch
values from a 3 level deep array (combo of dicts and lists). This
necessitates that I make use while lists and iterators to find the
values.

So if anyone has a better way of doing this, please let me know and
I'll do some refactoring.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use Python to parse HTML and integrating said script into Django

2009-04-13 Thread Brian Neal

On Apr 13, 9:44 am, Tonne  wrote:
> It's the calendar with the unusual form/structure  that I'm
> struggling to implement with the stock Django tools.
>
> I'll take a step back and give it another shot with logic in view and
> parsing in the template.

I'm not sure what you mean by "parsing"...I am assuming you mean
"generating".

But it sounds to me like you might want to look into creating your own
template tag to generate the calendar HTML. I'd rather do that than go
nuts with nested loops inside a template.

-BN
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use Python to parse HTML and integrating said script into Django

2009-04-13 Thread Tonne

Thanks for you input. Okay, I clearly need to do a bit of revision on
nesting loops in templates then, if you think it might be possible to
do that. 3 nested 'while' loops with incrementing variables sound
doable in a template?

>Well, what does the updating of the dict consist of?

It will need to be updated based on queryset derived from a model, so
not so much a cron job. I do have the rest of the app working as I
want it. It's the calendar with the unusual form/structure  that I'm
struggling to implement with the stock Django tools.

I'll take a step back and give it another shot with logic in view and
parsing in the template.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use Python to parse HTML and integrating said script into Django

2009-04-13 Thread TiNo
On Mon, Apr 13, 2009 at 11:17 AM, Tonne  wrote:

> In my case I need to firstly update a 3 dimensional dict/list (i.e.
> nested 3 levels deep - not sure if 3 dimensional is an appropriate
> description), then iterate over it and put those results into an html
> page. I'm probably not looking hard enough, but I can't quite seem to
> grasp how to achieve this with traditional Django views and Django
> templates.


Couldn't you do that with three nested for loops in the template? See:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

I'd prefer to solve the problem the Django way. The problem for me is
>
that what I'm trying to do is not the usual scenario of passing the
>
results of query through a view to a template. I haven't found a
>
precedent in the docs or a tutorial elsewhere that covers this.


Well, what does the updating of the dict consist of? Even if it depends on
the date or on other external factors, it could happen in the view. Unless
updating it is only necessary once a day and takes a lot of computing power.
In that case you could run it with a cronjob [1] or any other scheduled
task, once a day, and save the data into a file or db.

Remember that Django can be used as what you refer to as 'freeform' python
as well. You are totally free to import parts of django into an external
python script, and in that way make use of django's models etc. (Only make
sure to set DJANGO_SETTINGS_MODULE in your script [2])

[1] http://en.wikipedia.org/wiki/Cron
[2] http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/

TiNo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use Python to parse HTML and integrating said script into Django

2009-04-13 Thread Tonne

Thanks for you reply, Jakob.

I'd prefer to solve the problem the Django way. The problem for me is
that what I'm trying to do is not the usual scenario of passing the
results of query through a view to a template. I haven't found a
precedent in the docs or a tutorial elsewhere that covers this.

In my case I need to firstly update a 3 dimensional dict/list (i.e.
nested 3 levels deep - not sure if 3 dimensional is an appropriate
description), then iterate over it and put those results into an html
page. I'm probably not looking hard enough, but I can't quite seem to
grasp how to achieve this with traditional Django views and Django
templates.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use Python to parse HTML and integrating said script into Django

2009-04-13 Thread google torp

Hi.

It sounds like you need to change your code structure a bit to really
take advantage of Django and the possibilities it offer. If you just
want
to get your stuff working with Django and then nothing more, I guess
you could keep it like it is, but else re factoring would be a good
idea.

The way django works, you want to keep the logic separated from the
presentation. So basically that means, that you should keep the Python
code separated from your HTML. In Django terms, we use the view
to make the logic, where we can if needed, import helper functions.
When all the data has been calculated, we pass it to a template, a
html file where we with some Django code can insert data dynamically.

It sounds like you need to grasp these things, before you really get
going.

about writing views: http://docs.djangoproject.com/en/dev/topics/http/views/
about the template language 
http://docs.djangoproject.com/en/dev/topics/templates/
about render_to_response: 
http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response

Render to response is  common way of passing data to a template for
display.
Which was what your initial question was about. But I would recommend
that
you strip the html from your Python code and instead put the html in
your template
instead. That would be a more clean and Djangoish way of doing it.

~Jakob

On 13 Apr., 07:24, Tonne  wrote:
> Hi
>
> I'm not too sure how to ask this correctly (not an experienced
> developer so my vocab is not very accurate), but I'll try.
>
> I have created a Python script (collection of functions) that
> generates a calendar of sorts, really just a long list of dates from a
> 4 year date range. It also parses the HTML, as I couldn't work out how
> to do this with the limited logic available the templating language.
>
> My question are:
>
> Is it possible to use a "freeform" python within the Django framework,
> and yet let it receive arguments from the model?
>
> I was intially thinking of making a custom view, but then I have all
> this parsed HTML and am not sure how to get it into a template.
>
> Or should I be looking at making a custom tag?
>
> If not the above, do you have any other pointers on how to go about
> this?
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Use Python to parse HTML and integrating said script into Django

2009-04-12 Thread Tonne

Hi

I'm not too sure how to ask this correctly (not an experienced
developer so my vocab is not very accurate), but I'll try.

I have created a Python script (collection of functions) that
generates a calendar of sorts, really just a long list of dates from a
4 year date range. It also parses the HTML, as I couldn't work out how
to do this with the limited logic available the templating language.

My question are:

Is it possible to use a "freeform" python within the Django framework,
and yet let it receive arguments from the model?

I was intially thinking of making a custom view, but then I have all
this parsed HTML and am not sure how to get it into a template.

Or should I be looking at making a custom tag?

If not the above, do you have any other pointers on how to go about
this?

Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---