Re: [mezzanine-users] Displayable Model, Urls, Template
yea, the _slash is defined. it's working now, so thank for your help. On Thursday, January 29, 2015 at 12:15:49 AM UTC+8, Josh Cartmell wrote: > > That's a good point, is _slash even defined anywhere? I think: > > url("^techspec/(?P.*)/$", tsmodelview, name="techspec_model"), > > should work > > > > On Wed, Jan 28, 2015 at 2:54 AM, S.C. > > wrote: > >> i found out maybe because my url did not declare correctly, i mean the >> format for example the following works: >> >> urlpatterns = patterns("", >> url("^techspec/(?P.*)", views.tsmodeldetail, name= >> "tsmodeldetail"), >> ) >> >> >> as long as "techspec/(?P.*)" without "/", it will work. >> >> But then, why this happen, can't understand what cause this problem. >> >> >> On Wednesday, January 28, 2015 at 12:00:47 AM UTC+8, Josh Cartmell wrote: >>> >>> I would add some print statements or breakpoints around this line: >>> >>> tsmodel = get_object_or_404(tsmodels, slug=slug) >>> >>> I would print the slug before that line and verify that slug actually >>> exists in the database. My guess is that line is producing the 404 because >>> it isn't finding an object. >>> >>> On Tue, Jan 27, 2015 at 12:09 AM, S.C. wrote: >>> it show page not found (404)... On Tuesday, January 27, 2015 at 12:16:18 AM UTC+8, Josh Cartmell wrote: > > What happened when you tried what you posted above? > > I don't think this has anything to do with using Displayable (I don't > think Displayable does anything to templates) and more likely has to do > with the view. > > On Mon, Jan 26, 2015 at 5:16 AM, S.C. wrote: > >> I was unable to link up template for the Displayable's Model, i >> follow the example in the source code but failed to link to the >> template. >> >> The app name "*TechSpec*", and the template name for the models " >> *tsmodel.html*" (path: templates/techspec/tsmodel.html) >> >> *Models:* >> class TSModel(Displayable, RichText): >> order = models.IntegerField(_("Ordering"), default=0) >> title = models.charField(_("Title"), max_length=50) >> >> class Meta: >> verbose_name = _("TS Model") >> verbose_name_plural = _("TS Models") >> ordering = ("order", ) >> >> >> @models.permalink >> def get_absolute_url(self): >> return ("techspec_model", (), {"slug": self.slug}) >> >> *Views:* >> from models import TSModel >> >> def tsmodelview(request, slug, template="techspec/tsmodel.html"): >> tsmodels = TSModel.objects.all() >> >> tsmodel = get_object_or_404(tsmodels, slug=slug) >> context = {"tsmodel": tsmodel} >> templates = [u"techspec/%s.html" % str(slug), template] >> return render(request, templates, context) >> >> *Urls:* >> from views import tsmodelview >> >> urlpatterns = patterns("", >> url("^techspec/(?P.*)%s$" % _slash, tsmodelview, name= >> "techspec_model"), >> ) >> >> Thank you in advance. >> >> -- >> 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-use...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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-use...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. >>> >>> -- >> 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-use...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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] Google Analytics - Does footer_scripts.html need updating ?
I was a little impatient as the existing code works fine. Google just a bit slower confirming all okay than I would have liked. Sleeping on it helped. Thanks Stephen for the discussion link. I guess Google's plan to phase in the "Universal" replacing "Classic" needs looking at eventually. As pointed out is something like 2 years+ away from expiring. And thanks Josh. As always overriding will do the job. On Wednesday, January 28, 2015 at 4:22:56 PM UTC+8, Stephen McDonald wrote: > > There's a recent relevant discussion here: > https://github.com/stephenmcd/mezzanine/pull/1191 > > Apparently the code should work fine as is. > > On Wed, Jan 28, 2015 at 7:19 PM, Mark Doukidis > wrote: > >> Having trouble getting Google Analytics to acknowledge a sites tracking >> code. >> >> I can see it in the generated pages and looks okay. >> >> Have noticed that the code in Mezzanine was last updated in 2012 and >> wondered if it needs updating as it appears quite different from the >> suggested code from Google. >> >> Google's suggestion: >> >> >> >> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ >> (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new >> Date();a=s.createElement(o), >> >> m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) >> })(window,document,'script','//www.google-analytics.com/analytics.js >> ','ga'); >> >> ga('create', 'UA-XX-1', 'auto'); >> ga('send', 'pageview'); >> >> >> >> >> Mezzanine's code: >> >> >> {% if settings.GOOGLE_ANALYTICS_ID and not request.user.is_staff %} >> var _gaq = _gaq || [['_trackPageview']]; >> _gaq.unshift(['_setAccount', '{{ settings.GOOGLE_ANALYTICS_ID }}']); >> (function(d, t) { >> var g = d.createElement(t), >> s = d.getElementsByTagName(t)[0]; >> g.async = true; >> g.src = '//www.google-analytics.com/ga.js'; >> s.parentNode.insertBefore(g, s); >> })(document, 'script'); >> {% endif %} >> >> >> >> Anyone experiencing any issues with the code ? >> >> >> regards >> >> mark >> >> -- >> 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-use...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Stephen McDonald > http://jupo.org > -- 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] Google Analytics - Does footer_scripts.html need updating ?
Also if you do want to upgrade Mark you can override the footer scripts template in your own project, I've done that before myself to take advantage of some of the new features of universal analytics. I haven't had any problems with the current script not working as is though. On Wed, Jan 28, 2015 at 3:22 AM, Stephen McDonald wrote: > There's a recent relevant discussion here: > https://github.com/stephenmcd/mezzanine/pull/1191 > > Apparently the code should work fine as is. > > On Wed, Jan 28, 2015 at 7:19 PM, Mark Doukidis > wrote: > >> Having trouble getting Google Analytics to acknowledge a sites tracking >> code. >> >> I can see it in the generated pages and looks okay. >> >> Have noticed that the code in Mezzanine was last updated in 2012 and >> wondered if it needs updating as it appears quite different from the >> suggested code from Google. >> >> Google's suggestion: >> >> >> >> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ >> (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new >> Date();a=s.createElement(o), >> >> m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) >> })(window,document,'script','//www.google-analytics.com/analytics.js >> ','ga'); >> >> ga('create', 'UA-XX-1', 'auto'); >> ga('send', 'pageview'); >> >> >> >> >> Mezzanine's code: >> >> >> {% if settings.GOOGLE_ANALYTICS_ID and not request.user.is_staff %} >> var _gaq = _gaq || [['_trackPageview']]; >> _gaq.unshift(['_setAccount', '{{ settings.GOOGLE_ANALYTICS_ID }}']); >> (function(d, t) { >> var g = d.createElement(t), >> s = d.getElementsByTagName(t)[0]; >> g.async = true; >> g.src = '//www.google-analytics.com/ga.js'; >> s.parentNode.insertBefore(g, s); >> })(document, 'script'); >> {% endif %} >> >> >> >> Anyone experiencing any issues with the code ? >> >> >> regards >> >> mark >> >> -- >> 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. >> > > > > -- > Stephen McDonald > http://jupo.org > > -- > 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. > -- 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] Displayable Model, Urls, Template
That's a good point, is _slash even defined anywhere? I think: url("^techspec/(?P.*)/$", tsmodelview, name="techspec_model"), should work On Wed, Jan 28, 2015 at 2:54 AM, S.C. wrote: > i found out maybe because my url did not declare correctly, i mean the > format for example the following works: > > urlpatterns = patterns("", > url("^techspec/(?P.*)", views.tsmodeldetail, name= > "tsmodeldetail"), > ) > > > as long as "techspec/(?P.*)" without "/", it will work. > > But then, why this happen, can't understand what cause this problem. > > > On Wednesday, January 28, 2015 at 12:00:47 AM UTC+8, Josh Cartmell wrote: >> >> I would add some print statements or breakpoints around this line: >> >> tsmodel = get_object_or_404(tsmodels, slug=slug) >> >> I would print the slug before that line and verify that slug actually >> exists in the database. My guess is that line is producing the 404 because >> it isn't finding an object. >> >> On Tue, Jan 27, 2015 at 12:09 AM, S.C. wrote: >> >>> it show page not found (404)... >>> >>> On Tuesday, January 27, 2015 at 12:16:18 AM UTC+8, Josh Cartmell wrote: What happened when you tried what you posted above? I don't think this has anything to do with using Displayable (I don't think Displayable does anything to templates) and more likely has to do with the view. On Mon, Jan 26, 2015 at 5:16 AM, S.C. wrote: > I was unable to link up template for the Displayable's Model, i follow > the example in the source code but failed to link to the template. > > The app name "*TechSpec*", and the template name for the models " > *tsmodel.html*" (path: templates/techspec/tsmodel.html) > > *Models:* > class TSModel(Displayable, RichText): > order = models.IntegerField(_("Ordering"), default=0) > title = models.charField(_("Title"), max_length=50) > > class Meta: > verbose_name = _("TS Model") > verbose_name_plural = _("TS Models") > ordering = ("order", ) > > > @models.permalink > def get_absolute_url(self): > return ("techspec_model", (), {"slug": self.slug}) > > *Views:* > from models import TSModel > > def tsmodelview(request, slug, template="techspec/tsmodel.html"): > tsmodels = TSModel.objects.all() > > tsmodel = get_object_or_404(tsmodels, slug=slug) > context = {"tsmodel": tsmodel} > templates = [u"techspec/%s.html" % str(slug), template] > return render(request, templates, context) > > *Urls:* > from views import tsmodelview > > urlpatterns = patterns("", > url("^techspec/(?P.*)%s$" % _slash, tsmodelview, name= > "techspec_model"), > ) > > Thank you in advance. > > -- > 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-use...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- >>> 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-use...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > 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. > -- 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] Best Model Architecture?
Gotcha, I think I'm understanding better what you want to do. I'm not sure this is possible because presumably the Slide class will need a foreignkey to the parent page class that it shows up on, is that correct? I.e. wouldn't the models really look something like this: class SliderPage(Page): pass class Slide(Orderable): sliderpage = models.ForeignKey(SliderPage, related_name="slides") image = FileField(...) Then wherever you had an instance of a SliderPage you could do: sliderpage.slides.all() I don't know of any way to inherit a ForeignKey relationship (that of course doesn't mean it's impossible). Something else you may be able to do is use a generic foreignkey in some way, https://docs.djangoproject.com/en/1.7/ref/contrib/contenttypes/#generic-relations, that would allow you to have a slide be related to any other model, but it would also complicate things a lot more. On Tue, Jan 27, 2015 at 5:50 PM, Avery Laird wrote: > Hi Josh, > > Thanks for the reply. I actually already use abstract models in many of my > projects -- very useful feature! Maybe I should have explained my thinking > a bit better. I was describing something more along the lines of the > RichTextPage behaviour. I know the mechanics behind the scences of > RichTextPage is actually more complicated than this, but the behavior that > we see involves a page (eg, class Page(Page, RichTextPage) ) which inherits > RichTextPage. Is it possible to do something like that? For example, I know > I also want my page to have a slider, so I do: class Page(Page, Slider). > Let's say I also want an accordion: class Page(Page, Slider, Accordion). > The level lower than *that *(BaseSlider, BaseAccordion) would involve > the abstract models you talked about above. Being pretty new to django, I > have some large gaps in my knowledge which may have prevented me from > seeing some glaring error in this thinking -- is this even possible / > practical? > > Thanks again, I appreciate your help with this! > > On Tue, Jan 27, 2015 at 7:58 AM, Josh Cartmell > wrote: > >> Hi Avery, you should be able to do this: >> >> class SlideBase(models.Model): >> # eg >> image = FileField(verbose_name=_("Image"), >> upload_to=upload_to("theme.Slide.image", "slider"), >> format="Image", max_length=255, null=True, blank= >> True) >> Class Meta: >>abstract = True >> >> >> Then: >> >> class Slider(Orderable, BaseSlider): >> pass >> >> The key here is making BaseSlider abstract have a look at the docs if you >> want to dive in more, >> https://docs.djangoproject.com/en/1.7/topics/db/models/#abstract-base-classes >> >> On Mon, Jan 26, 2015 at 10:33 PM, Avery Laird >> wrote: >> >>> class Slider(Orderable): >>> # eg >>> >>> image = FileField(verbose_name=_("Image"), >>> upload_to=upload_to("theme.Slide.image", "slider" >>> ), >>> format="Image", max_length=255, null=True, blank= >>> True) >>> Class Meta: >>># whatever >>> >>> >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Mezzanine Users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/mezzanine-users/HVAjvY2ZfCY/unsubscribe >> . >> To unsubscribe from this group and all its topics, send an email to >> mezzanine-users+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > 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. > -- 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] How to replicate/copy complex pages
Hi Brygg, Your understanding is correct, though in my experience more often formulated so: $ python manage.py shell Let me take a moment to plug the excellent django-extensions module. In your python environment, `pip install django-extensions` will download and add the module to your python path. Mezzanine (and Cartridge) will take advantage of this module if installed. $ python manage.py shell_plus The above command will get your python shell up and load your models for you. It can be a huge time-saver, particularly if you are making changes and trying to test them in the shell. hth! - ken On Wed, Jan 28, 2015 at 1:22 AM, Brygg Ullmer wrote: > Josh, > > Many thanks for the very helpful code example! Using such a variation (as > opposed to direct SQL) does appear cleaner and more in keeping with Django. > > My apologies for the newcomer question, but -- per these links: > > https://docs.djangoproject.com/en/1.7/ref/django-admin/ > https://docs.djangoproject.com/en/1.7/topics/testing/tools/ > > ... am I correct in understanding that Django orm scripts of the style you > illustrate/describe may typically be accessed with a call like: > > python /usr/lib/python2.7/site-packages/django/bin/django-admin.py shell > --plain --settings=./mysite.settings > > followed by code that begins with: > > from django.test import Client > > Warmly appreciated! > > Brygg > > -- > 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. > -- 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] Google Analytics - Does footer_scripts.html need updating ?
There's a recent relevant discussion here: https://github.com/stephenmcd/mezzanine/pull/1191 Apparently the code should work fine as is. On Wed, Jan 28, 2015 at 7:19 PM, Mark Doukidis wrote: > Having trouble getting Google Analytics to acknowledge a sites tracking > code. > > I can see it in the generated pages and looks okay. > > Have noticed that the code in Mezzanine was last updated in 2012 and > wondered if it needs updating as it appears quite different from the > suggested code from Google. > > Google's suggestion: > > > > (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ > (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new > Date();a=s.createElement(o), > > m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) > })(window,document,'script','//www.google-analytics.com/analytics.js > ','ga'); > > ga('create', 'UA-XX-1', 'auto'); > ga('send', 'pageview'); > > > > > Mezzanine's code: > > > {% if settings.GOOGLE_ANALYTICS_ID and not request.user.is_staff %} > var _gaq = _gaq || [['_trackPageview']]; > _gaq.unshift(['_setAccount', '{{ settings.GOOGLE_ANALYTICS_ID }}']); > (function(d, t) { > var g = d.createElement(t), > s = d.getElementsByTagName(t)[0]; > g.async = true; > g.src = '//www.google-analytics.com/ga.js'; > s.parentNode.insertBefore(g, s); > })(document, 'script'); > {% endif %} > > > > Anyone experiencing any issues with the code ? > > > regards > > mark > > -- > 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. > -- Stephen McDonald http://jupo.org -- 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] Google Analytics - Does footer_scripts.html need updating ?
Having trouble getting Google Analytics to acknowledge a sites tracking code. I can see it in the generated pages and looks okay. Have noticed that the code in Mezzanine was last updated in 2012 and wondered if it needs updating as it appears quite different from the suggested code from Google. Google's suggestion: (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XX-1', 'auto'); ga('send', 'pageview'); Mezzanine's code: {% if settings.GOOGLE_ANALYTICS_ID and not request.user.is_staff %} var _gaq = _gaq || [['_trackPageview']]; _gaq.unshift(['_setAccount', '{{ settings.GOOGLE_ANALYTICS_ID }}']); (function(d, t) { var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; g.async = true; g.src = '//www.google-analytics.com/ga.js'; s.parentNode.insertBefore(g, s); })(document, 'script'); {% endif %} Anyone experiencing any issues with the code ? regards mark -- 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.