Bottle Template Support? - python

I'm using PyCharm 3.4.1 and learning MongoDB from Mongo University. In the code, they have us using Python to create html pages using the MVC pattern with bottle.
When I add a file of type .tpl to the editor in PyCharm, there is no "intellisense" or support for the model in the code. Changing it to be in the list of html file types helps some, but no python support in the editor.
Is there a plugin or some other change i can make to support editing better? Seems someone else asked something similar earlier in the year at How to get tpl files highlighted in pycharm?

Bottle comes with a built-in template engine called SimpleTemplate which is not currently supported by PyCharm.
There is a relevant feature request: Bottle microframework support, but it doesn't explicitly state about .tpl syntax support.
I'd go and create a feature request in PyCharm's issue tracker asking about SimpleTemplate syntax support or, at least, vote up and comment in the existing issue.
For example, there is the similar feature-request for tornado template engine:
Add Tornado Template Support
It has currently 56 votes up which is probably increasing the possibility of seeing it happen.
As a workaround, you can configure .tpl file type under Settings -> File Types. It is possible to set highlighting rules there.

Related

VSCode mouse-over information for python

I recently started using Dart and Flutter for Mobile App dev on VSCode, and I love how the mouse-over tooltip for methods shows return type, expected parameters, and the source of the method:
I understand that Python is not a strongly typed language so showing type information is not possible for variables. But what about methods in python?
The information in mouse-over tooltip seems extremely hard to read, and not really helpful. I don't know where the method came from and what it outputs. The description is also not very readable. Am I doing something wrong, or is this really not a feature? Or do I just need to learn to read that tooltip?
It seems this is the behaviour when using Jedi.
You can refer to this page for more details.
I suggest you using Pylance as language server. Adding the following codes to your settings.json:
"python.languageServer": "Pylance"

Use Python CGI or Django for a web project

I am a front-end web developer learning Python and decided to try to create a website for a friend. The website contains an astrology calculator that will generate a chart image and reading based on a person's birth date, birth time, and birthplace. I can use either Python CGI or Django to build this. Which one is appropriate for this project?
The chart calculator will:
1. generate an image of a chart with the correct houses and signs lined up.
2. plot the planets in the correct houses in the chart
3. show the connections between the stars, like a trine, square, or conjuction.
To render images, I think HTML5 can probably work. For the server-side scripting I am leaning towards CGI because it seems like you can write real Python programs with it and just output the results with something like print "sun conjunct jupiter". Django seems to limit you to that weird syntax that forces you to write every Python expression in these <% ... %> brackets and it doesn't seem like you can import Python modules easily.
I am not extremely familiar with Django, but these seem to be some of the limitations I noticed in the Django tutorial.
What do others in the community think? Should I use CGI or Django to create this website?
I checked out other questions, but not sure if a Python mini-framework is appropriate here.
Not really sure what you're hoping to glean from this (or what the question is exactly), but you seem to be misinterpreting what the Python CGI functions and Django are.
Django is a web framework meant to expedite the process of developing a website, so you can focus on specific issues (like the chart problem you described) rather than have to tend to the infrastructure of a site. It's meant to abstract away CGI (to oversimplify it a bit). If you're looking for something less heavy than Django, perhaps try Flask or Bottle.
PS: A quick Google search showed a similar question from a few years back: My first web app (Python): use CGI, or a framework like Django?

PyCharm3 Live template not working at all

I just switched from Eclipse/PyDev to PyCharm 3 CE. I can't get the live templates working any ways. Followed every documentation I can find online like this:
http://www.jetbrains.com/pycharm/webhelp/live-templates.html
And the builtin python template super(Generates a 'super' call) does not work either.
By "not working", I meant that when editing a python file in PyCharm and typing the abbreviation, the popup snippets list does not include the live templates, even though they are under the Python template group.
Am I missing something?
I am using PyCharm 3.1 Professional (evaluation version) and am having the same issue.
However, using Ctrl+J will bring up templates as will Code -> Insert Live Template. It is also possible to start typing a code snippet and then press Ctrl+J to see a filtered list of templates.
Don't forget to also select the "context"...

Python based web reporting tool? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 months ago.
Improve this question
I have a question for those of you doing web work with python. Is
anyone familiar with a python based reporting tool? I am about to
start on a pretty big web app and will need the ability to do some end
user reporting (invoices, revenue reports, etc). It can be an existing
django app or anything python based so I can hook into it.
ReportLab
Welcome to the ReportLab Open Source site. ReportLab is a library for programatically creating PDF documents. It's a fast, flexible, cross platform solution written in Python.
Or go a little higher level than reportlab: xhtml2pdf - now WeasyPrint (built on top of reportlab)
From the website:
Translates HTML and CSS input into PDF files
Is written pure Python and therefore platform independent
Supports document specifics like columns, headers, footers, page numbers, custom Postscript and TrueType fonts, etc.
Best support for frameworks like Django, Turbogears, CherryPy, Pylons, WSGI
Simple integration into Python programms
Also available as stand alone command line tool for Windows, MacOS X and Linux
Most reporting tools are stuck in the '80s: a time when you 'painted' a report intended to be printed that completely lacked integration with other reports.
Sometimes we still need that. If you need to print an invoice, you're pretty much stuck with that kind of functionality. But in general, most reporting these days consists of multiple queries/charts/graphs/tables per page with drill-down built directly into it.
If you've got enough of a need go with an OLAP tool - then you don't even code the reports, your users (theoretically) can. If not, I've seldom seen a scenario in which a "reporting tool" was better than using something like Chart Director with a language like php, perl, python, ruby, etc.
Try to have look at the Cubes - Light-weight OLAP framework for Python. It is just partial solution for your problem, but I think it might help.
Sources at github
Documentation
Blog with tutorials
You can either use Python to do OLAP/aggregated browsing or you can run an OLAP HTTP Server (called Slicer). Here is an example using HTTP Server: Open Public Procurements reporting. The front-end is PHP which accesses Slicer server through HTTP. Example of server can be found here with documentation for the server can be found here.
Currently the framework provides SQL backend using SQLAlchemy, so you can use any DB that can SQLAlchemy has engine for.
Reports in form of charts, tables & stuff, including JS front-end framework are planned. Just wanted to help at least with lower OLAP layer.
Let me know if you have any questions, I am the author.
Also have a look at myDBR a tool that allows you to define your reports in the database (using stored procedures) and then takes care of the layout and formatting of the data.
Even though myDBR is a PHP application, it does not require any PHP coding, just install the application and embed it as iframe in your own app.
I've been working on a recent addition to this. It allows you to create HTML reports from Python which you can share as standalone HTML files. This means you can have interactive components - such as table viewers and interactive plots (which have become a lot more popular since this question was originally posed).
Currently it supports pandas DataFrames, Bokeh, Plotly, Altair, JSON, and Markdown components.
For instance:
import altair as alt
import pandas as pd
import datapane as dp
df = pd.read_csv('https://query1.finance.yahoo.com/v7/finance/download/GOOG?period1=1553600505&period2=1585222905&interval=1d&events=history')
chart = alt.Chart(df).encode(x='Date', y='High', y2='Low').mark_area(opacity=0.5).interactive()
dp.Report(dp.Table(df['High']), dp.Plot(chart)).save(path='stock_analysis.html')
It's still early, but check it out: https://docs.datapane.com
I was doing some research and found about awe. It runs a small webserver which can do realtime updates on a page and allows for more complicated report layouts.
It has documentation and examples and can give you something up and running, quickly.

How to create an internationalized Google App Engine application

I would like to provide my Python GAE website in the user's own language, using only the tools available directly in App Engine. For that, I would like to use GNU gettext files (.po and .mo files).
Has someone successfully combined Python Google App Engine and gettext files? If so, could you please provide the steps you used?
I had started a discussion in GAE's Google group, but haven't been able to extract from it how I'd like to do it: I don't want to add external dependencies, like Babel (suggested in the discussion). I want to use plain vanilla Google App Engine, so no manual update of Django or this kind of stuff.
At first, I will start using the language sent by the browser, so no need to manually force the language by using cookies etc. However, I might add a language changing feature later, once the basic internationalization works.
As a background note to give you more details about what I'm trying to do, I would like to internationalize Issue Tracker Tracker, an open source application I've hosted on Launchpad. I plan to use Launchpad's translation platform (explaining why I'd like to use .mo files). You can have a look at the source code in it's Bazaar branch (sorry no link due to stackoverflow spam prevention limit for new users...)
Thanks for helping me advance on this project!
As my needs were simple, I used a simple hack instead of (unavailable) gettext. I created a file with string translations, translate.py. Approximately like this:
en={}
ru={}
en['default_site_title']=u"Site title in English"
ru['default_site_title']=u"Название сайта по-русски"
Then in the main code I defined a function which returns a dictionary with translations into the most suitable language from the list (the first one to have a translation is used or English):
import translate
def get_messages(languages=[]):
msgs=translate.en
for lang in languages:
if hasattr(translate,lang):
msgs=getattr(translate,lang)
break
return msgs
Usage:
msgs = get_messages(["it","ru","en"])
hi = msgs['hello_message'] % 'yourname'
I also defined a helper function which extracts a list of languages from Accept-Language header.
It's not the most flexible solution, but it doesn't have any external dependencies and works for me (in a toy project). I think translate.py may be generated automatically from gettext files.
In case you want to see more, my actual source is here.
You can use the Django internationalisation tool, like explained here.
They are also saying that there is no easy way to do this.
I hope that helps you :)

Categories

Resources