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
Simple way to navigate a JSON object?

Is there a simple way to navigate a large JSON object in jupyter notebook?

For example in https://jsonformatter.curiousconcept.com I can paste in a json object and then minimize/expand different layers. This is much more productive than reading through a printed json object.

I could just paste in the json object I get into the above site, but I would like a solution with the notebook so I can have a simpler workflow.




/r/JupyterNotebooks
https://redd.it/7d4zrh
What's up with Shuup (previously Shoop)?

TL;DR: Is Shuup about to go subscription/enterprise mode with a limited CE edition?

Asking because:

* Search for shoop/shuup on r/django turns up ONE result,
* 2 months ago shoop was renamed shuup with a new github repo, it has ONE commit since then,
* shuup.com menu for "Products" only lists "Entersprise" and "Why shuup?",
* Download page goes to typical marketing signup-before-download page,
* Only mention of github is in the footer,
* Install docs for latest version doesn't work, requires multiple tweaks to even get to the migration.

Longer version:

I'm evaluating CMS+eCommerce options for a freelance project I've been asked to send a proposal for. I wished to try something different than the wordpress swamp this time, preferably python since I dunno, I like it?

My search first lead me to Saleor (not customizable enough for my client) -> Django-CMS+Django-Shop (couldn't get the apphooks to work easily) -> Django-Oscar (too basic, tight deadline) -> Mezzanine+Cartridge (my weapon of choice, everything just worked). But another team member suggested I check shuup as well, because they seemed to have more features (demo page looks very nice: https://demo2.shuup.com/), but the more I read and check about shuup the less I feel for it. All the activity graphs of their repos are equally dead. I mean, they have more stars, followers and forks than Cartridge, but no commits in 2 months?

Am I missing something obvious here? To me it seems like they've been bought and are in a hush-hush phase of commercializing the product and mainly focus on an enterprise version.

I just don't want to be stuck with a non-supported and/or costly framework for this project...

EDIT: Typo

/r/django
https://redd.it/7d5t15
django-Filter: Only show filter options contained in queryset

I'm using the excellent [django-filter](https://github.com/carltongibson/django-filter) app to filter a queryset of model objects. Let's say my model and view look as follows:

#model
[...]
class Animal(models.Model):
REGION_CHOICES = (
(0, 'Africa'),
(1, 'Europe'),
)

name = models.CharField(max_length=100)
region = models.CharField(choices=REGION_CHOICES, max_length=100)
[...]

#view
[...]
qs = Animal.objects.all()
filter = AnimalFilter(request.GET, qs)
[...]


Assuming there are two animals in the database:

zebra = Animal(name='Zebra', region='Africa')
frog = Animal(name='Frog', region'Europe')

When I render the filter in the template, I correctly get a selector for region which contains the two options Europe and Africa.

But if I use some logic in the view to .exclude() objects from the queryset like this:

#view
[...]
qs = Animal.objects.all().exclude(name='Frog')
filter = AnimalFilter(request.GET, qs)
[...]

Now if I render the filter in the template I still get the two optione Europe and Africa for region although the queryset only contains one animal which has the region Africa.

Any ideas how I could get the correct options for the region field rendered in the template? Any help is greatly appreciated.

/r/djangolearning
https://redd.it/7d32ck
How do i filter Django list using my bootstrap form?

I have been using Django and its default admin templates for my app. There is a certain list view for which I have decided to create my own bootstrap form for filtering objects. I want the values in the form fields to be used to filter on the queryset. How do I POST the data to Django and tell it to reload the page bearing in mind the choices in the form? Basically, how do I tell Django to "refresh this page" but apply the values in the form to queryset? Here is my code for the customized list

{% extends 'admin/change_list.html' %}

{% load i18n admin_urls static admin_list %}
{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}" />

{% if cl.formset %}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />
{% endif %}
{% if cl.formset or action_form %}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
{% endif %}
{{ media.css }}
{% if not actions_on_top and not actions_on_bottom %}
<style>
#changelist table thead th:first-child {width: inherit}
</style>
{% endif %}
{% endblock %}

{% block content_title %}
<h1> Activity Summary </h1>
{% endblock %}

{% block object-tools-items %}
{% if has_add_permission %}
{{ block.super }}

<!-- Modal -->
<button type="button" data-toggle="modal" data-target="#filterModal" class="btn btn-primary">Launch modal</button>

<div class="modal fade" id="filterModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Filter</h4>
</div>
<div class="modal-body">

<form>
<div class="form-group">
<label for="user">Users:</label>
<input type="text" class="form-control" id="user">
</div>
<div class="form-group">
<label for="text">Date</label>
<input type="text" class="form-control" id="text">
</div>
<div class="checkbox">
<label><input type="checkbox"> Verified </label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>

</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div>
</div>
</div>

{% endif %}
{% endblock %}
{% load humanize %}
{% block result_list %}

<script type="text/javascript">
$(document).ready(function() {
$("#user").autocomplete(
{
minLength: 2,
source: function (request, response)
{
$.ajax(
{
url: "/autocomplete/",
data: {term: request.term},
dataType: "json",
appendTo : "ui-id-1",
success: function (jsonDataReceivedFromServer)
{
//alert (JSON.stringify (jsonDataReceivedFromServer));
// console.log (jsonDataReceivedFromServer);
response ($.map(jsonDataReceivedFromServer, function (item)
{
console.log (item.firstname);
return {
id: item.firstname, value: item.email, label: item.firstname };
}));
}
});
},
});
});
</script>

<div class="results">
<table>

<thead>
<tr>
<th>
<div class="text">
<a href="#">Employee</a>
</div>
</th>
<th>

</table>
</div>

{% endblock %}

{% block pagination %}{% endblock %}

/r/djangolearning
https://redd.it/7d2kaj
[D] Should we introduce an "Inaccurate"/"Misleading" tag for posts?

As a moderator, simply removing a post doesn't seem to curb the amount self-promotion and inaccurate submissions that continue to crop up. This is mainly because these posts come from a different author each time.

There's no incentive to not post since there will be some amount of visibility before it gets removed. To disincentivize these types of posts, should we introduce "Inaccurate" and "Misleading" tags to inform the community that the post could be misleading. The author can appeal this tag with the moderators, but it will be at our discretion whether it will be removed or not.


/r/MachineLearning
https://redd.it/7d6dkw
Install flask production on centos 7

I can't find a tutorial online that gives a step by step on how to install Flask for production on Centos 7 that uses port 80 with either nginix or apache. Does anyone have a good tutorial on this? It's always setting it up with "venv" and then port 5000. I want to use it on a production machine on port 80 but can't find a good tutorial.

/r/flask
https://redd.it/7d8ue0
[AF] Example of Flask app w/search form

I'm a new Flask (and Python) user, and was wondering if there is a good example of a Flask application that uses a search form as a basis for a database query. Especially if it uses Pagination.

Miguel's tutorial has an example of full-text search, but in general the things I've found only show some simpler parts of the process--using forms for user login, or getting all examples of something from the database (and then paginating this). I'd love a good model to follow for generating a perhaps-complicated query, which would involve using non-trivial bits of WTForms, SQLAlchemy, &c.

/r/flask
https://redd.it/7d527c
Flask apache hello world

I have an amazon aws server and was attempting to use flask to do a simple hello world on the server.

I have tried a few options listed at http://flask.pocoo.org/docs/0.12/deploying/ and can't seem to get any of them to work and I'm not entirely sure why. I also can't seem to find a simple hello world tutorial showing what I am trying to do.

So my question is what is the simplest way to have my server when accessed through a web browser display "Hello World"

Note the script is called hello_world.py: https://pastebin.com/30nutV4c

/r/flask
https://redd.it/7dbo3x
Flask, Docker + Google Cloud Platform

Hey guys,

I'm currently working on a pretty basic dockerized Flask application that consists of three containers, one for nginx, postgres and the flask_app itself. Everything works fine locally so no problems there what so ever. The point of the project however is to deploy such an application across some cloud platforms in a scalable way, enter Google Cloud Platform (gcp).

I have a cluster deployed on gcp and want to deploy to it. Instead of using a postgres container now (as I do locally) I've created a PostgreSQL db on gcp that I can use across my application. I've pushed my docker images sans the postgres image to the container registry and then I attempt to deploy using a deploy.yml (https://gist.github.com/tnolan8/b608c77ca4dff70bb48f8ae88408ff85) file. This is where I'm running into issues.

I'm using Flask-SqlAlchemy within the application to connect with my db, but no matter what connection string I seem to use I can't get the db to work with my application. I figure it must be something I'm doing incorrectly with my deploy.yml file and/or my connection string I'm setting in my app config for SQLALCHEMY_DATABASE_URI. What should I be setting this variable to? I'm relatively new to gcp and Kubernetes in general and would really appreciated any help/examples people may have.

Thank you!



/r/flask
https://redd.it/7d4c2c
Are you still on Python2? What is stopping you moving to Python3?

Any comments or links welcome. I'm trying to understand what the barriers are that keep us on Python2

/r/Python
https://redd.it/7dcgnq