Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
# 2
# 3
# 4
[AF] Help with combining two Flask-SqlAlchemy queries into one

I have looked myself blind on this issue. Is anybody familiar with SqlAlchemy and can help me in the right direction with combining the following two queries into one query, giving a total count?

unread_count1 = models.MessageThread.query.join(models.AppReg, models.MessageThread.source_app)\
.filter(and_(models.MessageThread.source_read == 0, models.MessageThread.source_archived == 0))\
.filter(models.AppReg.user_UID == g._user.uid)\
.count()

unread_count2 = models.MessageThread.query.join(models.AppReg, models.MessageThread.target_app)\
.filter(and_(models.MessageThread.target_read == 0, models.MessageThread.target_archived == 0))\
.filter(models.AppReg.user_UID == g._user.uid)\
.count()

/r/flask
https://redd.it/6y3agr
Best way to do dynamic models? (or any other solution?)

Hi all,
I want to implement the following:
A "document" is a collection of different "components" that can be just about anything (text, images, dates, links, output of custom scripts, whatever).
Each component can get status (draft, validated, disabled..), comments, history, validation etc.
We only know at runtime what kind of components a specific document will have, and how many.
I'm a bit lost on how to even get started. I saw some things about dynamic forms, but I can't really get how to relate this with a model.
Any suggestions on how to achieve that using Django? Or maybe it's not the right framework for what I want?
Thanks a lot!

/r/django
https://redd.it/6y78ih
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.


/r/Python
https://redd.it/6y87sb
I want to make a minimal Mezzanine site. How do I start from "scratch?"

I've set up a virtual environment using `virtualenv` command. Then I ran these commands:

# Install from PyPI
$ pip install mezzanine

# Create a project
$ mezzanine-project myproject
$ cd myproject

# Create a database
$ python manage.py createdb

# Run the web server
$ python manage.py runserver

When I go to `localhost:8080`, I get the standard, basic Mezzanine site. But I want to make a minimal homepage with two main sections: A navbar up top and a big main section below.

It seems like a lot of work to change the basic Mezzanine theme to match what I want.

So what do I do if I want to start a Mezzanine website/page from scratch?

/r/django
https://redd.it/6y9cqc
PyData Conference

I am relatively new to python (can do the basics, but have few big projects). However, I am debating trying to transition my job from academia to data analyst around May.

My questions for this community:
1) Both in terms of learning new things and interacting with potential employers, is the upcoming PyData conference in New York something that I would benefit from attending?

2) Has anybody attended in the past? What was your experience like?

3) If I decide to attend, how should I prepare?

I should also mention that my college will pay between 50-75% of my total expenses.

I appreciate any thoughts!


/r/pystats
https://redd.it/6xuh5x
What is considered to be the definitive Python bible, so far as books go?

I've been doing software development for 20+ years, and I'm not looking for a beginners Python programming book. I'm looking for something more akin to Perl's Camel book - a definitive reference, that covers all aspects of the language.

Many thanks!

/r/Python
https://redd.it/6y8i05
[AF] Strange problem with output compounding if the a form is submitted within a short timeframe

This one has me stumped.

I have a WTForm that I'm using like so:

form = UserForm()
if form.validate_on_submit():
session['form'] = form.data
return redirect('/analysis')

and then on my analysis function in views.py:

@app.route('/analysis', methods=['GET', 'POST'])
def analysis_results(text=None):
image, answers = main(session.get('form', None))
uniques = answers['uniques']
del answers['uniques']
session['form'] = None # a hack...didn't actually help.
if answers == False:
flash('No viable schedules are possible with these settings. Revise your parameters and submit again.')
return render_template('analysis.html',
title='Analysis',
image=image,
schedules=uniques,
mutations=answers)

So as you can see, I'm calling my backend program (main), which receives the session cookie that has the form data. The problem is that if I go to my analysis page, its great the first time. But, if I go back to the form quickly enough and just submit the same info (or different) in a 30 second window, it processes the whole thing, and then it looks like the 'answers' output (a dict) contains more keys than it should, and these end up getting printed to the analysis page.

Thing is, if I wait more than 30 seconds, no problem.

Thing is, if I try to print the form data, it looks the same no matter what. Or I'm crazy. One of the two.

How the heck could my front end be jacking up my back end if the input form data seemingly stays the same? And its not a problem if I just wait a little? I'm very confused.

This probably wouldn't be an issue for 90% of my users, but if someone did encounter this problem, it would make them lose confidence in my project. Help appreciated.

/r/flask
https://redd.it/6yc6a1
Bokeh poor support of Pandas DataFrame?

Just curious if anybody else find it surprising that Bokeh doesn't support Pandas dataframe as well as they would like as compared to plotly? Bokeh, seaborn, dask, pandas, et. el. are all part of the pydata organization. So I was surprised for instance, if you make a Bokeh chart of multiple lines from a pandas dataframe, the hover tool doesn't include the column names. It includes the (x,y) coordinates and index value, but omits the line labels!!! Hmmm...wow. One of the usefulness of the hover tool is when you have multiple lines, you want to easily identify the corresponding line label. In Bokeh, to get the line labels/column names in the hover tool you have to create a ColumnDataSource object from the Pandas dataframe, create a Hover object, and then use a FOR loop to render each line, otherwise resort to using HoloViews (a higher level API around Bokeh), which I still don't see how to get line labels. So I look into HoloViews further and I also find out it doesn't support pandas dataframe index, you have to resort to doing an additional reset_index() per their [doc](http://dev.holoviews.org/Tutorials/Pandas_Conversion.html).

Plotly surprisingly supports Pandas dataframes more completely compared to Bokeh (shows column names/line labels in the hover tool) and supports dataframe index. This is part of the major reason why it looks like I will have to stick with Plotly for interactive visualizations. If I have a need for a viz server or plot billions of data points, then I'll use Bokeh.

/r/pystats
https://redd.it/6xtmes
Postgres vs MySql - Which is better? Why?

I use MySql, as pythonanywhere has that preinstalled for free accounts. Any reason why you might go with postgres over mysql?

/r/flask
https://redd.it/6y2u0m
[AF] Where to store data and and static charts to be accessed by a Flask app

Flask newbie here! I have a question about how best to supply data to a Flask app.

I have a Flask app that shows some data and charts that are updated every hour. I'd consider the data "small" (a table of ~50 rows and 3 columns). The data and charts are generated by an R script that I have running outside and independently of my Flask app. The R script stores the data as a csv file and the charts as images on AWS S3, which the Flask app loads and presents. The Flask app does not write to the data set; it only reads it.

This setup works fine for now, but I'm wondering if I will experience issues as usage of the app (hopefully) scales. Are there issues with the app loading a csv file instead of reading from a database? Are there issues with the data and charts sitting outside of the app entirely?

Being new to web app development, I just want to make sure that I'm on the right path and not making egregious mistakes. Apologies if my current setup is way off the mark, but I would appreciate feedback. Thanks for your help!

/r/flask
https://redd.it/6xvlwk