Michio JP

Michio JP

1564204304

When Django Is Better Than JavaScript Frameworks for Business Processes

Originally published by Craig Oda  at dzone.com

Although some people view Django as old technology compared to the hot JavaScript framework of the year, Django is mature, stable, easy to use, and better suited for a wide range of business tasks.

I’ll illustrate this point with components for a VR or 360 image management system based on Django that provides the following functionality:

  1. 360 image capture and camera setting adjustment using the Google Optical Spherical Camera (OSC) open API.
  2. Network-attached camera management to view and download pictures into Django from multiple cameras on a Wi-Fi network.
  3. Bulk process hundreds or thousands of images using simple bash or shell commands from Django.
  4. Sync internal server with a public cloud-based server to view images in 360 degrees.

The example Django site described in this article is available here: https://gallery.theta360.guide/.

What Are 360 Images

360 image gallery

360 images are standard JPG or PNG files that are presented in equirectangular format. In the image above, the thumbnails are displayed in equirectangular format. The 360 view looks like Google Streetview or Google Maps.

360 image sample

The images are different in a few ways. A single picture from a consumer camera like the RICOH THETA Z1 used in the example above is large. The picture is 6,720 by 3,360 pixels and is eight MB in size. Images from industrial cameras are much larger. Only a portion of the picture is viewable on the page and must be rotated with the mouse or headset.

Another difference is that the metadata attached to the image contains orientation and projection information.

Image Capture and Camera Settings

The Google OSC API is a simple HTTP API that sends GET and POST commands to the camera over Wi-Fi. Although there are different ways to implement the connection, the easiest method to have the DHCP server on your office network is to assign the camera an IP address. If there are restrictions on allowing devices to connect to the same office network, you can isolate the Django management server and the cameras on a separate subnet.

Architecture overview

In this architecture, you can have dozens or even hundreds of cameras connected to the same management server simultaneously. This is useful for businesses such as large-scale used car auctions where the camera is used to take interior shots of the cars. Another use is for factory or retail store traffic optimization where images of different areas are continually taken for later analysis.

Problems With JavaScript Digest Authentication

To send an HTTP command to the RICOH THETA camera used in this example, the client must pass the ID and password of each camera with Digest Authentication. This is straightforward and common to do with Python using the common requests module. This is not as easy with JavaScript, though it appears to be possible.

Several of us tried building this system using Electron and Node prior to switching to Django and Python. While it always seems possible to accomplish the same thing in JavaScript, the reality is that it’s sometimes harder and more problematic to work with JavaScript.

THETA API and JavaScript Dev

Using Python, it took a few hours to build out a decent set of sample camera commands. The Django views.py function to take a picture is shown below.

def take_picture(request):
url = f"{THETA_URL}commands/execute"
    payload = {"name": "camera.takePicture"}
    resp = requests.post(
                        url,
                        json=payload,
                        auth=(HTTPDigestAuth(THETA_ID, THETA_PASSWORD)))
    data = resp.json()
    pprint.pprint(data)
    return render(request, 'commandhome.html', {'data': data})

The digest authentication is accomplished with the requests module HTTPDigestAuth(ID, PASSWORD) .

As I mentioned before, this should work with JavaScript and Node, but we couldn’t get it to work properly. Community members have got Digest Authentication working with the camera using Java, but I found that Java wasn’t as concise as Python.


Listing Images

With the Google OSC API specification, the camera images are accessed from the URL OF each image. You can click on each image link and display it in the web page you generate with Django or download it to the Django file directory for batch processing.

Each image URL looks similar to this:

http://192.168.2.101/files/150100525831424d42079d18e0b6c300/100RICOH/R0010056.JPGThe Django views.py function to list the image URLs in a web page is shown below.

def generate_image_list():
    url = f"{THETA_URL}commands/execute"
    command_string = "camera.listFiles"
    payload = {
                "name": command_string,
                "parameters": {
                    "fileType": "image",
                    "entryCount": 20,
                    "maxThumbSize": 0
                }}
    resp = requests.post(
                        url,
                        json=payload,
                        auth=(HTTPDigestAuth(THETA_ID, THETA_PASSWORD)))
    data = resp.json()
    imageEntries = data["results"]["entries"]
    images = []
    for imageEntry in imageEntries:
        print(imageEntry["fileUrl"])
        images.append(imageEntry["fileUrl"])
    return images

Although the algorithm would be similar in JavaScript, we could not get it working with JavaScript due to the Digest Authentication issue. There were several other cases where a Python module like requests seemed to have more support for a wider range of usage scenarios than the equivalent JavaScript package.

Batch Processing with Bash and Shell Commands

Python is often used in DevOps because it can directly access shell scripts and commands with subprocess. Python can even run bash scripts. Although it’s not as easy to run shell commands as using bash directly, it only takes a few lines of code.

We first looked at using the Python imaging library fork called Pillow. However, to involve a larger group of non-developers in the image processing testing, we switched to the common command line applications ImageMagick and exiftool. Once we had a reasonable work process, we then ran the tools through Django to get feedback from a larger group of people.

In one test, we merged an image an a mask to produce watermarks.

Note: For a Live 360 view of the watermark overlay test, clich here.

Equirectangular view of image with watermarks

To create a watermarked image using this technique, you first create one watermark mask with the same dimensions as the original and then apply a transparent background. You think combine the two images with ImageMagick composite.

Watermark

You can test this on a command line with:

$ composite -geometry +3000+1600 theta_logo.png toyo-hardrock.jpg new-image.jpg

You can then run it from Django views.py, using subprocess Popen , PIPE , and STDOUT . Here’s a short example that processes an image after it’s downloaded into Django.

from django.shortcuts import render
from subprocess import Popen, PIPE, STDOUT
import requests
import os
PROJECT_MEDIA_DIR = os.getcwd() + "/media/"
def watermark(request):
    # pass in file name after upload for production
    image_file_name = f"{PROJECT_MEDIA_DIR}/toyo-hardrock.jpg"
    logo_file_name = f"{PROJECT_MEDIA_DIR}/theta_logo.png"
    output_file = f"{PROJECT_MEDIA_DIR}/new-image.jpg"
    # composite is part of imagemagick package
    Popen(['composite', '-geometry', '+3000+1600', logo_file_name,
        image_file_name, output_file], stdout=PIPE, stderr=STDOUT)
    return render(request, 'watermark.html', {"output": output_file.split('/')[-1]})

In watermark.html , you can grab the output directly with {{output}} .

 <script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/0.7.1/aframe.min.js"
   crossorigin="anonymous"></script>
    <h1>Watermark</h1>
        <a-scene>
                <a-sky src="/media/{{output}}" rotation="0 -130 0"></a-sky>
          </a-scene>

In another test, we produced 12 versions of the same image with the image dimensions the same, but with different image quality settings. This changed the file size from 8.6MB to 220K for images of the same size. A live site of results is here:

https://gallery.theta360.guide/blog/qualitytuba/

Image quality tests

Managing EXIF Data

As I mentioned earlier, the 360 images contain metadata or EXIF data, including data needed to position the 360 image. This is an example of metadata from an image.

Full Pano Height Pixels : 3584 
Full Pano Width Pixels : 7168 
Initial Horizontal FOV Degrees : 70.0 
Initial View Heading Degrees : 0.0 
Initial View Pitch Degrees : 0.0 
Initial View Roll Degrees : 0 
Pose Heading Degrees : -54.1 
Pose Pitch Degrees : 0.0 
Pose Roll Degrees : 0.0 
Projection Type : equirectangular 
Stitching Software : RICOH THETA Stitcher v1.00.4 
Use Panorama Viewer : true

Using exiftool , you can grab the metadata from the command line.

$ exiftool filename.jpg

The code below from views.py will get the data into Django for display on a web page below the image.

def exif(request):
    # pass in file name after upload for production
    image_file_name = f"{PROJECT_MEDIA_DIR}/osaka-night.jpg"
    process = Popen(['exiftool', image_file_name], stdout=PIPE, stderr=STDOUT)
    output_byte = process.stdout.read()
    output_list = str(output_byte)[2:-1].strip().split('\\n')
    return render(request, 'exif.html', {"output": output_list, "filename": image_file_name.split('/')[-1]})

Exiftool can also be used to write the data. Keep in mind that Python libraries like Pillow can do the same thing. In production, you probably want to use Python libraries instead of shell commands. The shell commands are great for building something in minutes and putting it on a web site to show colleagues for feedback.



Summary

After a few years of intermittently trying to build a workflow with MEAN, Cordova, and Electron, I decided to try Python and Django. I’m glad I did. Python and Django are old, but I found that they had more support for obscure edge cases. The same functionality was possible but difficult to achieve with JavaScript.

As modern JavaScript or TypeScript projects likely involve a transpiler and bundler, it was refreshing to use the simpler edit-view flow of Python, especially with virtualenv and pip to take care of the requirements and versioning.

It also felt surprisingly good to use the shell directly from Python. To be honest, it felt a bit like cheating and not the correct thing to do, but it was gratifying to see the results of image processing after a few minutes of coding using command line techniques I already knew and didn’t have to look up in the documentation.

The flexibility, maturity, just-get-done features of Python makes Django a framework for more than just a web site. Django can manage and control network-connected devices, batch-edit images, and the same management system can deploy the images to the public. Django is a better choice for this type of workflow management than comparable JavaScript frameworks.

Originally published by Craig Oda  at dzone.com

===================================================================

Thanks for reading :heart: If you liked this post, share it with all of your programming buddies! Follow me on Facebook | Twitter

Learn More

☞ Complete Python Bootcamp: Go from zero to hero in Python 3

☞ Python and Django Full Stack Web Developer Bootcamp

☞ Python for Time Series Data Analysis

☞ Python Programming For Beginners From Scratch

☞ Beginner’s guide on Python: Learn python from scratch! (New)

☞ Python for Beginners: Complete Python Programming

☞ Django 2.1 & Python | The Ultimate Web Development Bootcamp

☞ Python eCommerce | Build a Django eCommerce Web Application

☞ Python Django Dev To Deployment

#python #django

What is GEEK

Buddha Community

When Django Is Better Than JavaScript Frameworks for Business Processes
Ahebwe  Oscar

Ahebwe Oscar

1620177818

Django admin full Customization step by step

Welcome to my blog , hey everyone in this article you learn how to customize the Django app and view in the article you will know how to register  and unregister  models from the admin view how to add filtering how to add a custom input field, and a button that triggers an action on all objects and even how to change the look of your app and page using the Django suit package let’s get started.

Database

Custom Titles of Django Admin

Exclude in Django Admin

Fields in Django Admin

#django #create super user django #customize django admin dashboard #django admin #django admin custom field display #django admin customization #django admin full customization #django admin interface #django admin register all models #django customization

Carmen  Grimes

Carmen Grimes

1595491178

Best Electric Bikes and Scooters for Rental Business or Campus Facility

The electric scooter revolution has caught on super-fast taking many cities across the globe by storm. eScooters, a renovated version of old-school scooters now turned into electric vehicles are an environmentally friendly solution to current on-demand commute problems. They work on engines, like cars, enabling short traveling distances without hassle. The result is that these groundbreaking electric machines can now provide faster transport for less — cheaper than Uber and faster than Metro.

Since they are durable, fast, easy to operate and maintain, and are more convenient to park compared to four-wheelers, the eScooters trend has and continues to spike interest as a promising growth area. Several companies and universities are increasingly setting up shop to provide eScooter services realizing a would-be profitable business model and a ready customer base that is university students or residents in need of faster and cheap travel going about their business in school, town, and other surrounding areas.

Electric Scooters Trends and Statistics

In many countries including the U.S., Canada, Mexico, U.K., Germany, France, China, Japan, India, Brazil and Mexico and more, a growing number of eScooter users both locals and tourists can now be seen effortlessly passing lines of drivers stuck in the endless and unmoving traffic.

A recent report by McKinsey revealed that the E-Scooter industry will be worth― $200 billion to $300 billion in the United States, $100 billion to $150 billion in Europe, and $30 billion to $50 billion in China in 2030. The e-Scooter revenue model will also spike and is projected to rise by more than 20% amounting to approximately $5 billion.

And, with a necessity to move people away from high carbon prints, traffic and congestion issues brought about by car-centric transport systems in cities, more and more city planners are developing more bike/scooter lanes and adopting zero-emission plans. This is the force behind the booming electric scooter market and the numbers will only go higher and higher.

Companies that have taken advantage of the growing eScooter trend develop an appthat allows them to provide efficient eScooter services. Such an app enables them to be able to locate bike pick-up and drop points through fully integrated google maps.

List of Best Electric Bikes for Rental Business or Campus Facility 2020:

It’s clear that e scooters will increasingly become more common and the e-scooter business model will continue to grab the attention of manufacturers, investors, entrepreneurs. All this should go ahead with a quest to know what are some of the best electric bikes in the market especially for anyone who would want to get started in the electric bikes/scooters rental business.

We have done a comprehensive list of the best electric bikes! Each bike has been reviewed in depth and includes a full list of specs and a photo.

Billy eBike

mobile-best-electric-bikes-scooters https://www.kickstarter.com/projects/enkicycles/billy-were-redefining-joyrides

To start us off is the Billy eBike, a powerful go-anywhere urban electric bike that’s specially designed to offer an exciting ride like no other whether you want to ride to the grocery store, cafe, work or school. The Billy eBike comes in 4 color options – Billy Blue, Polished aluminium, Artic white, and Stealth black.

Price: $2490

Available countries

Available in the USA, Europe, Asia, South Africa and Australia.This item ships from the USA. Buyers are therefore responsible for any taxes and/or customs duties incurred once it arrives in your country.

Features

  • Control – Ride with confidence with our ultra-wide BMX bars and a hyper-responsive twist throttle.
  • Stealth- Ride like a ninja with our Gates carbon drive that’s as smooth as butter and maintenance-free.
  • Drive – Ride further with our high torque fat bike motor, giving a better climbing performance.
  • Accelerate – Ride quicker with our 20-inch lightweight cutout rims for improved acceleration.
  • Customize – Ride your own way with 5 levels of power control. Each level determines power and speed.
  • Flickable – Ride harder with our BMX /MotoX inspired geometry and lightweight aluminum package

Specifications

  • Maximum speed: 20 mph (32 km/h)
  • Range per charge: 41 miles (66 km)
  • Maximum Power: 500W
  • Motor type: Fat Bike Motor: Bafang RM G060.500.DC
  • Load capacity: 300lbs (136kg)
  • Battery type: 13.6Ah Samsung lithium-ion,
  • Battery capacity: On/off-bike charging available
  • Weight: w/o batt. 48.5lbs (22kg), w/ batt. 54lbs (24.5kg)
  • Front Suspension: Fully adjustable air shock, preload/compression damping /lockout
  • Rear Suspension: spring, preload adjustment
  • Built-in GPS

Why Should You Buy This?

  • Riding fun and excitement
  • Better climbing ability and faster acceleration.
  • Ride with confidence
  • Billy folds for convenient storage and transportation.
  • Shorty levers connect to disc brakes ensuring you stop on a dime
  • belt drives are maintenance-free and clean (no oil or lubrication needed)

**Who Should Ride Billy? **

Both new and experienced riders

**Where to Buy? **Local distributors or ships from the USA.

Genze 200 series e-Bike

genze-best-electric-bikes-scooters https://www.genze.com/fleet/

Featuring a sleek and lightweight aluminum frame design, the 200-Series ebike takes your riding experience to greater heights. Available in both black and white this ebike comes with a connected app, which allows you to plan activities, map distances and routes while also allowing connections with fellow riders.

Price: $2099.00

Available countries

The Genze 200 series e-Bike is available at GenZe retail locations across the U.S or online via GenZe.com website. Customers from outside the US can ship the product while incurring the relevant charges.

Features

  • 2 Frame Options
  • 2 Sizes
  • Integrated/Removable Battery
  • Throttle and Pedal Assist Ride Modes
  • Integrated LCD Display
  • Connected App
  • 24 month warranty
  • GPS navigation
  • Bluetooth connectivity

Specifications

  • Maximum speed: 20 mph with throttle
  • Range per charge: 15-18 miles w/ throttle and 30-50 miles w/ pedal assist
  • Charging time: 3.5 hours
  • Motor type: Brushless Rear Hub Motor
  • Gears: Microshift Thumb Shifter
  • Battery type: Removable Samsung 36V, 9.6AH Li-Ion battery pack
  • Battery capacity: 36V and 350 Wh
  • Weight: 46 pounds
  • Derailleur: 8-speed Shimano
  • Brakes: Dual classic
  • Wheels: 26 x 20 inches
  • Frame: 16, and 18 inches
  • Operating Mode: Analog mode 5 levels of Pedal Assist Thrott­le Mode

Norco from eBikestore

norco-best-electric-bikes-scooters https://ebikestore.com/shop/norco-vlt-s2/

The Norco VLT S2 is a front suspension e-Bike with solid components alongside the reliable Bosch Performance Line Power systems that offer precise pedal assistance during any riding situation.

Price: $2,699.00

Available countries

This item is available via the various Norco bikes international distributors.

Features

  • VLT aluminum frame- for stiffness and wheel security.
  • Bosch e-bike system – for their reliability and performance.
  • E-bike components – for added durability.
  • Hydraulic disc brakes – offer riders more stopping power for safety and control at higher speeds.
  • Practical design features – to add convenience and versatility.

Specifications

  • Maximum speed: KMC X9 9spd
  • Motor type: Bosch Active Line
  • Gears: Shimano Altus RD-M2000, SGS, 9 Speed
  • Battery type: Power Pack 400
  • Battery capacity: 396Wh
  • Suspension: SR Suntour suspension fork
  • Frame: Norco VLT, Aluminum, 12x142mm TA Dropouts

Bodo EV

bodo-best-electric-bikes-scootershttp://www.bodoevs.com/bodoev/products_show.asp?product_id=13

Manufactured by Bodo Vehicle Group Limited, the Bodo EV is specially designed for strong power and extraordinary long service to facilitate super amazing rides. The Bodo Vehicle Company is a striking top in electric vehicles brand field in China and across the globe. Their Bodo EV will no doubt provide your riders with high-level riding satisfaction owing to its high-quality design, strength, breaking stability and speed.

Price: $799

Available countries

This item ships from China with buyers bearing the shipping costs and other variables prior to delivery.

Features

  • Reliable
  • Environment friendly
  • Comfortable riding
  • Fashionable
  • Economical
  • Durable – long service life
  • Braking stability
  • LED lighting technology

Specifications

  • Maximum speed: 45km/h
  • Range per charge: 50km per person
  • Charging time: 8 hours
  • Maximum Power: 3000W
  • Motor type: Brushless DC Motor
  • Load capacity: 100kg
  • Battery type: Lead-acid battery
  • Battery capacity: 60V 20AH
  • Weight: w/o battery 47kg

#android app #autorent #entrepreneurship #ios app #minimum viable product (mvp) #mobile app development #news #app like bird #app like bounce #app like lime #autorent #best electric bikes 2020 #best electric bikes for rental business #best electric kick scooters 2020 #best electric kickscooters for rental business #best electric scooters 2020 #best electric scooters for rental business #bird scooter business model #bird scooter rental #bird scooter rental cost #bird scooter rental price #clone app like bird #clone app like bounce #clone app like lime #electric rental scooters #electric scooter company #electric scooter rental business #how do you start a moped #how to start a moped #how to start a scooter rental business #how to start an electric company #how to start electric scooterrental business #lime scooter business model #scooter franchise #scooter rental business #scooter rental business for sale #scooter rental business insurance #scooters franchise cost #white label app like bird #white label app like bounce #white label app like lime

Top 15 Free JavaScript Frameworks for Web Applications

List of some useful JavaScript Frameworks and libraries for website, web apps, and mobile apps development, that developers should know about to make selection easier.
This article will help you understand the various types of JavaScript Framework available in the market. When it comes to choosing the best platform for you, it’s not only the number of features you need to consider but also its functionality. The ease with which it fits within your project is also an essential factor. The next step is to choose the framework that best fits your company requirements or you can select the best from the list of top web development companies to develop your product based on your requirements.

#javascript frameworks for web applications #web applications development companies #progressive javascript framework #javascript frameworks #javascript #frameworks

Ahebwe  Oscar

Ahebwe Oscar

1620185280

How model queries work in Django

How model queries work in Django

Welcome to my blog, hey everyone in this article we are going to be working with queries in Django so for any web app that you build your going to want to write a query so you can retrieve information from your database so in this article I’ll be showing you all the different ways that you can write queries and it should cover about 90% of the cases that you’ll have when you’re writing your code the other 10% depend on your specific use case you may have to get more complicated but for the most part what I cover in this article should be able to help you so let’s start with the model that I have I’ve already created it.

**Read More : **How to make Chatbot in Python.

Read More : Django Admin Full Customization step by step

let’s just get into this diagram that I made so in here:

django queries aboutDescribe each parameter in Django querset

we’re making a simple query for the myModel table so we want to pull out all the information in the database so we have this variable which is gonna hold a return value and we have our myModel models so this is simply the myModel model name so whatever you named your model just make sure you specify that and we’re gonna access the objects attribute once we get that object’s attribute we can simply use the all method and this will return all the information in the database so we’re gonna start with all and then we will go into getting single items filtering that data and go to our command prompt.

Here and we’ll actually start making our queries from here to do this let’s just go ahead and run** Python manage.py shell** and I am in my project file so make sure you’re in there when you start and what this does is it gives us an interactive shell to actually start working with our data so this is a lot like the Python shell but because we did manage.py it allows us to do things a Django way and actually query our database now open up the command prompt and let’s go ahead and start making our first queries.

#django #django model queries #django orm #django queries #django query #model django query #model query #query with django

Marget D

Marget D

1626077187

4 key Features of Django Framework that Make it the Best Amongst all!

Django is one of the popular python based open-source web frameworks mainly used by the developers who like to have rapid development along with the clean pragmatic design.

Read this blog to know the various Django Features with details.

#django framework #django web development #django development company #django development services #python django development company #python django development