Django-allauth Installation

There is a useful django-allauth video tutorial at Create third party Facebook login in Django. The document below simply follows that but only adds facebook social authentication. Documentation can be found at django-alluth documentation. django-allauth can also be installed by cloning from https://github.com/pennersr/django-allauth I am running Django 1.9.5 and will install django-allauth 0.25.2 Setup a…Read More

Part 6: Django CRUD, Update

Continued from Part 5: Django CRUD, Delete Full code on https://github.com/shanegibney/djangoCRUD We may wish to update the model ‘Members’. Let us start by adding an edit icon to the table in ‘index.html’. <td><a href=”{% url ‘edit_new’ item.id %}”><span class=”glyphicon glyphicon-pencil”></span></a></td> If you are not using Bootstrap replace the span tags with ‘edit’. <td><a href=”{% url ‘edit_new’…Read More

Part 3: Django CRUD, Display Models

Continued from Part 2: Setting up Django, URL’s & Views Full code on https://github.com/shanegibney/djangoCRUD Add to the crudapp/models.py file from django.db import models In the same file create a model called ‘Members’ with columns for ‘first_name’, ‘last_name’ and ‘description’. This is equivalent to a table called ‘Members’ with fields for ‘first_name’, ‘last_name’ and ‘description’. class Members(models.Model): first_name =…Read More

Simple Python into HTML

The following Python code will find instances of {body} in a file template.html and replace it with a string. Then a new file index.html is created with this change. generate.py with open(‘template.html’,’r’) as template_file: template = template_file.read() content = template tokens = {‘body’: ‘Body stuff can go here’} replaced = ‘Body stuff can go here.’…Read More

Running Python unittests from Command Line

This script will allow a Python unittest to be run from the command line. import unittest import testFile suite = unittest.TestLoader().loadTestsFromModule(testFile) unittest.TextTestRunner().run(suite) testFile.py import unittest from fun import add class test_function(unittest.TestCase): def test_one(self): result = add(2,3) self.assertEquals(result, 5) fun.py def add(a,b): return a+b

Simple Python Unit Test

This simple Python unit-test tests two function. The first function adds two numbers and the second function uses list comprehensions to make a list of numbers from to 0 to n which are divisible by m. testFile.py import unittest from add import addition, make_list class test_add_function(unittest.TestCase): def test_for_add(self): result = addition(1, 5) self.assertEqual(result, 6) def…Read More

Angular Service Example

The following code demonstrates how a service can be created in AngularJS. index.html <html> <head> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js”></script> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js”></script> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-route.min.js”></script> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.min.js”></script> <script src=”app.js”></script> <script src=”anotherModule.js”></script> </head> <body> <div ng-app=”mainModule” ng-controller=”mainController as alias”> <b>Invoice:</b> <p>The input is: {{alias.quantity}}</p> <div> Quantity: <input type=”number” min=”0″ ng-model=”alias.quantity”required> </div> <div><p>Add 4 and double it!</p></div> <div> <b>Result:</b> <span>{{alias.total(alias.quantity)}}</span> <button…Read More

Install Mongodb on Fedora 23

To install Mongodb on Fedora 23 go to https://www.mongodb.org/downloads On the Linux tab go to version RHEL 7 Linux 64-bit $ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.3.tgz Untar the tarball $ tar -zxvf mongodb-linux-x86_64-rhel70-3.2.3.tgz $ echo $PATH $ sudo ln -s ~/Downloads/mongodb-linux-x86_64-rhel70-3.2.3/bin/mongo /usr/local/bin/mongod $ mongod –version MongoDB shell version: 3.2.3 $ mongo –version MongoDB shell version: 3.0.8 Make the…Read More