Wagtail: Is it possible to disable prepending internal link's with the site domain? - django

I want to make the urls which I put in the WYSIWYG editor just absolute like /something but not sitename.com/something. I know that I can use the "external link" option, but it is not very handy for my editors.

If your rich text fields are outputting full URLs including a domain, it probably means you're hosting multiple sites on the same Wagtail installation. Unfortunately, in this situation it's not possible to override this behaviour to output local URLs.
Wagtail will always prefer to generate local URLs (without a domain) wherever possible, according to the following rules:
If the Wagtail installation is only hosting one site, generate a local URL
If we know that the link is being output on a page that's on the same site as the link destination, generate a local URL
Otherwise, generate a full URL including the domain
In the case of rule 2, the {% pageurl %} template tag is able to compare the current page against the link destination. However, this isn't possible within the |richtext template filter: a Django template filter has no access to the calling template's variables, so there's no way for it to know that the current page matches the link destination.

Related

Editing a previously generated HTML file with Django

I am very new to web development and the following is my use-case :
I have a large number of Bokeh charts, each in a separate HTML file.
In simple terms, I would like to have a home page, where I can provide
links to each one of these charts. However, During runtime, I would
like to edit these separate HTML files, so as to provide a link to go
back to the home page or to other pages. I would not like to modify
the HTML files permanently, so I can make use of them outside of the
web page as well for simple visualization on my system.
What is the best way to do this ? Are there technologies outside Django, I should be looking at to do something like this ?
If most of the content is static, maybe have a look at Jekyll.
The include functionality would let you create one file with the 'link back to the homepage' or in fact further content which you want to avoid repeating (such as navbars, headers, footers).
Bootstrap 4 is your freind for making the site look shiney.
As you're building the site you can run the development server with jekyll serve which allows you to connect to a development server from your browser, and preview changes as you're making them. This would be accessible somewhere like http://localhost:4000/
When you're ready to publish, you can use the jekyll build command, which outputs all of the static HTML files to the _site directory. Notice that at this point, the step of 'putting the homepage link in every page' is handled automatically by Jekyll and you end up with a directory you can upload directly to any hosting platform. The original HTML files/Boken Charts can therefor remain in their original form for use elsewhere.
This method is probably much more effiient than using Django for your use-case, which seems to require serving lots of static content whch already exists. With Django in production you'd need an application server, as well as a webserver and possibly a database which means more things to go wrong.
For bonus points, once you've got the hosting setup, stick the whole thing behind CloudFlare to reduce your hosting costs, and improve access speeds for visitors around the world!
Good luck.
EDIT: response to comment:*
Do you mean that I should abandon django altogether ?
If the purpose is just to serve your exising HTML files to the public, without any requirement for authentication, editing of content by users through the frontend, or more advanced back-end functions, then yes Django is probably overkill for this task.
How is Jekyll different from Django ?
Django is a Python Web Framework, which allows you to build an interactive site on which users or staff can login, post articles, comment, etc. One of its key features is the ability to define database relationships trough 'Models' and then have all the admin-side forms generated automatically in the background. This means, with minimal work, you can instantly have the 'admin portal' side of the site live, which works great for use-cases like large blogs or news sites. You would then build the frontend, which can also be interactive. To launch this into production is a separate task which involves configuring multiple server components.
Jeykll on the other hand is much simpler, and basically gives you a way to create some template HTML files (avoiding the need to repeat code for stuff like navigation bars) and then with the jekyll build command outputs a _site directory which can be uploaded straight to a basic webserver. This is the crucial part, as you then only need a webserver which can serve static content, rather than requiring python, a database, application server like UWSGI, etc
Let's look at this example from the Jeyll Docs with your usecase in mind.
You could define a YML file with a list of all your charts:
docs_list_title: All Charts here.
docs:
- title: A Lovely Bokeh Chart.
url: bokeh_chart_1.html
- title: This Bokeh Chart is even Better
url: bokeh_chart_2.html
You mentioned previously that you already have the HTML files, so really what you've done here is made a list of those, which can be interpreted by the frontend.
The HTML template portion would look something like this:
<h2>{{ site.data.samplelist.docs_list_title }}</h2>
<ul>
{% for item in site.data.samplelist.docs %}
<li>{{ item.title }}</li>
{% endfor %}
</ul>
This would result in a list of links to all of your Charts, with the link text as the title.
Obviously you could then go further and add further info to the YML file, like beneath each url put publisher: someone which could then be accessed in the template's for loop as {{item.publisher}}
Can such tools like Jekyll, Django and Bootstrap be used together ?
Bootstrap can be used with Django or Jekyll, as it is a CSS library which controls how HTML is rendered in the user's browser. Check the documentation for more examples of its capability.
A good starting point may be to download a theme from somewhere like Start Bootstrap. Once you have that as a ZIP file, you can put it in your Jeykll project and attempt to have it render through the dev server with jekyll serve. You can then remove nav bar or header code to separate include files (see my earlier link to the Jeykll docs) and before you know it you'll be seeing progress.
The best way to learn is to just go ahead and try this!

Django: which url does the LocaleMiddleware check?

Our company provides both a API and a small number of widgets that are embedded in clients websites through Iframes.
Now we have a Belgian customer who wishes to use our widgets. As you know Belgium is bi-lingual, so we are making liberal use of both the LocaleMiddleware and the {% trans 'string' %} tags.
Now as I understand correctly the middleware checks the URL to see which language to use. When you first visit our clients website you get a large pop-up where you choose your language. After this popup your url changes to this format: www.clientorg.be/fr_BE/rest-of-the-url, so that should (hopefully) work just fine.
However, our widget is served through an Iframe. (src = s2.oururl.com) which contains no language value.
So my question is: Will Django be able to detect the language of the user? Or will it only be able to check 'our' s2.url, meaning we need to contact our client and provide him with 2 urls to paste in the iframe, depending on the language the user chooses.
Here's exactly what LocalMiddleware tries to do to determine the language:
https://docs.djangoproject.com/en/2.0/topics/i18n/translation/
LocaleMiddleware tries to determine the user’s language preference by
following this algorithm:
First, it looks for the language prefix in the requested URL. This is
only performed when you are using the i18n_patterns function in your
root URLconf. See Internationalization: in URL patterns for more
information about the language prefix and how to internationalize URL
patterns.
Failing that, it looks for the LANGUAGE_SESSION_KEY key in the current
user’s session.
Failing that, it looks for a cookie.
The name of the cookie used is set by the LANGUAGE_COOKIE_NAME
setting. (The default name is django_language.)
Failing that, it looks at the Accept-Language HTTP header. This header
is sent by your browser and tells the server which language(s) you
prefer, in order by priority. Django tries each language in the header
until it finds one with available translations.
Failing that, it uses the global LANGUAGE_CODE setting.

SIteCore - multisite - displaying page from wrong site

We have a multisite SiteCore setup with 2 sites within the same .Net solution.
This works by setting the rootPath property on a Site Definition in web.config to limit the site to part of the SiteCore folder structure.
This works well apart from when pages are created with the same name as in the other site then it's serving content from the other site! We have inherited a fair bit of custom code in this solution form the other site so this may be the cause but dont know what Im looking for ...
Thanks
How are you referencing the sites? Do they each have their own host name? Do you have the "hostName" property set for the site node in the Site Defintion?
I will assume that you are not referring to them this way and instead, the sites are using the "virtualFolder" property. If both sites have the same default value of "/" for virtualFolder, attempting to get to either site will result in Sitecore rendering the first site that it matches on, which would be the site listed first.
Try putting the actual site name for "virtualFolder" and "physicalFolder" (e.g. "Site1" and "Site2", respectively). Then you can address your sites as http://yourserver.com/Site1 and http://yourserver.com/Site2. The "virtualFolder" will match first and render the correct site.
See Configuring Sites in the web.config File on SDN for additional information.
Hope this helps.
It turns out this is happening in this case because of a System alias that is redirecting for a subset of pages

Joomla 2.5 : External URL links to internal pages not working on server subfolder

I have a dedicated server with many different sub-folders/accounts. I have a test-installation for a new Joomla 2.5 site on one of these accounts/sub-folders that doesn't have a domain name associated with it yet. I have to access it by
http://(SERVER-IP)/~subfolder/
rather than
http://www.example.com/
Most of my link types are working smoothly (ie, "Single Article" links to the correct article alias, etc.) however when I use an External URL menu item type to link to an internal article alias, things go bad... Within the Menu Item options I put "/contact-us" in the Link field so that (in theory) I can link to
http://(SERVER-IP)/~subfolder/index.php/contact-us
however it is removing the subfolder, causing it to link to the apache root of the dedicated server instead, resulting in:
http://(SERVER-IP)/contact-us
I only have this issue when I use IP addresses instead of a domain name...
I have URL re-writing OFF, so it is not the .htaccess file causing the problems...is there an issue with the defined Absolute Path? Any ideas on how I can get this fixed so I can stop seeing 404-errors while in development? Thanks for any and all help pointing me in the right direction!
The beginning forward slash means start at document root, so it basically says to strip all "folders" down to the root domain (which on your dev system means just the IP address).
One option is to use the base tag to set up relative links for the external url menu type. You could add this to your template file's index.php just after the <head> declaration:
<base href="<?php echo JURI::root(); ?>" />
This can introduce a host of issues with relative links though, so you may want to weigh the issues with that here: Is it recommended to use the <base> html tag?
The second option would be to try it with index.php at the start, so make the url index.php/contact-us. I believe that this will be routed properly as an internal link.
This will cause an issue if you go live and turn on htaccess URL rewriting. I just checked and this will not have the index.php section removed, so that is an issue.
The third option (which takes more work but is probably recommended) is to stop linking to internal urls with external url menu items. Joomla tends to function best when you set up a menu item for your urls. (Much of the url routing is based around the menu item.)
Really the third option is that it may be easier to help you not use the External URL menu item than to fix the routing issue.

Multilingual sites in Sitecore

I'am new to Sitecore and had few questions on Multilingual sites in Sitecore
First I added the new language to the existing site and try to access the same with sc* parameter for testing purpose.
The site throws "Input string is in incorrect format" error. Though the content is not added for this it should be a blank page, not sure why it's throwing the error.
If, by chance, your Sitecore instance has multiple sites (i.e. you're using the SiteDefinition.config file to define separate site host headers) then you need to specify the language per-site, in the language attribute within the particular site node in SiteDefinition.config.
The value would be the language code, like "en-US" or "da-DK" for instance. For reference, see this (this references the web.config, but it applies to SiteDefinition.config as well).
besides the sc_lang query parameter, you can also give the language in the url.
for example /en leads to English homepage, /nl-NL to the dutch homepage. the first part of the url is the language.
so /en/page1.asp leads to the en version of the page1 item under your home.
The current language is stored in a cookie check the website#lang cookie.. Where website is the name of the website.
The default language is located in the web.config or include files
With the LinkManager in the web.config you can configer the appearance