Parsing a reStructuredText

2011-10-25 Thread eaman
I'm developing a web site in django to manage guides / howtos
that I've been writing in reStructuredText.
I'd like to display each section of them in a single page,
how can I parse the reStructuredText to get titles / context of single
sections?

-- 
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: Parsing a reStructuredText

2011-10-25 Thread eaman


On Oct 25, 6:46 pm, "J. Cliff Dyer"  wrote:
[CUT]
> What have you got so far?
About 10 documents, longest one is around ~2700 'lines'.
...and I'm reading docutils documentation [1]
and a blog entry quite near my topic [2]

>  If you check out the docutils documentation,
> you might find docutils.core.publish_string() fits your needs.
>
> http://docutils.sourceforge.net/docs/api/publisher.html
Thanks, next on my list TO_READ.

[1] http://docutils.sourceforge.net/docs/ref/doctree.html
[2] http://www.arnebrodowski.de/blog/write-your-own-restructuredtext-writer.html

-- 
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: Parsing a reStructuredText

2011-10-25 Thread eaman


On Oct 25, 7:04 pm, eaman  wrote:
> On Oct 25, 6:46 pm, "J. Cliff Dyer"  wrote:
> [CUT]> What have you got so far?
I found this tutorial[1] that quite nails it, now I can traverse
through  document
and extract a piece of content.
I guess I'll have to learn to use a transformer -> writer to parse a
node
to some useful mark-up.


[1] http://www.ibm.com/developerworks/library/x-matters24/#code5

-- 
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.



Accesing a foreign key parent model attribute from a related class

2010-02-05 Thread eaman
Hello, I'm working on a photo gallery web app, and
I've got a question aboute the models:

class Gallery(models.Model):
title   = models.CharField(max_length=30)
dir = models.CharField(max_length=20)


class Photo(models.Model):
title = models.CharField(max_length=30)
photo  = models.ImageField(upload_to='foto')
gallery= models.ForeignKey('Gallery')

I'd like to upload the Photos (models.ImageField(upload_to='foto') )
to ``dir / foto``, with 'dir' taken from the class Gallery.
My question is: how can i build the  path "(upload_to='foto')"  with
Gallery.dir ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Accesing a foreign key parent model attribute from a related class

2010-02-05 Thread eaman


On Feb 5, 10:01 pm, Dj Gilcrease  wrote:
[CUT]
> http://dpaste.com/hold/155132/
>
> That should do it
Thanks a lot, I was thinking of getting that path in a couple of ways
that are way less 'pythonic' and elegant then your proposed solution.
instance.gallery.dir and a function does the trick.

If someone else would find it of use, just add the filename to the
path like:

def _get_photo_upload_to(instance, filename):
#return os.path.abspath(instance.galleria.dir + 'foto').replace('\
\', '/')
return (instance.galleria.dir + '/foto/' + filename )

Thanks again,
eaman

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Next previous links from a query set / generi views

2010-02-06 Thread eaman
Hello, I have a quite simple query set and a related generic views:
http://dpaste.com/155494/
And template for generating a detail page of a photo.

Is there an easy way to have a link to  previous | next element in the
template
without manualy coding a view ?

Somthing like a:
{% if foto.next_item %}
 Next
{% endif}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Next previous links from a query set / generi views

2010-02-07 Thread eaman


On Feb 7, 3:24 am, Eric Abrahamsen  wrote:
> Yup, if you have non-null date/datetime fields on your model, each  
> model will automatically get "get_next_by_FOO" and  
> "get_previous_by_FOO" methods, where FOO is the name of the datetime  
Well I guess the 'Lazy' optiond is to add a date field to my model and
get the free pagination. Or code my own view, of course.

Thanks.
/eaman
[CUT]

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Next previous links from a query set / generi views

2010-02-07 Thread eaman


On Feb 7, 2:56 pm, Eric Abrahamsen  wrote:
> On Feb 7, 2010, at 8:54 PM, eaman wrote:
[CUT]
> The lazy option would probably be to add get_next() and get_previous()  
> methods to your model, that return an instance based on whatever  
> definition of "next" and "previous" works for you. You might consider  
> some kind of timestamp field for your model, though – you'd be  
> surprised how often that comes in handy…

Thanks, I've made a try with the free pagination, which is nice and
easy
but doesn't work out of the box as I would like (but that's probbly me
unable to pass an extra parameter to limit the query set...).

I'm up to code those two methods, I guess I'll try first to embed them
in the model and then to think about of some form of abstraction to
use them
with others similar models.

Generic views are really nice, but I guess it's time for me to  dive
deeper in models and views.

Thanks for the clue.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Next previous links from a query set / generi views

2010-02-07 Thread eaman
> I'm up to code those two methods...
If some one is interested in this thread I managed to code
these two methods: get_next | get_prev
in order to get a previous or next item in a set right from my model:
- http://dpaste.com/155961/

- Is there a better way to get the highest  'previous' item then
using
aggregate(Max('id'))?

- I guess the if /else conditional loop that should check the
existence of the prev | next item is suboptimal...

/eaman

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Next previous links from a query set / generi views

2010-02-08 Thread eaman
On Feb 8, 3:38 am, Eric Abrahamsen  wrote:
[CUT]
> Now that you've got a date attribute, why not use that for next and  
> previous?
1. Date based next and prev go throught the whole photo set,
but I prefer next and prev to provide only items inside a gallery.
But I guess that's just me unable to pass an extra parameter
to the generic view.

2. I'm learning: I wanted to test an other way to get this navigation
links,
coding some custom methods.

> If you don't want to do that, you still might consider returning a  
> real object instance,
Yes this should be better, it could be more userfull if I had to
generate a PDF or some other kind of output.

> and then giving the model a get_absolute_url()  
> method and calling that in the template. That will save you hardcoding  
> the links in the template.
- http://docs.djangoproject.com/en/dev/ref/models/instances/#get-absolute-url
Thanks for the advice: this will make deployment and refactoring
easier.

>
> But if it's just an id you want, the following might be more efficient:
>
> def get_next(self):
>      all_ids = Foto.objects.filter(galleria = self.galleria,  
> id__gt=self.id).values_list("id",flat=True).order_by("id")
>      try:
>          return min(all_ids)
>      except ValueError:
>          return None
>
> Then reverse that (id__lt=self.id and use the max python function) for  
> get_prev()
>
> Hope that's helpful,
> Eric
Oh yes thanks a lot, code examples are really useful to  me as I'm not
yet very familiar with of all this 'snaky' dotted object syntax /
traversing;
I'll get into the django shell and play a bit with this.

Thanks for all this suggestions.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.