[mezzanine-users] Validating BlogPost model categories

2015-08-24 Thread Matt Hughes

Hi when i add a blog post via the admin page, how do i validate the 
categories?

Ive tried overriding the 'clean()' method of BlogPost, which does get 
called, but not sure where to check for categories.

when i submit a post via the admin, i want to make sure it has atleast one 
category.
I have also modified my blogcategory model to include a 'parent_category' 
field, and i want the make sure the BlogPost also includes all 
parent_categories, so post with also be listed under these parent_categories

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: Validating BlogPost model categories

2015-08-24 Thread Matt Hughes
Ok i think i might have figured it out, I needed to hook the save_related() 
method from BlogPostAdmin
not sure if this is the correct way tho, i just hooked into 
__getattribute__, and watched for any methods that looked useful

so i ended up adding the following to BlogPostAdmin

def save_related(self, request, form, formsets, change):
aaa = super(BlogPostAdmin, self).save_related(request, form, 
formsets, change)
cats = form.instance.categories.all()
parents = []
for a in cats:
maxx = 10
while a.parent_category != None and maxx > 0:
parents.append(a.parent_category)
a = a.parent_category
maxx = maxx - 1
for a in parents:
form.instance.categories.add(a)
return aaa

not sure if i need the loop counter, i just get nervous when using while 
loops lol

On Tuesday, August 25, 2015 at 12:12:02 AM UTC-4, Matt Hughes wrote:
>
>
> Hi when i add a blog post via the admin page, how do i validate the 
> categories?
>
> Ive tried overriding the 'clean()' method of BlogPost, which does get 
> called, but not sure where to check for categories.
>
> when i submit a post via the admin, i want to make sure it has atleast one 
> category.
> I have also modified my blogcategory model to include a 'parent_category' 
> field, and i want the make sure the BlogPost also includes all 
> parent_categories, so post with also be listed under these parent_categories
>
> Thanks!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: EXTRA_MODEL_FIELDS - ForeignKey to self

2015-08-28 Thread Matt Hughes
anyway to implement this without changing 'boot/__init__' directly?

On Friday, February 20, 2015 at 4:50:57 PM UTC-5, Mathias Ettinger wrote:
>
> I guess it’s because both EXTRA_MODEL_FIELDS and strings referencing 
> classes as ForeignKey positional argument rely on the class_prepared 
> signal. But with it being only sent once, the ForeignKey doesn't have any 
> chance to catch the signal in time.
>
> For every other use case other than a self-referencing ForeignKey, either 
> the model being referenced has been created when the extra ForeignKey is 
> added and it can be resolved as a class right away, or the ForeignKey will 
> be able to resolve the class as soon as it send the class_prepared signal.
> In the case of a self-referencing extra ForeignKey, the ForeignKey is 
> added after the class_prepared signal has been fired but can't resolve the 
> string into a class yet because the model has not finished initializing. So 
> the ForeignKey connect to the class_prepared signal and wait for the class 
> that just fired it to fire it "again". In vain.
>
> One solution could be to re-raise the class_prepared signal after extra 
> fields had been added to a model. To do so, you could change the 
> add_extra_model_fields function in mezzanine/boot/__init__.py to:
> def add_extra_model_fields(sender, **kwargs):
> """
> Injects custom fields onto the given sender model as defined
> by the ``EXTRA_MODEL_FIELDS`` setting.
> """
> model_path = "%s.%s" % (sender.__module__, sender.__name__)
> extra_fields = fields.get(model_path, {})
> if (extra_fields):
> for field_name, field in extra_fields.items():
> field.contribute_to_class(sender, field_name)
> del fields[model_path]
> # re-send the class_prepared signal so self-referencing ForeignKey 
> can catch up
> class_prepared.send(sender=sender)
>
>
> Le vendredi 20 février 2015 17:44:37 UTC+1, Kacper Kołodziej a écrit :
>>
>> Hi! I'm trying to create multi-level categories structure. I have added 
>> ForeignKey to 'self' to BlogCategory. I've tried to do it in some different 
>> ways: http://pastebin.com/77ex9ehe but none of them works. I always 
>> receive error on syncdb:
>>
>> CommandError: One or more models did not validate:
>>> blog.blogcategory: 'parent_category' has a relation with model self, 
>>> which has either not been installed or is abstract.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] how to subclass BlogPost model, and replace in admin site

2015-09-05 Thread Matt Hughes
Hi i would like to add some additional processing to the BlogPost model,
but im having a difficulty trying to figure out how to properly subclass 
it, and register it to the admin page.

for now ive just done something simple like this in my models.py

class MyBlogPost(BlogPost):
pass


and in my admin.py

from mezzanine.blog.admin import BlogPostAdmin
from mezzanine.blog.models import BlogPost
from .models import MyBlogPost

admin.site.unregister(BlogPost)
admin.site.register(MyBlogPost, BlogPostAdmin)


But the I just get an 'BlogPost is not registered' error, so im doing 
something wrong

So what the correct to replace BlogPost with my subclass?

Im sure i had this figured out previously, but removed it temporarily, and 
now cant remember how i did it.
Trying to google for it like i did before hasn't gotten me anywhere.

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: how to subclass BlogPost model, and replace in admin site

2015-09-05 Thread Matt Hughes
I think i should be a little more clear what im trying to do,
I have added a charfield to the BlogPost model, using 'EXTRA_MODEL_FIELDS' 
injection
the charfield is a comma separated list of web links
When the model is submitted, i need to check this field, and build a 
separate model entry for each link, and associate these entries to the 
blogpost



On Saturday, September 5, 2015 at 1:32:59 PM UTC-4, Matt Hughes wrote:
>
> Hi i would like to add some additional processing to the BlogPost model,
> but im having a difficulty trying to figure out how to properly subclass 
> it, and register it to the admin page.
>
> for now ive just done something simple like this in my models.py
>
> class MyBlogPost(BlogPost):
> pass
>
>
> and in my admin.py
>
> from mezzanine.blog.admin import BlogPostAdmin
> from mezzanine.blog.models import BlogPost
> from .models import MyBlogPost
>
> admin.site.unregister(BlogPost)
> admin.site.register(MyBlogPost, BlogPostAdmin)
>
>
> But the I just get an 'BlogPost is not registered' error, so im doing 
> something wrong
>
> So what the correct to replace BlogPost with my subclass?
>
> Im sure i had this figured out previously, but removed it temporarily, and 
> now cant remember how i did it.
> Trying to google for it like i did before hasn't gotten me anywhere.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: how to subclass BlogPost model, and replace in admin site

2015-09-05 Thread Matt Hughes
i think i was approaching this wrong, i think i need to hook the save_model 
of BlogPostAdmin not BlogPost


On Saturday, September 5, 2015 at 1:32:59 PM UTC-4, Matt Hughes wrote:
>
> Hi i would like to add some additional processing to the BlogPost model,
> but im having a difficulty trying to figure out how to properly subclass 
> it, and register it to the admin page.
>
> for now ive just done something simple like this in my models.py
>
> class MyBlogPost(BlogPost):
> pass
>
>
> and in my admin.py
>
> from mezzanine.blog.admin import BlogPostAdmin
> from mezzanine.blog.models import BlogPost
> from .models import MyBlogPost
>
> admin.site.unregister(BlogPost)
> admin.site.register(MyBlogPost, BlogPostAdmin)
>
>
> But the I just get an 'BlogPost is not registered' error, so im doing 
> something wrong
>
> So what the correct to replace BlogPost with my subclass?
>
> Im sure i had this figured out previously, but removed it temporarily, and 
> now cant remember how i did it.
> Trying to google for it like i did before hasn't gotten me anywhere.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] tinymce, stripping inline styles

2015-09-13 Thread Matt Hughes
Ive added an image to a blog post content, and set it to center, but when I 
save, the stye is stripped out.

The style being applied to the image is "margin-left: auto; margin-right: 
auto; display: block;"

I found a reference to a setting 'RICHTEXT_ALLOWED_STYLES' 
which allows the following styles to be used "margin-top", "margin-bottom", 
"margin-left", "margin-right", "float", "vertical-align", "border", "margin"

So if "margin-left", "margin-right" are allowed why are they being stripped 
out?


-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.