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
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
javascripthon 0.8 released

Hello,

i'm pleased to announce a new release of javascripthon, the lean Python
to ES6 JavaScript translator. New in this release:

- add support for ``except`` sections with more than one exception
type and arbitrary exception variable name. Thanks to @devanlai;
- dict keys conversion fixes;
- enable ``--inline-map`` when translating a string with ``-s``;

See https://github.com/azazel75/metapensiero.pj for more info

cheers,

Alberto


/r/Python
https://redd.it/7dcpoy
[AF] Flask CRUD app.

Start off by saying I'm new to both Python and Flask. I've some programming and scripting experience, but was asked to learn Python so I could maintain a few sites my team uses.

I started by doing a search on how to get started with Flask and landed [here](https://scotch.io/tutorials/getting-started-with-flask-a-python-microframework). I was able to get everything installed and the basic "hello world" stuff going just fine. But it all came crashing down in [part 2](https://scotch.io/tutorials/build-a-crud-web-app-with-python-and-flask-part-one).

At this point, my code is basically copy/pasted from the [source](https://github.com/scotch-io/python-flask-crud-1), but am continually getting errors having to do with the blueprints. Here are my requirements and trace. Any help you good folks could give would be greatly appreciated. I have a feeling this is important...


(crud) C:\Users\xxxxx\Desktop\projects>pip freeze
alembic==0.9.6
click==6.7
dominate==2.3.1
Flask==0.12.2
Flask-Bootstrap==3.3.7.1
Flask-Login==0.4.0
Flask-Migrate==2.1.1
Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2
itsdangerous==0.24
Jinja2==2.10
Mako==1.0.7
MarkupSafe==1.0
mysqlclient==1.3.12
python-dateutil==2.6.1
python-editor==1.0.3
six==1.11.0
SQLAlchemy==1.1.15
visitor==0.1.3
Werkzeug==0.12.2
WTForms==2.1


(crud) C:\Users\xxxxxx\Desktop\projects>flask run
c:\users\xxxxxx\envs\crud\lib\site-packages\flask_sqlalchemy\__init__.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
Traceback (most recent call last):
File "c:\users\xxxxxx\appdata\local\programs\python\python36-32\Lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\xxxxxx\appdata\local\programs\python\python36-32\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\xxxxxx\Envs\crud\Scripts\flask.exe\__main__.py", line 9, in <module>
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 513, in main
cli.main(args=args, prog_name=name)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 380, in main
return AppGroup.main(self, *args, **kwargs)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 423, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 152, in __init__
self._load_unlocked()
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 176, in _load_unlocked
self._app = rv = self.loader()
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 237, in load_app
rv = locate_app(self.app_import_path)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 90, in locate_app
__import__(module)
File "C:\Users\xxxxxx\Desktop\projects\run.py", line 6, in <module>
app = create_app(config_name)
File "C:\Users\xxxxxx\Desktop\projects\app\__init__.py", line 29, in create_app
from .admin import admin as admin_blueprint
ImportError: cannot import name 'admin'

/r/flask
htt
ps://redd.it/7df66j
Why did Python only become dominant recently?

Python came out in 1991, which is earlier than PHP, Java, Javascript, which all came out around mid 1990s. People tend to see PHP as old tech, but Python is even older.

Yet Python never had [huge popularity](https://trends.google.com/trends/explore?date=all&q=python) until the [sudden growth in the early 2010s](https://stackoverflow.blog/wp-content/uploads/2017/09/projections-1-1400x1200.png). What caused this sudden increase in popularity?

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