Integrate Piwik tracking code into Sphinx-generated docs hosted on readthedocs.io - python

While readthedocs.io offers the possibility to enable Google Analytics for a page by just adding the tracking ID within a project's settings, the same offer does not seem to exists for using Piwik.
I would like to use Piwik for a page that I generate for a Python project using Sphinx and that is hosted on readthedocs.io. I guess one way to enable it would be to add the Piwik tracking code to the page template as mentioned in https://github.com/rtfd/readthedocs.org/issues/199 however I'm not sure how to start with this.
Has someone been able to use Piwki in this configuration or an idea on how to achieve it? Thank you very much for your help!

Modify your theme's template, inserting your Piwik tracking code. My answer to a related question can point you in the right direction.

Related

Flask url_for on external URLs

I have been researching this for quite a while and it seems that I cannot get my head around it. I have different ideas but all of them looks like they are not the right one to solve this problem.
I have an application in flask that does different things like for example:
loading an image (user profile image)
calling APIs (to perform specific tasks, like for example adding a comment to a forum post)
etc.
The way I am doing all of this is by using url_for in this way:
client_info = requests.post(url_for('api.read_comments', _external=True),
json={'client_name': client}).json()
So my application is at "https://www.myapp.com/comments" - The "url_for()" in my code will basically generate this url: "https://www.myapp.com/api/read_comments".
All comments are then retrieved by my API code.
This works just fine, but what I would like to do is to have the Frontend on "https://www.myapp.com/" but the Backend on "https://backend.myapp.com".
So my question is, how can I make my url_for() as dynamic as possible and able to access content on other subdomains/servers that I own?
Any thoughts? Or additional methods/functions that I should be using?
For example all comments will be located at "comments.myapp.com", all my profile details are on "profiles.myapp.com", etc. This is just a general idea on how the system can be setup. Any thoughts?
Thanks a lot and I look forward to hearing from you.

Huge Django project

I have a new job and a huge django project (15 apps, more than 30 loc). It's pretty hard to understand it's architecture from scratch. Are there any techniques to simplify my work in the beginning? sometimes it's even hard to understand where to find a form or a view that I need... thnx in advance.
When I come to this kind of problem I open up a notebook and answer the following:
1. Infrastructure
Server configuration, OS etc
Check out the database type (mysql, postgres, nosql)
External APIS (e.g Facebook Connect)
2. Backend
Write a simple description
Write its input/output from user (try to be thorough; which fields are required and which aren't)
Write its FK and its relation to any other apps (and why)
List down each plugin the app is using. And for what purpose. For example in rails I'd write: 'gem will_paginate - To display guestbook app results on several pages'
3. Frontend
Check out the JS framework
Check the main stylesheet files (for the template)
The main html/haml (etc) files for creating a new template based page.
When you are done doing that. I think you are much more prepared and able go deeper developing/debugging the app. Good luck.
Use this http://packages.python.org/django-extensions/graph_models.html
to generate the Relationship diagrams from the models so that you can visually see how the models are related to each other. This will give you nice idea about the app
1) Try to install the site from scratch. You will find what external apps are needed for the site to run.
2) Reverse engineer. Browse through the site and try to find out what you have to do to change something to that page. Start with the url, look up in urls.py, read the view, check the model. Are there any hints to other processes?
3) Try to write down everything you don't understand, and document the answers for future reference.
I would clone the project so you can mess up endlessly.
Then I would start to reduce the code. "What happens if if just remove this function here?
Also get django debug toolbar:
https://github.com/django-debug-toolbar/django-debug-toolbar
A good terminal debugger is also golden, there are many out there, here is an example:
https://github.com/tomchristie/django-pdb
This allow you to halt the code and even inject and mutate parameters in runtime. Just like GDB in C.
If you use FireFox you can install FireBug on it and when you for example submit ajax form you can see at which url send you request after what you can easily find controller which work with this form data. At chrome this utility embedded by default and call by F12 key.

How to make a pretty Python web app?

I'm looking for a python web framework that is easy to use and allows me to generate some nice looking user interfaces on the fly. I have not much experience with web development and don't want to spent much time to learn internals.
So far I use cherrypy and mako templating to serve the app. My problem is, it just looks awful. I'd like to have some nice (maybe AJAX?) features available to make the app a little bit more fancy.
My app is a simple search site without any database connection. So I have a main page where the user enters the search string and a result page. In the end it should look like the Goole search, with some hover effects for the results, nice keyboard controls, maybe even something similar like the page preview from Google.
So to achieve this, should I use a different framework or do I need to write the CSS and javascript by hand? What options do I have?
Thanks!
Your user interface has nothing to do with the web framework you choose to use.
That said, you might find Bootstrap useful:
Bootstrap is a toolkit from Twitter designed to kickstart development
of webapps and sites. It includes base CSS and HTML for typography,
forms, buttons, tables, grids, navigation, and more.
You might also find this article useful: http://web.archive.org/web/20120418061148/http://jamie-davidson.com/2012/01/resources-to-hack-design/ (original article at: http://jamie-davidson.com/2012/01/resources-to-hack-design/ is no longer available)
"easy to use"
Django
"generate some nice looking user interfaces on the fly"
Django!
"don't want to spent much time"
Django!!
For javascript, I strongly suggest jQuery and for some CSS: Grid 960.
How about Django or Pinax? Maybe BlueBream? There are so many Python frameworks... If you're new to dev work, however, choose one in which there's a solid offline local community to lean on...to go to with questions to help get the app built. (In L.A., it's Django.) But, specifically to your app, my question would be: if you only have essentially just two different page layouts--i.e., the main search page where a user inputs their query, and then X number of dynamically generated pages for the results...and no database--do you really need a whole Python "framework" for that? You write that you're also looking to dynamically generate "nice looking user interfaces on the fly"...which is a little confusing given the stated scope of your app.
Pyjamas - Python Javascript Compiler, Desktop Widget Set and RIA Web Framework
I found interesting web2py framework, easy to install, and it has o lot of features as "from the box"

Add a debugging page to a Django project?

I'm supplying a Django project to a client, who has requested a 'debugging' page that will show useful information.
[UPDATE for clarity: We'd like this page so we can use it for debugging in future: the clients are not very technical and I won't have direct access to their servers. In the event of future issues, it would be very useful if I could check out this page without asking them to edit the Debug setting or do any other server-side fiddling.]
The project will be running in production, so I can't set DEBUG=True.
What I would like is a page similar to the Django debugging page but without any sensitive information in.
I guess I can simply write my own, but does anyone have any ideas? Anything standard in Django I could use?
Thanks!
Googling 'standard Django debugging page'
Isn't as effective as reading the Django source itself.
Look in base.py for code like this
from django.views import debug
That will provide you some hints as to how they do it.
Then you can look at django/views/debug.py for the "technical_404_response" view function. You can use this function in your code, also.
You can use Django Debug Toolbar and enable it only for choosen IPs

turbogears request/user object in templates and request context

I am currently making the switch from Django to Turbogears 2.1 and am running into some problems that I could not find the answers to in the Turbogears docs. If tg developers read this, let me tell you that one of the best features Django has over TG is its documentation!
1) How do I access the request (user?) object within a mako template in order to check if the user is authenticated? For instance
if (request.user.is_authenticated)
'logout link'
else
'login link'
2) A related quesiton (as the user object is exposed in Django to templates via context processors). Is there a way to add data to the request context? For instance, in my Django app I add a cached dictionary of notifications for the user if the user is logged in via a definition in a context_processors.py file and then include that def in the TEMPLATE_CONTEXT_PROCESSORS tuple in the settings file.
3) This may warrant its own question, but I thought I'd throw it in in case anyone has a quick suggestion. I'm using Netbeans as my IDE and it offers no code coloring or tools for mako files. However, trying to rename the templates with a .html extension throws a mako error. Is there any way around this or am I stuck with plain text and the .mak extension?
Thanks very much
I've moved from Turbogears 1.0 to Django. Might not be able to answer all of these, but I believe in general TG2 tries to keep things fairly similar to TG1. Hopefully pointing out how it works in TG 1, might help...
1) In Turbogears 1.0 you would use tg.identity.anonymous to see if the user was logged in or not. A quick look at the docs, shows it's most likely still the same.
2) Turbogears called this sort of thing stdvars - see here for details for TG 1 http://docs.turbogears.org/1.0/stdvars
3) Sorry don't know, but I presume you can probably just tell Netbeans to consider .mak as another extension for html files (so it uses html syntax highlighting).

Categories