Re: [mezzanine-users] Adding a Button to TinyMCE Issue

2017-10-16 Thread marcusguttenplan
Thank you for your response!

I had tried to use this (from tinymce docs 
) in the init 
function:
toolbar: 'hrbutton',

setup: function (editor) {
console.log("setup fn hit");
editor.addButton('hrbutton', {
  text: '|',
  icon: false,
  onclick: function () {
editor.insertContent('');
  }
});
},

but with no success. Your question made me realize that I had been editing 
grapelli's tinymce_setup and not mezzanine's. Unfortunately the same 
toolbar field and setup function do not work in mezzanine's tinymce_setup 
either. The changes were't appearing at all. Finally overriding the default 
tinymce_setup worked fine.

TINYMCE_SETUP_JS = 'js/customtinymce_setup.js'


Thank you for your help!



On Monday, October 16, 2017 at 7:38:58 PM UTC-7, Ryne Everett wrote:
>
> Pardon if I'm misunderstanding the question, but are you adding it to 
> the toolbar field in tinymce_setup? 
>

-- 
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] Adding a Button to TinyMCE Issue

2017-10-16 Thread marcusguttenplan
I have been working to add a custom button to tinyMCE, but the button is 
not appearing and I am having trouble debugging. I looked through past 
questions on here, as well as SO and the tinyMCE docs, but haven't found a 
solution that works.

I want to add a button for an hr tag. There is a plugin that exists for this 
 (though with the default parent 
menu "insert"). I've added it to the plugins option.

plugins: 
"hr,advimage,advlink,fullscreen,paste,media,searchreplace,grappelli,grappelli_contextmenu,template"
,

I have also tried 
theme_advanced_buttons1: 
"formatselect,styleselect,|,bold,italic,underline,|,bullist,numlist,blockquote,|,undo,redo,|,link,unlink,|,image,|,fullscreen,|,hr,|,grappelli_adv"
,

As well as
theme_advanced_buttons1_add:
from the docs.

I've also tried registering the hr button inside of 
`theme_advanced_buttons2` and `theme_advanced_blockformats`, but neither of 
those work. Maybe I need to override the plugin's default parent? Do I need 
to create the plugin myself an include it, or download from source?

Any advice or a point in the right direction would be appreciated! Thank 
you for your time and for a great open source project.

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


Re: [mezzanine-users] Re: Extending Displayable Model, Views

2017-07-09 Thread marcusguttenplan
Just solved this 404 issue, such a stupid mistake! Was using (now 
deprecated) `urlpatterns = patterns()`, just switch out patterns for a 
simple `urlpatterns = []` and all works as expected.

Have also successfully reversed the blog's views enough to return data!

Thanks for the help Eduardo, just enough of a push to get going.

On Sunday, July 9, 2017 at 10:00:23 AM UTC-7, marcusgu...@gmail.com wrote:
>
> Currently they are before the catch-all
> url("^", include("mezzanine.urls")),
>
> but after the redirect to index
> url("^$", direct_to_template, {"template": "index.html"}, name="home"),
>
> In the same pattern
> urlpatterns += []
>
> Trying to get debug statements into both the app's urlconf and views, but 
> the requests don't seem to be making it there. Also tried commenting out 
> Mezzanine's default 404 and 500 handlers, with no luck.
>
>
>
> On Saturday, July 8, 2017 at 3:46:53 PM UTC-7, Eduardo Rivas wrote:
>>
>> Have you included your url patterns before Mezzanine's catch-all in the 
>> root conf? 
>>
>> On Jul 7, 2017 1:37 PM,  wrote:
>>
>> Solved that, and have been constantly 404'ing since. Saw another of your 
>> posts Eduardo about i18n and middleware causing 404's on pages that don't 
>> exist, but have disabled i18n and am still running into issue. It's almost 
>> like the urls.py is not updating. 
>>
>> Here is the root url pattern I am using:
>> url("^news/", include("kdi.urls")),
>>
>> And the urls.py for kdi:
>> url(r"^$", "kdi.views.newstest", name="newstest"),
>>
>> And the `newstest` view:
>> def newstest(request, slug):
>> print "called!"
>> return HttpResponse('Test')
>>
>>
>> Expected behavior should be that navigation to domain/news will send the 
>> request to `kdi.urls`, where it will accept any string (^$) and call the 
>> `newstest` view to return the super simple response of "test". 404's every 
>> time.
>>
>>
>>
>>
>> On Friday, July 7, 2017 at 11:11:38 AM UTC-7, marcusgu...@gmail.com 
>> wrote:
>>>
>>> Have solved the fully qualified path issue, but now throwing `'unicode' 
>>> object has no attribute 'regex'` error. This one is more difficult to 
>>> traceback.
>>>
>>> On Thursday, July 6, 2017 at 8:12:00 PM UTC-7, marcusgu...@gmail.com 
>>> wrote:

 Hi, thanks for such a great resource! I have googled around for a few 
 days and have made some headway this problem, but have hit a wall. I'm 
 trying to use the Displayable model to create an easy way to add news 
 stories and have them displayed as a simple list view, which is very 
 similar behavior to the blog app. If there is a better solution using a 
 ForeignKey, please point me in the right direction!

 I read an older post 
 
  about 
 creating a new Displayable, and have used Mezzanine's source code to 
 successfully extend the Displayable model and have it appear correctly in 
 the admin. The issue now is that I can't seem to get the views (views.py) 
 and url patterns to work. When clicked "view on site" from the admin, the 
 url seems to grab the model's slug ("news"), but ends up linking to 
 http://localhost:8000/en/admin//news/%28u/, and doesn't work 
 linking directly to the actual item's slug. Exploring the source code for 
 Mezzanine's blog's urls and views, I'm unsure how to correctly refactor. I 
 understand that I will need to create my own templates to act as 
 blog_post_list.html 
 and blog_post_detail.html, but don't know how to create the super 
 basic views to point to them.

 models.py:
 class News(Displayable, RichText):

 pagetitle = models.CharField('Title', max_length=255, blank=True)
 url = models.CharField('Link', max_length=255, blank=True)
 summary = models.CharField('Summary', max_length=255, blank=True)
 date = models.DateField(_("Date"), default=datetime.date.today)
 categories = models.ManyToManyField("NewsCategory",
 verbose_name=_("Categories 
 (Magazine, Award, etc.)"),
 blank=True, 
 related_name="newsitems")
 related_news = models.ManyToManyField("self",
  verbose_name=_("Related News"), 
 blank=True)

 class Meta:
 verbose_name = _("News Item")
 verbose_name_plural = _("News Items")

 def get_absolute_url(self):
 url_name = 'news'
 kwargs = {
 'slug': self.slug,
 }
 return (url_name, (), kwargs)


 class NewsCategory(Slugged):
 """
 A category for grouping news items into a series.
 """

 class Meta:
 verbose_name = _("News Category")
 verbose_name_plural = _("News Categories")
 ordering 

Re: [mezzanine-users] Re: Extending Displayable Model, Views

2017-07-09 Thread marcusguttenplan
Currently they are before the catch-all
url("^", include("mezzanine.urls")),

but after the redirect to index
url("^$", direct_to_template, {"template": "index.html"}, name="home"),

In the same pattern
urlpatterns += []

Trying to get debug statements into both the app's urlconf and views, but 
the requests don't seem to be making it there. Also tried commenting out 
Mezzanine's default 404 and 500 handlers, with no luck.



On Saturday, July 8, 2017 at 3:46:53 PM UTC-7, Eduardo Rivas wrote:
>
> Have you included your url patterns before Mezzanine's catch-all in the 
> root conf? 
>
> On Jul 7, 2017 1:37 PM,  wrote:
>
> Solved that, and have been constantly 404'ing since. Saw another of your 
> posts Eduardo about i18n and middleware causing 404's on pages that don't 
> exist, but have disabled i18n and am still running into issue. It's almost 
> like the urls.py is not updating. 
>
> Here is the root url pattern I am using:
> url("^news/", include("kdi.urls")),
>
> And the urls.py for kdi:
> url(r"^$", "kdi.views.newstest", name="newstest"),
>
> And the `newstest` view:
> def newstest(request, slug):
> print "called!"
> return HttpResponse('Test')
>
>
> Expected behavior should be that navigation to domain/news will send the 
> request to `kdi.urls`, where it will accept any string (^$) and call the 
> `newstest` view to return the super simple response of "test". 404's every 
> time.
>
>
>
>
> On Friday, July 7, 2017 at 11:11:38 AM UTC-7, marcusgu...@gmail.com wrote:
>>
>> Have solved the fully qualified path issue, but now throwing `'unicode' 
>> object has no attribute 'regex'` error. This one is more difficult to 
>> traceback.
>>
>> On Thursday, July 6, 2017 at 8:12:00 PM UTC-7, marcusgu...@gmail.com 
>> wrote:
>>>
>>> Hi, thanks for such a great resource! I have googled around for a few 
>>> days and have made some headway this problem, but have hit a wall. I'm 
>>> trying to use the Displayable model to create an easy way to add news 
>>> stories and have them displayed as a simple list view, which is very 
>>> similar behavior to the blog app. If there is a better solution using a 
>>> ForeignKey, please point me in the right direction!
>>>
>>> I read an older post 
>>> 
>>>  about 
>>> creating a new Displayable, and have used Mezzanine's source code to 
>>> successfully extend the Displayable model and have it appear correctly in 
>>> the admin. The issue now is that I can't seem to get the views (views.py) 
>>> and url patterns to work. When clicked "view on site" from the admin, the 
>>> url seems to grab the model's slug ("news"), but ends up linking to 
>>> http://localhost:8000/en/admin//news/%28u/, and doesn't work 
>>> linking directly to the actual item's slug. Exploring the source code for 
>>> Mezzanine's blog's urls and views, I'm unsure how to correctly refactor. I 
>>> understand that I will need to create my own templates to act as 
>>> blog_post_list.html 
>>> and blog_post_detail.html, but don't know how to create the super basic 
>>> views to point to them.
>>>
>>> models.py:
>>> class News(Displayable, RichText):
>>>
>>> pagetitle = models.CharField('Title', max_length=255, blank=True)
>>> url = models.CharField('Link', max_length=255, blank=True)
>>> summary = models.CharField('Summary', max_length=255, blank=True)
>>> date = models.DateField(_("Date"), default=datetime.date.today)
>>> categories = models.ManyToManyField("NewsCategory",
>>> verbose_name=_("Categories 
>>> (Magazine, Award, etc.)"),
>>> blank=True, 
>>> related_name="newsitems")
>>> related_news = models.ManyToManyField("self",
>>>  verbose_name=_("Related News"), 
>>> blank=True)
>>>
>>> class Meta:
>>> verbose_name = _("News Item")
>>> verbose_name_plural = _("News Items")
>>>
>>> def get_absolute_url(self):
>>> url_name = 'news'
>>> kwargs = {
>>> 'slug': self.slug,
>>> }
>>> return (url_name, (), kwargs)
>>>
>>>
>>> class NewsCategory(Slugged):
>>> """
>>> A category for grouping news items into a series.
>>> """
>>>
>>> class Meta:
>>> verbose_name = _("News Category")
>>> verbose_name_plural = _("News Categories")
>>> ordering = ("title",)
>>>
>>> @models.permalink
>>> def get_absolute_url(self):
>>> return ("news_item_list_category", (), {"category": self.slug})
>>>
>>> admin.py
>>> news_fieldsets = deepcopy(DisplayableAdmin.fieldsets)
>>> news_fieldsets[0][1]["fields"].insert(1, "categories")
>>> news_fieldsets[0][1]["fields"].extend(["pagetitle", "url", "summary", 
>>> "date"])
>>> news_fieldsets = list(news_fieldsets)
>>> news_fieldsets.insert(1, (_("Other News"), {
>>> "classes": ("collapse-closed",),
>>> "fields": 

[mezzanine-users] Re: Extending Displayable Model, Views

2017-07-07 Thread marcusguttenplan
Solved that, and have been constantly 404'ing since. Saw another of your 
posts Eduardo about i18n and middleware causing 404's on pages that don't 
exist, but have disabled i18n and am still running into issue. It's almost 
like the urls.py is not updating. 

Here is the root url pattern I am using:
url("^news/", include("kdi.urls")),

And the urls.py for kdi:
url(r"^$", "kdi.views.newstest", name="newstest"),

And the `newstest` view:
def newstest(request, slug):
print "called!"
return HttpResponse('Test')


Expected behavior should be that navigation to domain/news will send the 
request to `kdi.urls`, where it will accept any string (^$) and call the 
`newstest` view to return the super simple response of "test". 404's every 
time.



On Friday, July 7, 2017 at 11:11:38 AM UTC-7, marcusgu...@gmail.com wrote:
>
> Have solved the fully qualified path issue, but now throwing `'unicode' 
> object has no attribute 'regex'` error. This one is more difficult to 
> traceback.
>
> On Thursday, July 6, 2017 at 8:12:00 PM UTC-7, marcusgu...@gmail.com 
> wrote:
>>
>> Hi, thanks for such a great resource! I have googled around for a few 
>> days and have made some headway this problem, but have hit a wall. I'm 
>> trying to use the Displayable model to create an easy way to add news 
>> stories and have them displayed as a simple list view, which is very 
>> similar behavior to the blog app. If there is a better solution using a 
>> ForeignKey, please point me in the right direction!
>>
>> I read an older post 
>> 
>>  about 
>> creating a new Displayable, and have used Mezzanine's source code to 
>> successfully extend the Displayable model and have it appear correctly in 
>> the admin. The issue now is that I can't seem to get the views (views.py) 
>> and url patterns to work. When clicked "view on site" from the admin, the 
>> url seems to grab the model's slug ("news"), but ends up linking to 
>> http://localhost:8000/en/admin//news/%28u/, and doesn't work 
>> linking directly to the actual item's slug. Exploring the source code for 
>> Mezzanine's blog's urls and views, I'm unsure how to correctly refactor. I 
>> understand that I will need to create my own templates to act as 
>> blog_post_list.html 
>> and blog_post_detail.html, but don't know how to create the super basic 
>> views to point to them.
>>
>> models.py:
>> class News(Displayable, RichText):
>>
>> pagetitle = models.CharField('Title', max_length=255, blank=True)
>> url = models.CharField('Link', max_length=255, blank=True)
>> summary = models.CharField('Summary', max_length=255, blank=True)
>> date = models.DateField(_("Date"), default=datetime.date.today)
>> categories = models.ManyToManyField("NewsCategory",
>> verbose_name=_("Categories 
>> (Magazine, Award, etc.)"),
>> blank=True, 
>> related_name="newsitems")
>> related_news = models.ManyToManyField("self",
>>  verbose_name=_("Related News"), 
>> blank=True)
>>
>> class Meta:
>> verbose_name = _("News Item")
>> verbose_name_plural = _("News Items")
>>
>> def get_absolute_url(self):
>> url_name = 'news'
>> kwargs = {
>> 'slug': self.slug,
>> }
>> return (url_name, (), kwargs)
>>
>>
>> class NewsCategory(Slugged):
>> """
>> A category for grouping news items into a series.
>> """
>>
>> class Meta:
>> verbose_name = _("News Category")
>> verbose_name_plural = _("News Categories")
>> ordering = ("title",)
>>
>> @models.permalink
>> def get_absolute_url(self):
>> return ("news_item_list_category", (), {"category": self.slug})
>>
>> admin.py
>> news_fieldsets = deepcopy(DisplayableAdmin.fieldsets)
>> news_fieldsets[0][1]["fields"].insert(1, "categories")
>> news_fieldsets[0][1]["fields"].extend(["pagetitle", "url", "summary", 
>> "date"])
>> news_fieldsets = list(news_fieldsets)
>> news_fieldsets.insert(1, (_("Other News"), {
>> "classes": ("collapse-closed",),
>> "fields": ("related_news",)}))
>> news_list_filter = deepcopy(DisplayableAdmin.list_filter) + 
>> ("categories",)
>>
>>
>> class NewsAdmin(DisplayableAdmin):
>> """
>> Admin class for news posts.
>> """
>>
>> fieldsets = news_fieldsets
>> # list_display = news_list_display
>> list_filter = news_list_filter
>> filter_horizontal = ("categories", "related_news",)
>>
>> def save_form(self, request, form, change):
>> """
>> Super class ordering is important here - user must get saved 
>> first.
>> """
>> DisplayableAdmin.save_form(self, request, form, change)
>> return DisplayableAdmin.save_form(self, request, form, change)
>>
>> class NewsCategoryAdmin(BaseTranslationModelAdmin):
>> """
>> Admin class for blog 

[mezzanine-users] Re: Extending Displayable Model, Views

2017-07-07 Thread marcusguttenplan
Have solved the fully qualified path issue, but now throwing `'unicode' 
object has no attribute 'regex'` error. This one is more difficult to 
traceback.

On Thursday, July 6, 2017 at 8:12:00 PM UTC-7, marcusgu...@gmail.com wrote:
>
> Hi, thanks for such a great resource! I have googled around for a few days 
> and have made some headway this problem, but have hit a wall. I'm trying to 
> use the Displayable model to create an easy way to add news stories and 
> have them displayed as a simple list view, which is very similar behavior 
> to the blog app. If there is a better solution using a ForeignKey, please 
> point me in the right direction!
>
> I read an older post 
> 
>  about 
> creating a new Displayable, and have used Mezzanine's source code to 
> successfully extend the Displayable model and have it appear correctly in 
> the admin. The issue now is that I can't seem to get the views (views.py) 
> and url patterns to work. When clicked "view on site" from the admin, the 
> url seems to grab the model's slug ("news"), but ends up linking to 
> http://localhost:8000/en/admin//news/%28u/, and doesn't work 
> linking directly to the actual item's slug. Exploring the source code for 
> Mezzanine's blog's urls and views, I'm unsure how to correctly refactor. I 
> understand that I will need to create my own templates to act as 
> blog_post_list.html 
> and blog_post_detail.html, but don't know how to create the super basic 
> views to point to them.
>
> models.py:
> class News(Displayable, RichText):
>
> pagetitle = models.CharField('Title', max_length=255, blank=True)
> url = models.CharField('Link', max_length=255, blank=True)
> summary = models.CharField('Summary', max_length=255, blank=True)
> date = models.DateField(_("Date"), default=datetime.date.today)
> categories = models.ManyToManyField("NewsCategory",
> verbose_name=_("Categories 
> (Magazine, Award, etc.)"),
> blank=True, 
> related_name="newsitems")
> related_news = models.ManyToManyField("self",
>  verbose_name=_("Related News"), 
> blank=True)
>
> class Meta:
> verbose_name = _("News Item")
> verbose_name_plural = _("News Items")
>
> def get_absolute_url(self):
> url_name = 'news'
> kwargs = {
> 'slug': self.slug,
> }
> return (url_name, (), kwargs)
>
>
> class NewsCategory(Slugged):
> """
> A category for grouping news items into a series.
> """
>
> class Meta:
> verbose_name = _("News Category")
> verbose_name_plural = _("News Categories")
> ordering = ("title",)
>
> @models.permalink
> def get_absolute_url(self):
> return ("news_item_list_category", (), {"category": self.slug})
>
> admin.py
> news_fieldsets = deepcopy(DisplayableAdmin.fieldsets)
> news_fieldsets[0][1]["fields"].insert(1, "categories")
> news_fieldsets[0][1]["fields"].extend(["pagetitle", "url", "summary", 
> "date"])
> news_fieldsets = list(news_fieldsets)
> news_fieldsets.insert(1, (_("Other News"), {
> "classes": ("collapse-closed",),
> "fields": ("related_news",)}))
> news_list_filter = deepcopy(DisplayableAdmin.list_filter) + ("categories",)
>
>
> class NewsAdmin(DisplayableAdmin):
> """
> Admin class for news posts.
> """
>
> fieldsets = news_fieldsets
> # list_display = news_list_display
> list_filter = news_list_filter
> filter_horizontal = ("categories", "related_news",)
>
> def save_form(self, request, form, change):
> """
> Super class ordering is important here - user must get saved first.
> """
> DisplayableAdmin.save_form(self, request, form, change)
> return DisplayableAdmin.save_form(self, request, form, change)
>
> class NewsCategoryAdmin(BaseTranslationModelAdmin):
> """
> Admin class for blog categories. Hides itself from the admin menu
> unless explicitly specified.
> """
>
> fieldsets = ((None, {"fields": ("title",)}),)
>
> def has_module_permission(self, request):
> """
> Hide from the admin menu unless explicitly set in 
> ``ADMIN_MENU_ORDER``.
> """
> for (name, items) in settings.ADMIN_MENU_ORDER:
> if "blog.BlogCategory" in items:
> return True
> return False
>
>
> admin.site.register(News, NewsAdmin)
> admin.site.register(NewsCategory, NewsCategoryAdmin)
>
> urls.py:
> from .models import News
> import .views
>
> _slashes = (
> "/" if settings.BLOG_SLUG else "",
> "/" if settings.APPEND_SLASH else "",
> )
>
> urlpatterns = patterns(
> 'news.views',
> url("^%s(?P.*)%s$" % _slashes, "news", name="news"),
> )
>
> views.py:
> from django.shortcuts import render
>
> def news(request, slug):
> return HttpResponse('Test')
>

Re: [mezzanine-users] Extending Displayable Model, Views

2017-07-07 Thread marcusguttenplan
It's an ImportError (ImportError at /news Could not import 'news'. The path 
must be fully qualified.) and trying to follow the traceback have narrowed 
it down to either how I am importing the model in my views (if that's even 
necessary) or to how I am calling the defined `news` view in the app's 
urlconf.

views.py:
from .models import News, NewsCategory

def news(request, slug):
return HttpResponse('Test')

urls.py
from .models import News
import views

urlpatterns = [
'news.views',
url("^%s(?P.*)%s$" % _slashes, "news", name="news"),
]

And the root urls.py pattern, with `kdi` being the name of my app:
url(r'^news/',include('kdi.urls')),


Slowly trying to reverse engineer the blog's views and urls to get to a 
pared down version, but there is a lot going on. Because my custom 
Displayable model does not need to be Ownable, there is no need to be any 
calling of the User model or referencing the request.user or author; there 
is also no need for a Detail view or feeds, or much filtering at all. That 
leaves only date and category in the pared views.py. That leaves something 
like this:

def news(request, tag=None, year=None, month=None, category=None, 
template="blog/blog_post_list.html", extra_context=None):

templates = []
blog_posts = BlogPost.objects.published(for_user=request.user)
if tag is not None:
tag = get_object_or_404(Keyword, slug=tag)
blog_posts = blog_posts.filter(keywords__keyword=tag)
if year is not None:
blog_posts = blog_posts.filter(publish_date__year=year)
if month is not None:
blog_posts = blog_posts.filter(publish_date__month=month)
try:
month = _(month_name[int(month)])
except IndexError:
raise Http404()
if category is not None:
category = get_object_or_404(BlogCategory, slug=category)
blog_posts = blog_posts.filter(categories=category)
templates.append(u"templates/blog_post_list_%s.html" %
  str(category.slug))

prefetch = ("categories", "keywords__keyword")
blog_posts = 
blog_posts.select_related("user").prefetch_related(*prefetch)
blog_posts = paginate(blog_posts, request.GET.get("page", 1),
  settings.BLOG_POST_PER_PAGE,
  settings.MAX_PAGING_LINKS)
context = {"blog_posts": blog_posts, "year": year, "month": month,
   "tag": tag, "category": category, "author": author}
context.update(extra_context or {})
templates.append(template)
return TemplateResponse(request, templates, context)

And this is where I have some questions. Going line by line, `
BlogPost.objects.published(for_user=request.user)`, would removing the 
`request.user` return all of the published objects, in this case 
News.objects?

Filtering by tags, dates, and categories makes sense, until we reach 
select_related `blog_posts = 
blog_posts.select_related("user").prefetch_related(*prefetch)`. Because 
this is focused on the user which is not necessary, is it possible to just 
prefetch all posts with the custom model, or to select_related based on the 
category? 

Pagination is also not necessary for this use case, so is it possible to 
remove entirely `blog_posts = paginate(blog_posts, request.GET.get("page", 
1), settings.BLOG_POST_PER_PAGE, settings.MAX_PAGING_LINKS)`? The hacky 
solution would be to keep this bit of code, and then set 
`BLOG_POST_PER_PAGE` to a large number in settings.

And then in the `context` dict, is it safe to remove unneeded key/val 
pairs? Specifically `author`? Because there is so much heavy lifting going 
on with the blog that's not needed here, I'm afraid of breakage.

Now looking at simplifying urlpatterns so that it will successfully direct 
to the News model's get_absolute_url + the object's slug (something like 
 http://x/news/slug):
'news.views',
url("^%s(?P.*)%s$" % _slashes, "news", name="news"),

Is this structured correctly? Should the slug come after the absolute url? 
Something like `url("^news/(?P.*)%s$" % _slashes, "news", name="news")
`?

Sorry to ask so many questions, and thank you for your help! I've been a 
bit intimidated by Django's urls.py and views.py for a while, and have 
managed to do almost all of my logic through custom models and custom 
templatetags. Even just learning the correct things to google helps a ton, 
and I appreciate any help at all!




On Friday, July 7, 2017 at 8:09:00 AM UTC-7, Eduardo Rivas wrote:
>
> Could you share the error message you’re getting?
>

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


Re: [mezzanine-users] Extending Displayable Model, Views

2017-07-06 Thread marcusguttenplan
Getting closer! Imported into root with 
url(r'^news/',include('app.urls')),

Throwing a new error about the path not being fully qualified, but progress.


On Thursday, July 6, 2017 at 9:38:22 PM UTC-7, marcusgu...@gmail.com wrote:
>
> I originally put that url pattern into the root conf, but it wasn't 
> working there either. Embarrassingly, I'm not sure how to import my app's 
> conf or define a new pattern that would point to it.
>
> This is what the root urls.py looks like:
> from __future__ import unicode_literals
>
> from django.conf.urls import include, url
> from django.conf.urls.i18n import i18n_patterns
> from django.contrib import admin
> from django.views.i18n import set_language
>
> from mezzanine.core.views import direct_to_template
> from mezzanine.conf import settings
>
>
> admin.autodiscover()
>
> urlpatterns = i18n_patterns(
> # Change the admin prefix here to use an alternate URL for the
> # admin interface, which would be marginally more secure.
> url("^admin/", include(admin.site.urls)),
> )
>
> if settings.USE_MODELTRANSLATION:
> urlpatterns += [
> url('^i18n/$', set_language, name='set_language'),
> ]
>
> urlpatterns += [
>
> url("^$", direct_to_template, {"template": "index.html"}, name="home"),
>
> # REST API URLs
> url("^api/", include("mezzanine_api.urls")),
>
> url("^", include("mezzanine.urls")),
> ]
>
> handler404 = "mezzanine.core.views.page_not_found"
> handler500 = "mezzanine.core.views.server_error"
>
>
>
>
> On Thursday, July 6, 2017 at 9:13:26 PM UTC-7, Eduardo Rivas wrote:
>>
>> I see you created a urlconf for your app, but have you added it to your 
>> root urls.py? If so, is if above or below Mezzanine's catch-all pattern? 
>>
>> On Jul 6, 2017 9:12 PM,  wrote:
>>
>>> Hi, thanks for such a great resource! I have googled around for a few 
>>> days and have made some headway this problem, but have hit a wall. I'm 
>>> trying to use the Displayable model to create an easy way to add news 
>>> stories and have them displayed as a simple list view, which is very 
>>> similar behavior to the blog app. If there is a better solution using a 
>>> ForeignKey, please point me in the right direction!
>>>
>>> I read an older post 
>>> 
>>>  about 
>>> creating a new Displayable, and have used Mezzanine's source code to 
>>> successfully extend the Displayable model and have it appear correctly in 
>>> the admin. The issue now is that I can't seem to get the views (views.py) 
>>> and url patterns to work. When clicked "view on site" from the admin, the 
>>> url seems to grab the model's slug ("news"), but ends up linking to 
>>> http://localhost:8000/en/admin//news/%28u/, and doesn't work 
>>> linking directly to the actual item's slug. Exploring the source code for 
>>> Mezzanine's blog's urls and views, I'm unsure how to correctly refactor. I 
>>> understand that I will need to create my own templates to act as 
>>> blog_post_list.html 
>>> and blog_post_detail.html, but don't know how to create the super basic 
>>> views to point to them.
>>>
>>> models.py:
>>> class News(Displayable, RichText):
>>>
>>> pagetitle = models.CharField('Title', max_length=255, blank=True)
>>> url = models.CharField('Link', max_length=255, blank=True)
>>> summary = models.CharField('Summary', max_length=255, blank=True)
>>> date = models.DateField(_("Date"), default=datetime.date.today)
>>> categories = models.ManyToManyField("NewsCategory",
>>> verbose_name=_("Categories 
>>> (Magazine, Award, etc.)"),
>>> blank=True, 
>>> related_name="newsitems")
>>> related_news = models.ManyToManyField("self",
>>>  verbose_name=_("Related News"), 
>>> blank=True)
>>>
>>> class Meta:
>>> verbose_name = _("News Item")
>>> verbose_name_plural = _("News Items")
>>>
>>> def get_absolute_url(self):
>>> url_name = 'news'
>>> kwargs = {
>>> 'slug': self.slug,
>>> }
>>> return (url_name, (), kwargs)
>>>
>>>
>>> class NewsCategory(Slugged):
>>> """
>>> A category for grouping news items into a series.
>>> """
>>>
>>> class Meta:
>>> verbose_name = _("News Category")
>>> verbose_name_plural = _("News Categories")
>>> ordering = ("title",)
>>>
>>> @models.permalink
>>> def get_absolute_url(self):
>>> return ("news_item_list_category", (), {"category": self.slug})
>>>
>>> admin.py
>>> news_fieldsets = deepcopy(DisplayableAdmin.fieldsets)
>>> news_fieldsets[0][1]["fields"].insert(1, "categories")
>>> news_fieldsets[0][1]["fields"].extend(["pagetitle", "url", "summary", 
>>> "date"])
>>> news_fieldsets = list(news_fieldsets)
>>> news_fieldsets.insert(1, (_("Other News"), {
>>> "classes": ("collapse-closed",),
>>> 

Re: [mezzanine-users] Extending Displayable Model, Views

2017-07-06 Thread marcusguttenplan
I originally put that url pattern into the root conf, but it wasn't working 
there either. Embarrassingly, I'm not sure how to import my app's conf or 
define a new pattern that would point to it.

This is what the root urls.py looks like:
from __future__ import unicode_literals

from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.views.i18n import set_language

from mezzanine.core.views import direct_to_template
from mezzanine.conf import settings


admin.autodiscover()

urlpatterns = i18n_patterns(
# Change the admin prefix here to use an alternate URL for the
# admin interface, which would be marginally more secure.
url("^admin/", include(admin.site.urls)),
)

if settings.USE_MODELTRANSLATION:
urlpatterns += [
url('^i18n/$', set_language, name='set_language'),
]

urlpatterns += [

url("^$", direct_to_template, {"template": "index.html"}, name="home"),

# REST API URLs
url("^api/", include("mezzanine_api.urls")),

url("^", include("mezzanine.urls")),
]

handler404 = "mezzanine.core.views.page_not_found"
handler500 = "mezzanine.core.views.server_error"




On Thursday, July 6, 2017 at 9:13:26 PM UTC-7, Eduardo Rivas wrote:
>
> I see you created a urlconf for your app, but have you added it to your 
> root urls.py? If so, is if above or below Mezzanine's catch-all pattern? 
>
> On Jul 6, 2017 9:12 PM,  wrote:
>
>> Hi, thanks for such a great resource! I have googled around for a few 
>> days and have made some headway this problem, but have hit a wall. I'm 
>> trying to use the Displayable model to create an easy way to add news 
>> stories and have them displayed as a simple list view, which is very 
>> similar behavior to the blog app. If there is a better solution using a 
>> ForeignKey, please point me in the right direction!
>>
>> I read an older post 
>> 
>>  about 
>> creating a new Displayable, and have used Mezzanine's source code to 
>> successfully extend the Displayable model and have it appear correctly in 
>> the admin. The issue now is that I can't seem to get the views (views.py) 
>> and url patterns to work. When clicked "view on site" from the admin, the 
>> url seems to grab the model's slug ("news"), but ends up linking to 
>> http://localhost:8000/en/admin//news/%28u/, and doesn't work 
>> linking directly to the actual item's slug. Exploring the source code for 
>> Mezzanine's blog's urls and views, I'm unsure how to correctly refactor. I 
>> understand that I will need to create my own templates to act as 
>> blog_post_list.html 
>> and blog_post_detail.html, but don't know how to create the super basic 
>> views to point to them.
>>
>> models.py:
>> class News(Displayable, RichText):
>>
>> pagetitle = models.CharField('Title', max_length=255, blank=True)
>> url = models.CharField('Link', max_length=255, blank=True)
>> summary = models.CharField('Summary', max_length=255, blank=True)
>> date = models.DateField(_("Date"), default=datetime.date.today)
>> categories = models.ManyToManyField("NewsCategory",
>> verbose_name=_("Categories 
>> (Magazine, Award, etc.)"),
>> blank=True, 
>> related_name="newsitems")
>> related_news = models.ManyToManyField("self",
>>  verbose_name=_("Related News"), 
>> blank=True)
>>
>> class Meta:
>> verbose_name = _("News Item")
>> verbose_name_plural = _("News Items")
>>
>> def get_absolute_url(self):
>> url_name = 'news'
>> kwargs = {
>> 'slug': self.slug,
>> }
>> return (url_name, (), kwargs)
>>
>>
>> class NewsCategory(Slugged):
>> """
>> A category for grouping news items into a series.
>> """
>>
>> class Meta:
>> verbose_name = _("News Category")
>> verbose_name_plural = _("News Categories")
>> ordering = ("title",)
>>
>> @models.permalink
>> def get_absolute_url(self):
>> return ("news_item_list_category", (), {"category": self.slug})
>>
>> admin.py
>> news_fieldsets = deepcopy(DisplayableAdmin.fieldsets)
>> news_fieldsets[0][1]["fields"].insert(1, "categories")
>> news_fieldsets[0][1]["fields"].extend(["pagetitle", "url", "summary", 
>> "date"])
>> news_fieldsets = list(news_fieldsets)
>> news_fieldsets.insert(1, (_("Other News"), {
>> "classes": ("collapse-closed",),
>> "fields": ("related_news",)}))
>> news_list_filter = deepcopy(DisplayableAdmin.list_filter) + 
>> ("categories",)
>>
>>
>> class NewsAdmin(DisplayableAdmin):
>> """
>> Admin class for news posts.
>> """
>>
>> fieldsets = news_fieldsets
>> # list_display = news_list_display
>> list_filter = news_list_filter
>> filter_horizontal = ("categories", "related_news",)
>>

[mezzanine-users] Re: Possible to remove fields inherited from Page in custom models?

2017-06-27 Thread marcusguttenplan
Just an update with some more details:

Tried extending the Displayable model to create a lower level custom model 
with one ImageField and three CharFields, and registering with 
DisplayableAdmin, but behavior wasn't as expected -- the model appeared 
with the custom name, but the fields were the same as the existing BlogPost 
model. I also just discovered this gist 
 for creating a custom page 
admin to register the model, would this be frowned upon?

On Monday, June 26, 2017 at 11:57:55 PM UTC-7, marcusgu...@gmail.com wrote:
>
> Hi, I have a few custom models that are built off of the Page model and 
> manager, and work great. But there is one model where it would be useful 
> for an inherited field (Show in Navigation booleans) to either set to 
> editable=false or remove them entirely. Is this possible?
>
> I'm worried that the fact the default states are all True and the extra 
> interaction required will effect the experience. I have read many posts on 
> the mailing list, stack overflow, and the git issues usually suggesting 
> that this is not a good idea and can cause unforeseen breakage, but the 
> Show in Nav bools seem pretty innocuous. I was thinking maybe finding a way 
> to hack some javascript into the admin to check the url and hide the fields 
> conditionally, but there must be a better way. If you have any ideas, I'm 
> open to anything! Thanks for a great tool!
>

-- 
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] Possible to remove fields inherited from Page in custom models?

2017-06-27 Thread marcusguttenplan
Hi, I have a few custom models that are built off of the Page model and 
manager, and work great. But there is one model where it would be useful 
for an inherited field (Show in Navigation booleans) to either set to 
editable=false or remove them entirely. Is this possible?

I'm worried that the fact the default states are all True and the extra 
interaction required will effect the experience. I have read many posts on 
the mailing list, stack overflow, and the git issues usually suggesting 
that this is not a good idea and can cause unforeseen breakage, but the 
Show in Nav bools seem pretty innocuous. I was thinking maybe finding a way 
to hack some javascript into the admin to check the url and hide the fields 
conditionally, but there must be a better way. If you have any ideas, I'm 
open to anything! Thanks for a great tool!

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