Re: Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread Dennis Marwood
Ok, thanks. It seems like such a common use case that I wanted to be sure 
there was not an existing template tag for it.


On Sunday, 30 August 2015 14:48:47 UTC-7, Christophe Pettus wrote:
>
>
> On Aug 30, 2015, at 2:37 PM, Christophe Pettus <x...@thebuild.com 
> > wrote: 
>
> > On Aug 30, 2015, at 12:43 PM, Dennis Marwood <dennis...@gmail.com 
> > wrote: 
> > 
> >> How do I get the template to treat {{ }} in my entry as a variable? 
> > 
> > The Django template language doesn't iterate over the results of 
> expansion; once a substitution is done, it moves on.  So, template language 
> constructs that "appear" in the result due to variable expansion. 
>
> As a note, this is a feature, not a bug: If template expansion iterated 
> like that, it would be a serious security hole, since someone could drop 
> template items ( {{ entry.delete }}, anyone?) into user-edited content.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bad2c6f3-cdf4-447d-87e1-9a50f439efd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread Dennis Marwood
So you are saying I should alter the models save method to do a search and 
replace on the entry field?

On Sunday, 30 August 2015 14:03:18 UTC-7, monoBOT monoBOT wrote:
>
> You can import your any part of your settings into the model.py file and 
> then insert it
>
> like this:
>
> from django.conf import MEDIA_URL
>
>
> 2015-08-30 20:43 GMT+01:00 Dennis Marwood <dennis...@gmail.com 
> >:
>
>> Hello,
>>
>> I have a seemingly straight forward and likely common issue. But there is 
>> no obvious way that I am seeing to make it work.
>>
>> I have a Blog model with a text field called entry. I want to put 
>> something like 
>>
>> 
>>
>> into the blog post. So Blog.entry would contain it. Then I use the 
>> template to display my blog post like
>>
>> {% for post in posts %} {{ post.entry }} {% endfor %}
>>
>> But the template does not process {{ MEDIA_URL }}. It just sees it as a 
>> string and prints it exactly as passed in.
>>
>> How do I get the template to treat {{ }} in my entry as a variable? How 
>> can I get that value substituted? I have used a custom template filter in 
>> the past. But this has got to be a very common use case. It seems like 
>> there would be some built in django way to get this to work?
>>
>> Thanks,
>> Dennis
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *monoBOT*
> Visite mi sitio(Visit my site): monobotsoft.es/blog/
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/99e5bce9-1537-4bd1-99b1-a2b6e14aa64b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread Dennis Marwood
Hello,

I have a seemingly straight forward and likely common issue. But there is 
no obvious way that I am seeing to make it work.

I have a Blog model with a text field called entry. I want to put something 
like 



into the blog post. So Blog.entry would contain it. Then I use the template 
to display my blog post like

{% for post in posts %} {{ post.entry }} {% endfor %}

But the template does not process {{ MEDIA_URL }}. It just sees it as a 
string and prints it exactly as passed in.

How do I get the template to treat {{ }} in my entry as a variable? How can 
I get that value substituted? I have used a custom template filter in the 
past. But this has got to be a very common use case. It seems like there 
would be some built in django way to get this to work?

Thanks,
Dennis

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I am not able to pass a variable to a widget with its "mark_safe" attribute intact.

2015-06-20 Thread Dennis Marwood
I found that the "correct" way to address this issue is to use 
raw_id_fields.

On Tuesday, 16 June 2015 19:46:51 UTC-7, Dennis Marwood wrote:
>
> Hello,
>
> I want to display images in my manyTomany so that a user can choose what 
> images would be included inside of a "BlogWidgetCarousel". The issue I am 
> running into is that the render function for the widget returns html via 
> the "format_html" and the variable has lost its "safe" setting at that 
> point.
>
> In my model I return the choice_label with "mark_safe" but somewhere along 
> the way the string is altered and it must be losing that quality. (For the 
> example I just changed it to a  tag)
>
> I have found the render method and confirmed that I can set the string 
> back to a safe state and it works fine.
>
> My questions
>
>1. Am I just making some kind of mistake when I try to send back the 
>string from the model?
>2. Am I doing something that is unexpected? It seems like this should 
>work.
>3. Would you create a custom widget to solve this issue, if not what 
>would you use?
>
>
>
>
> #models.py
> class BlogWidgetCarousel(models.Model):
> entry = models.TextField()
> blog = models.ForeignKey(Blog, blank=True, null=True)
> position = models.PositiveSmallIntegerField("Position")
> images = models.ManyToManyField("Image")
>
> class Meta:
> ordering = ('position', )
>
> def __str__(self):
> return str(self.position)
> 
> def save(self, *args, **kwargs):
> self.entry = "TODO: create image slider"
> super(BlogWidgetCarousel, self).save(*args, **kwargs)
>
> def display(self):
> return self.entry
>
> class Image(models.Model):
> title = models.CharField(max_length=60, blank=False, null=False)
> image = models.ImageField(upload_to="images/")
>
> def thumb(self):
> return ''.\
> format(MEDIA_URL + str(self.image))
>
> def __str__(self):
> return mark_safe(u'bold')
> __str__.allow_tags = True
>
>
> #admin.py
> class BlogWidgetCarouselInline(admin.StackedInline): #, SortableInline):
> model = BlogWidgetCarousel
> extra = 0
>
> formfield_overrides = {
> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
> }
>
> fieldsets = (
> ("Create Carousel:", {
> 'fields': (("position"), 'images',)
> }),
> ("Result:", {
> 'fields': ('thumb', 'display_as',)
> }),
> )
> readonly_fields = ('display_as', 'thumb',)
>
> def display_as(self, instance):
> return instance.display()
> display_as.allow_tags = True
>
> def thumb(self, instance):
> x = ""
> for i in instance.images.all():
> x += i.thumb()
> return x 
> thumb.allow_tags = True
>
> class EntryAdmin(admin.ModelAdmin):
> list_display = ("title", "created")
> prepopulated_fields = {"slug": ("title",)}
> inlines = [
> BlogWidgetTextInline, BlogWidgetCarouselInline,
> ]
>
>
> #dist-packages/django/forms/widgets
> #...
> @html_safe
> @python_2_unicode_compatible
> class ChoiceInput(SubWidget):
> """
> An object used by ChoiceFieldRenderer that represents a single
> .
> """
> input_type = None  # Subclasses must define this
>
> def __init__(self, name, value, attrs, choice, index):
> self.name = name
> self.value = value
> self.attrs = attrs
> self.choice_value = force_text(choice[0])
> self.choice_label = force_text(choice[1])
> self.index = index
> if 'id' in self.attrs:
> self.attrs['id'] += "_%d" % self.index
>
> def __str__(self):
> return self.render()
>
> def render(self, name=None, value=None, attrs=None, choices=()):
> if self.id_for_label:
> label_for = format_html(' for="{}"', self.id_for_label)
> else:
> label_for = ''
> attrs = dict(self.attrs, **attrs) if attrs else self.attrs
> #print self.choice_label < Prints "bold" as expected.
> return format_html('<label{}>{} {}', label_for, 
> self.tag(attrs), self.choice_label) # choice_label is escaped by format_html
> #return format_html('<label{}>{} {}', label_for, 
> self.tag(attrs), mark_safe(self.choice_label)) <---Works
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ab8d2ea-cf84-4e4f-ae21-507d70ed6e00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


I am not able to pass a variable to a widget with its "mark_safe" attribute intact.

2015-06-16 Thread Dennis Marwood
Hello,

I want to display images in my manyTomany so that a user can choose what 
images would be included inside of a "BlogWidgetCarousel". The issue I am 
running into is that the render function for the widget returns html via 
the "format_html" and the variable has lost its "safe" setting at that 
point.

In my model I return the choice_label with "mark_safe" but somewhere along 
the way the string is altered and it must be losing that quality. (For the 
example I just changed it to a  tag)

I have found the render method and confirmed that I can set the string back 
to a safe state and it works fine.

My questions

   1. Am I just making some kind of mistake when I try to send back the 
   string from the model?
   2. Am I doing something that is unexpected? It seems like this should 
   work.
   3. Would you create a custom widget to solve this issue, if not what 
   would you use?
   



#models.py
class BlogWidgetCarousel(models.Model):
entry = models.TextField()
blog = models.ForeignKey(Blog, blank=True, null=True)
position = models.PositiveSmallIntegerField("Position")
images = models.ManyToManyField("Image")

class Meta:
ordering = ('position', )

def __str__(self):
return str(self.position)

def save(self, *args, **kwargs):
self.entry = "TODO: create image slider"
super(BlogWidgetCarousel, self).save(*args, **kwargs)

def display(self):
return self.entry

class Image(models.Model):
title = models.CharField(max_length=60, blank=False, null=False)
image = models.ImageField(upload_to="images/")

def thumb(self):
return ''.\
format(MEDIA_URL + str(self.image))

def __str__(self):
return mark_safe(u'bold')
__str__.allow_tags = True


#admin.py
class BlogWidgetCarouselInline(admin.StackedInline): #, SortableInline):
model = BlogWidgetCarousel
extra = 0

formfield_overrides = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}

fieldsets = (
("Create Carousel:", {
'fields': (("position"), 'images',)
}),
("Result:", {
'fields': ('thumb', 'display_as',)
}),
)
readonly_fields = ('display_as', 'thumb',)

def display_as(self, instance):
return instance.display()
display_as.allow_tags = True

def thumb(self, instance):
x = ""
for i in instance.images.all():
x += i.thumb()
return x 
thumb.allow_tags = True

class EntryAdmin(admin.ModelAdmin):
list_display = ("title", "created")
prepopulated_fields = {"slug": ("title",)}
inlines = [
BlogWidgetTextInline, BlogWidgetCarouselInline,
]


#dist-packages/django/forms/widgets
#...
@html_safe
@python_2_unicode_compatible
class ChoiceInput(SubWidget):
"""
An object used by ChoiceFieldRenderer that represents a single
.
"""
input_type = None  # Subclasses must define this

def __init__(self, name, value, attrs, choice, index):
self.name = name
self.value = value
self.attrs = attrs
self.choice_value = force_text(choice[0])
self.choice_label = force_text(choice[1])
self.index = index
if 'id' in self.attrs:
self.attrs['id'] += "_%d" % self.index

def __str__(self):
return self.render()

def render(self, name=None, value=None, attrs=None, choices=()):
if self.id_for_label:
label_for = format_html(' for="{}"', self.id_for_label)
else:
label_for = ''
attrs = dict(self.attrs, **attrs) if attrs else self.attrs
#print self.choice_label < Prints "bold" as expected.
return format_html('{} {}', label_for, 
self.tag(attrs), self.choice_label) # choice_label is escaped by format_html
#return format_html('{} {}', label_for, 
self.tag(attrs), mark_safe(self.choice_label)) <---Works


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e4d7ef94-181c-4f09-8471-e038455793e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for direction on some admin console customization.

2014-03-11 Thread Dennis Marwood


<https://lh6.googleusercontent.com/-Fh01T6C8p94/Ux-x7AD6AMI/AFo/3X3uSwB0MQw/s1600/django2.png>

<https://lh5.googleusercontent.com/-yC-ZF_liMG8/Ux-x1kenfPI/AFg/Ol5yRPZYjNQ/s1600/django1.png>
Derik, thanks for the reply. I reread my post; you are right, it is not 
very clear. I attached some images to this post that, I believe, will help 
to clarify.

I want to be able to add either an image_widgets or a text_widgets to a 
blog post in any order. I could code up something like the "Display Order" 
and that would work but I was hoping for something better.

Really, I am wondering if people would do this all w/ js or if there is a 
better way that relies on better model set up / interaction and using / 
extending some existing admin feature (like the "Add another" link).

Thanks

On Monday, 10 March 2014 23:43:33 UTC-7, Derek wrote:
>
> Dennis
>
> Your use case is not very clear; but it sounds more like you need a CMS, 
> even a simple one.  There you can design templates that will hold all your 
> page content in a layout of your choice.  There are many Django-based CMS 
> e.g. https://pythonhosted.org/django-page-cms/
>
> Derek
>
> (PS  Your terminology is a bit mixed up here- when you say "add a text 
> model, a video model", I think you mean "add a text object, a video 
> object".  The models are the containers; the objects are the - crudely 
> speaking - the data that makes those containers "exist")
>
>
> On Monday, 10 March 2014 04:09:05 UTC+2, Dennis Marwood wrote:
>>
>> My goal is to be able to build a new blog entry via the admin console 
>> that is comprised of text, image slider, and video models. 
>>
>> I would choose to create a new blog entry and then add a text model, a 
>> video model, and another text model, or something like that. Each blog 
>> entry could be unique in the models that it is made up of.
>>
>> I have messed around with adding the models via inlines. But that is just 
>> not quite enough. Each of the entries ends up in its own fieldset in an 
>> unintuitive disorganized display. 
>>
>> What are some approaches to implementing this? It would be great if I 
>> could have a drop down or something that let me add a model entry, of my 
>> choosing, and it was just pushed into the blog entry.
>>
>> Thanks in advance.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a0b3183a-c962-4cab-a742-24ee71405d8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Looking for direction on some admin console customization.

2014-03-09 Thread Dennis Marwood
My goal is to be able to build a new blog entry via the admin console that 
is comprised of text, image slider, and video models. 

I would choose to create a new blog entry and then add a text model, a 
video model, and another text model, or something like that. Each blog 
entry could be unique in the models that it is made up of.

I have messed around with adding the models via inlines. But that is just 
not quite enough. Each of the entries ends up in its own fieldset in an 
unintuitive disorganized display. 

What are some approaches to implementing this? It would be great if I could 
have a drop down or something that let me add a model entry, of my 
choosing, and it was just pushed into the blog entry.

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/009c14be-04d8-417b-b8f0-bd0e9ae4fb28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using inlines on a one to many but not seeing "add another" link

2014-03-06 Thread Dennis Marwood
I found the answer to my issue, posting it here in case others have the 
same issue. 

The problem was caused by an old version of inline.js being loaded. I ran 
collectstatic at some point and a version of the script from 1.3 was saved.

On Saturday, 1 March 2014 15:53:41 UTC-8, Dennis Marwood wrote:
>
> Hello. 
> Here are my models and admin.py  dpaste.de <https://dpaste.de/oNTG>
> And here is the what I am referring to 
> https://docs.djangoproject.com/en/1.6/intro/tutorial02/#customize-the-admin-form
> But I my not seeing the link to add another. 
>
> Thanks
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6733723e-271c-4762-9424-bd00b6de8e92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using inlines on a one to many but not seeing "add another" link

2014-03-02 Thread Dennis Marwood
I tried deleting the db and running syncdb again (even though that will not 
be a viable fix) and this issue was still present.

Could you explain why this problem appeared and / or how to fix this issue? 
Did I miss something in the upgrade process? The docs just say to use pip 
and check the release notes.

Thank you :)

On Sunday, 2 March 2014 15:40:44 UTC-8, Camilo Torres wrote:
>
> On Saturday, 1 March 2014 15:53:41 UTC-8, Dennis Marwood wrote:
>>
>> Hello. 
>> Here are my models and admin.py  dpaste.de <https://dpaste.de/oNTG>
>> And here is the what I am referring to 
>> https://docs.djangoproject.com/en/1.6/intro/tutorial02/#customize-the-admin-form
>> But I my not seeing the link to add another. 
>>
> On Sunday, March 2, 2014 5:27:17 PM UTC-4:30, Dennis Marwood wrote:
>>
>> The only difference between the two apps that I can see is that I created 
>> the old one w/ django 1.4.
>>
>
>  That is a really _big_ difference, and surely is the cause for your error 
> :)
>
> Regards,
> Camilo
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3dd49c4e-ec2e-444e-9aa4-a799e2081683%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Using inlines on a one to many but not seeing "add another" link

2014-03-02 Thread Dennis Marwood
I went back to my original polls app and the link is not there either. 
So I spun up a new project and created the polls app again and found the 
link there. 

The only difference between the two apps that I can see is that I created 
the old one w/ django 1.4.

On Saturday, 1 March 2014 15:53:41 UTC-8, Dennis Marwood wrote:
>
> Hello. 
> Here are my models and admin.py  dpaste.de <https://dpaste.de/oNTG>
> And here is the what I am referring to 
> https://docs.djangoproject.com/en/1.6/intro/tutorial02/#customize-the-admin-form
> But I my not seeing the link to add another. 
>
> Thanks
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80381a10-8b18-4b10-94a5-1f069b9409c9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Using inlines on a one to many but not seeing "add another" link

2014-03-01 Thread Dennis Marwood
Hello. 
Here are my models and admin.py  dpaste.de 
And here is the what I am referring to 
https://docs.djangoproject.com/en/1.6/intro/tutorial02/#customize-the-admin-form
But I my not seeing the link to add another. 

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aaeed9f1-e499-4d09-b7c5-4ca087a4119b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Accessing a python function from a blog post stored in the db?

2014-02-27 Thread Dennis Marwood
OK I think you are talking about something like 
https://docs.djangoproject.com/en/dev/intro/tutorial02/#adding-related-objects 
where I could just insert a slider type of entry and then a text entry and 
so on. Is that it?

On Wednesday, 26 February 2014 14:49:55 UTC-8, C. Kirby wrote:
>
> It doesn't have to, I guess it depends on how involved the creation tools 
> are that you create. Quick and dirty idea off the top of my head:
> If the authoring tools define post widgets (body, text, scroller, video, 
> etc) you could let authors drag and drop the elements as they wish. On the 
> model side, make all resources extend a base class of BlogResource type, 
> then for each blog post have a many to many through table that stores 
> ordering:
> PostID(foriegn=blog)
> ResourceID(genericforeignkey to blog resource)
> OrderID(int)
>
> or somthing like that.
>
> Regards,
> ~CK
>
> On Wednesday, February 26, 2014 4:18:14 PM UTC-6, Dennis Marwood wrote:
>>
>> Won't this force my blog posts to all be the same. i.e. Text then a image 
>> scroller? 
>> How would I handle the case where a blog post was Text, image scroller, 
>> text, image scroller?
>>
>> On Wednesday, 26 February 2014 13:35:01 UTC-8, C. Kirby wrote:
>>>
>>> It sounds like your implementation is a little skewed.
>>> If a blog post is made of multiple resources (summary, body, multiple 
>>> image collections, etc.) You should probably have a model or models with 
>>> the appropriate fields/relationships.  That way your template can house all 
>>> of the template language, and you build a single, user facing blog post 
>>> from the elements in the blog post model(s).
>>> This also gives you the benefit of making the various resources 
>>> available in other ways (eg. Show all my image collections, share 
>>> collections, etc) as well as change your layout in the future without 
>>> having hard-coded template calls in your content.
>>>
>>> Regards
>>> ~CK
>>>
>>> On Wednesday, February 26, 2014 3:18:54 PM UTC-6, Dennis Marwood wrote:
>>>>
>>>> Thanks. I look forward to trying this soon.
>>>>
>>>> I feel like I may be trying to swim against the current with this. Is 
>>>> this a problem with the way that I have decided to implement my blog or 
>>>> are 
>>>> these workarounds typical for django applications?
>>>>
>>>> On Wednesday, 26 February 2014 04:15:15 UTC-8, Tom Evans wrote:
>>>>>
>>>>> On Wed, Feb 26, 2014 at 5:29 AM, Dennis Marwood <dennis...@gmail.com> 
>>>>> wrote: 
>>>>> > Thanks. I believe this is what I am looking for. However I am still 
>>>>> running 
>>>>> > into an issue w/ the fact that I am pulling my blog entries from the 
>>>>> db. 
>>>>> > This is causing the template to interpret the {% image_slider %} as 
>>>>> a 
>>>>> > string. 
>>>>> > 
>>>>> > From view.py: 
>>>>> > def blog(request): 
>>>>> > entries = 
>>>>> > 
>>>>> Project.objects.filter(destination="blog").order_by('-creation_date') 
>>>>> > return render(request, 'content.html', {"entries": entries, 
>>>>> >"page_title": "Blog", 
>>>>> >"description": 
>>>>> "Blog"}) 
>>>>> > 
>>>>> > And in content.html: 
>>>>> > {% for each in entries %} 
>>>>> > {{ each.entry }} 
>>>>> > {% endfor %} 
>>>>> > 
>>>>> > And a blog entry: 
>>>>> > Hello! Check out this collection of images. {% image_slider %} And 
>>>>> this 
>>>>> > collection! {% image_slider %} 
>>>>> > 
>>>>> > 
>>>>> > I don't want to hard code the inclusion tag in the content.html. 
>>>>> Instead I 
>>>>> > want to call it from the blog post. Is this possible? 
>>>>>
>>>>> Yes. You will need to write a custom template tag to parse the 
>>>>> contents of the object as a template, render it within the current 
>>>>> context and return the generated data. 
>>>>>
>>>>> Writing a custom template tag: 
>>>>>
>>>

Re: Accessing a python function from a blog post stored in the db?

2014-02-26 Thread Dennis Marwood
Won't this force my blog posts to all be the same. i.e. Text then a image 
scroller? 
How would I handle the case where a blog post was Text, image scroller, 
text, image scroller?

On Wednesday, 26 February 2014 13:35:01 UTC-8, C. Kirby wrote:
>
> It sounds like your implementation is a little skewed.
> If a blog post is made of multiple resources (summary, body, multiple 
> image collections, etc.) You should probably have a model or models with 
> the appropriate fields/relationships.  That way your template can house all 
> of the template language, and you build a single, user facing blog post 
> from the elements in the blog post model(s).
> This also gives you the benefit of making the various resources available 
> in other ways (eg. Show all my image collections, share collections, etc) 
> as well as change your layout in the future without having hard-coded 
> template calls in your content.
>
> Regards
> ~CK
>
> On Wednesday, February 26, 2014 3:18:54 PM UTC-6, Dennis Marwood wrote:
>>
>> Thanks. I look forward to trying this soon.
>>
>> I feel like I may be trying to swim against the current with this. Is 
>> this a problem with the way that I have decided to implement my blog or are 
>> these workarounds typical for django applications?
>>
>> On Wednesday, 26 February 2014 04:15:15 UTC-8, Tom Evans wrote:
>>>
>>> On Wed, Feb 26, 2014 at 5:29 AM, Dennis Marwood <dennis...@gmail.com> 
>>> wrote: 
>>> > Thanks. I believe this is what I am looking for. However I am still 
>>> running 
>>> > into an issue w/ the fact that I am pulling my blog entries from the 
>>> db. 
>>> > This is causing the template to interpret the {% image_slider %} as a 
>>> > string. 
>>> > 
>>> > From view.py: 
>>> > def blog(request): 
>>> > entries = 
>>> > Project.objects.filter(destination="blog").order_by('-creation_date') 
>>> > return render(request, 'content.html', {"entries": entries, 
>>> >"page_title": "Blog", 
>>> >"description": "Blog"}) 
>>> > 
>>> > And in content.html: 
>>> > {% for each in entries %} 
>>> > {{ each.entry }} 
>>> > {% endfor %} 
>>> > 
>>> > And a blog entry: 
>>> > Hello! Check out this collection of images. {% image_slider %} And 
>>> this 
>>> > collection! {% image_slider %} 
>>> > 
>>> > 
>>> > I don't want to hard code the inclusion tag in the content.html. 
>>> Instead I 
>>> > want to call it from the blog post. Is this possible? 
>>>
>>> Yes. You will need to write a custom template tag to parse the 
>>> contents of the object as a template, render it within the current 
>>> context and return the generated data. 
>>>
>>> Writing a custom template tag: 
>>>
>>>
>>> https://docs.djangoproject.com/en/1.6/howto/custom-template-tags/#writing-custom-template-tags
>>>  
>>>
>>> Rendering templates to string: 
>>>
>>>
>>> https://docs.djangoproject.com/en/1.6/ref/templates/api/#rendering-a-context
>>>  
>>>
>>> Your content.html would then look something like this, assuming you 
>>> called the custom tag 'render': 
>>>
>>> {% for each in entries %} 
>>> {% render each.entry %} 
>>> {% endfor %} 
>>>
>>> Beware the massive security holes if you allow users to generate 
>>> content that your site then renders as a template. 
>>>
>>> Cheers 
>>>
>>> Tom 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a010cac7-55c9-4d53-bb58-086e0b832c48%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Accessing a python function from a blog post stored in the db?

2014-02-26 Thread Dennis Marwood
Thanks. I look forward to trying this soon.

I feel like I may be trying to swim against the current with this. Is this 
a problem with the way that I have decided to implement my blog or are 
these workarounds typical for django applications?

On Wednesday, 26 February 2014 04:15:15 UTC-8, Tom Evans wrote:
>
> On Wed, Feb 26, 2014 at 5:29 AM, Dennis Marwood 
> <dennis...@gmail.com> 
> wrote: 
> > Thanks. I believe this is what I am looking for. However I am still 
> running 
> > into an issue w/ the fact that I am pulling my blog entries from the db. 
> > This is causing the template to interpret the {% image_slider %} as a 
> > string. 
> > 
> > From view.py: 
> > def blog(request): 
> > entries = 
> > Project.objects.filter(destination="blog").order_by('-creation_date') 
> > return render(request, 'content.html', {"entries": entries, 
> >"page_title": "Blog", 
> >"description": "Blog"}) 
> > 
> > And in content.html: 
> > {% for each in entries %} 
> > {{ each.entry }} 
> > {% endfor %} 
> > 
> > And a blog entry: 
> > Hello! Check out this collection of images. {% image_slider %} And this 
> > collection! {% image_slider %} 
> > 
> > 
> > I don't want to hard code the inclusion tag in the content.html. Instead 
> I 
> > want to call it from the blog post. Is this possible? 
>
> Yes. You will need to write a custom template tag to parse the 
> contents of the object as a template, render it within the current 
> context and return the generated data. 
>
> Writing a custom template tag: 
>
>
> https://docs.djangoproject.com/en/1.6/howto/custom-template-tags/#writing-custom-template-tags
>  
>
> Rendering templates to string: 
>
>
> https://docs.djangoproject.com/en/1.6/ref/templates/api/#rendering-a-context 
>
> Your content.html would then look something like this, assuming you 
> called the custom tag 'render': 
>
> {% for each in entries %} 
> {% render each.entry %} 
> {% endfor %} 
>
> Beware the massive security holes if you allow users to generate 
> content that your site then renders as a template. 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/84d40bec-8dfb-4b6d-99e3-9e908fa6fbfc%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Accessing a python function from a blog post stored in the db?

2014-02-25 Thread Dennis Marwood
Thanks. I believe this is what I am looking for. However I am still running 
into an issue w/ the fact that I am pulling my blog entries from the db. 
This is causing the template to interpret the {% image_slider %} as a 
string.

>From view.py:
def blog(request):
entries = 
Project.objects.filter(destination="blog").order_by('-creation_date')
return render(request, 'content.html', {"entries": entries,
   "page_title": "Blog",
   "description": "Blog"})

And in content.html:
{% for each in entries %}
{{ each.entry }}
{% endfor %}

And a blog entry:
Hello! Check out this collection of images. {% image_slider %} And this 
collection! {% image_slider %}


I don't want to hard code the inclusion tag in the content.html. Instead I 
want to call it from the blog post. Is this possible?


On Tuesday, 25 February 2014 05:52:33 UTC-8, jondbaker wrote:
>
> This sounds like a good fit for an inclusion tag. Since you need a bit of 
> markup around the images for the slider functionality, it'd be nice to keep 
> that markup in a separate template so you could use the image slider in 
> multiple places like, say, a post detail page as well as a dashboard. Then, 
> anytime you wanted to create image slider, in your template you could 
> simply do something like:
>
> {% load image_extras %}
>
> ...
> {% image_slider post.image_set %}
> ...
>
> Docs: 
> https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags
>
> JDB
>
>
> On Mon, Feb 24, 2014 at 11:39 PM, Dennis Marwood 
> <dennis...@gmail.com
> > wrote:
>
>> Hi. I am looking for some advice on the best way to approach the 
>> following: 
>>
>> I am pulling my blog posts out of my db. Inside of the posts I want to 
>> use an image scroller ( http://cssdeck.com/labs/css3-image-slider ), but 
>> I don't want to write all of the boilerplate surrounding each image every 
>> time. 
>>
>> The idea I have is a template filter but that just seems wrong. 
>> What's the proper way to handle this?
>>
>> Ideally, I would just add some bit in my post like css_slider({loc: 
>> loc_pic_1, desc: "blah blah"}, {loc: loc_pic_1, desc: "blah"}...)
>>  
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d38e2a00-5ae9-4e8e-8333-0677cc206a5e%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b057db2a-2930-455d-94b3-1c9e6741ed91%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Accessing a python function from a blog post stored in the db?

2014-02-25 Thread Dennis Marwood
Hi. I am looking for some advice on the best way to approach the following: 

I am pulling my blog posts out of my db. Inside of the posts I want to use 
an image scroller ( http://cssdeck.com/labs/css3-image-slider ), but I 
don't want to write all of the boilerplate surrounding each image every 
time. 

The idea I have is a template filter but that just seems wrong. What's 
the proper way to handle this?

Ideally, I would just add some bit in my post like css_slider({loc: 
loc_pic_1, desc: "blah blah"}, {loc: loc_pic_1, desc: "blah"}...)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d38e2a00-5ae9-4e8e-8333-0677cc206a5e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.