Language Selection

English French German Italian Portuguese Spanish

Python Programming Leftovers

Filed under
  • Django 3 Tutorial & CRUD Example with MySQL and Bootstrap

    Django 3 is released with full async support! In this tutorial, we'll see by example how to create a CRUD application from scratch and step by step. We'll see how to configure a MySQL database, enable the admin interface, and create the django views.

    We'll be using Bootstrap 4 for styling.

  • Creating a transparently encrypted field in Django

    This is officially PythonDiary's first Python 3 article! Python 2 is now officially dead, so there's less reasons to make that a major focus going forward.

    In some rare situations you may wish to have data which may otherwise be visible on the Django site, or through the Django admin, but may wish to have this data transparently encrypted into the database. This could be very useful, if for example, you use an untrusted database where it is not managed by you, and some database administrator can indeed either dump the data, or otherwise view the stored schemas. This is common with managed databases, which are either maintained by a hosting provider, or is shared with other tenants. In this current day and age with many database breaches appearing in the news from large vendors, you can never be 100% sure that the data you save into your database will never be leaked.

    Django supports custom fields on your database models, and the various CRUD and model services Django provides will use these fields with ease, making the creation of a globally transparently encrypted field possible. First lets start with the creation of the custom Django field to explain how that works first.

  • Return the word with the longest length within a string using Python

    Simple challenge – eliminate all bugs from the supplied code so that the code runs and outputs the expected value. The output should be the length of the longest word, as a number. There will only be one ‘longest’ word.

    Above is a question from CodeWars, we will create the below python function to perform the above task.

  • Getting Jenkins Jobs by Build State with Python

    I have been working with Python and Jenkins a lot lately and recently needed to find a way to check the job’s status at the build level. I discovered the jenkinsapi package and played around with it to see if it would give me the ability to drill down to the build and resultset level within Jenkins.

    In the builds that I run, there are X number of sub-jobs. Each of these sub-jobs can pass or fail. If one of them fails, the entire build is marked with the color yellow and tagged as “UNSTABLE”, which is failed in my book. I want a way to track which of these sub-jobs is failing and how often over a time period. Some of these jobs can be unstable because they access network resources, which others may have been broken by a recent commit to the code base.

    I eventually came up with some code that helps me figure out some of this information. But before you can dive into the code, you will need to install a package.

  • Wing Python IDE 7.2 Release Candidate 1 - January 14, 2020

    Wing 7.2 adds auto-formatting with Black and YAPF, expands support for virtualenv, adds support for Anaconda environments, explicitly supports debugging modules launched with python -m, simplifies manually configured remote debugging, and fixes a number of usability issues.

  • Creating password input widget in PyQt

    One of the most common parts of writing any desktop tool and taking password input is about having a widget that can show/hide password text. In Qt, we can add a QAction to a QLineEdit to do the same. The only thing to remember, that the icons for the QAction, must be square in aspect ratio; otherwise, they look super bad.

    The following code creates such a password input, and you can see it working at the GIF at the end of the blog post. I wrote this for the SecureDrop client project.

More in Tux Machines

today's howtos

Devices/Embedded With GNU/Linux

Easy Librem 5 App Development: Flashlight

In my first post on easy application development on the Librem 5 I discussed how to turn a simple shell script that takes a screenshot into a full graphical app with only a few extra lines of code. In this post I will follow up with an even simpler application that took about twenty minutes to write with much of that time involved in reading documentation. My Bright Idea The interesting thing about smart phones is how many other devices they have replaced beyond a regular phone. For instance, there used to be a market for small, pocket-sized digital cameras, but now many people just use the cameras on their smart phones. While some people still do keep a pocket flashlight with them, many people just use the light on their smart phone. I realized that a flashlight app would be another great way to showcase just how easy it is to develop applications for the Librem 5. As applications go the requirements are pretty simple: you need a button to turn on the light, a button to turn off the light, and a button to close the app. Read more

LibreOffice Writer Articles and Improvements

  • Two alternatives to Microsoft Word that are free and customizable

    If you're looking for an open-source office suite, LibreOffice is the software package for you. Its word processing program is LibreOffice Writer--which, incidentally, this story was written with, so I can attest to its excellence. You're able to choose from different fonts and text styles, embed images and figures, and use a variety of other functions you'd expect from its paid competition. It can save files in an Open Document Format (ODF), a number of Word formats, and export your work as a PDF for wide-ranging compatibility.

  • Improved rotated text handling in Writer's table rows with automatic height

    Writer now has better support for rotated text in tables containing rows with automatic height. This post also presents two related fixes. First, thanks Otevřená města who made this work by Collabora possible. [...] Before diving into improved rotated text handling, first a continuous section break import problem (tdf#128605) was fixed: this was a case when we created a new page style, but only a new section was intended.