diff --git a/prajesh_gohel/.DS_Store b/prajesh_gohel/.DS_Store index 68bde749..2ec4b737 100644 Binary files a/prajesh_gohel/.DS_Store and b/prajesh_gohel/.DS_Store differ diff --git a/prajesh_gohel/APIs_and_AJAX/Pokemon/bulbasaur.html b/prajesh_gohel/APIs_and_AJAX/Pokemon/bulbasaur.html new file mode 100644 index 00000000..f5e708f1 --- /dev/null +++ b/prajesh_gohel/APIs_and_AJAX/Pokemon/bulbasaur.html @@ -0,0 +1,25 @@ + + + + + Bulbasaur + + +
+ + + + diff --git a/prajesh_gohel/APIs_and_AJAX/Pokemon/index.html b/prajesh_gohel/APIs_and_AJAX/Pokemon/index.html index 679e43ae..64363f1f 100644 --- a/prajesh_gohel/APIs_and_AJAX/Pokemon/index.html +++ b/prajesh_gohel/APIs_and_AJAX/Pokemon/index.html @@ -2,19 +2,26 @@ - HTTP Request Response + Pokedex + -
- +
+
+
+
+
+ + +

Find all users whose name starts with +

+ {% csrf_token %} + +
+

+
+ + + diff --git a/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/tests.py b/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/urls.py b/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/urls.py new file mode 100644 index 00000000..fb5b27d8 --- /dev/null +++ b/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.autosearch), +] diff --git a/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/views.py b/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/views.py new file mode 100644 index 00000000..fd3be764 --- /dev/null +++ b/prajesh_gohel/Python/ajax_django/ajax_example/apps/autosearch/views.py @@ -0,0 +1,8 @@ +from django.shortcuts import render, HttpResponse, redirect +from .models import * + +def autosearch(request): + context = { + 'users': User.objects.filter(name=request.POST['starts_with']) + } + return render(request, 'ajax_example/autosearch.html', context) diff --git a/prajesh_gohel/Python/ajax_django/ajax_example/db.sqlite3 b/prajesh_gohel/Python/ajax_django/ajax_example/db.sqlite3 new file mode 100644 index 00000000..167c12b1 Binary files /dev/null and b/prajesh_gohel/Python/ajax_django/ajax_example/db.sqlite3 differ diff --git a/prajesh_gohel/Python/ajax_django/ajax_example/manage.py b/prajesh_gohel/Python/ajax_django/ajax_example/manage.py new file mode 100755 index 00000000..1929164c --- /dev/null +++ b/prajesh_gohel/Python/ajax_django/ajax_example/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ajax_example.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/prajesh_gohel/Python/django_ORM/Courses.zip b/prajesh_gohel/Python/django_ORM/Courses.zip new file mode 100644 index 00000000..b9f67744 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/Courses.zip differ diff --git a/prajesh_gohel/Python/django_ORM/Handy_Helper_Exam.zip b/prajesh_gohel/Python/django_ORM/Handy_Helper_Exam.zip new file mode 100644 index 00000000..3cc2b7ab Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/Handy_Helper_Exam.zip differ diff --git a/prajesh_gohel/Python/django_ORM/Login_Registration.zip b/prajesh_gohel/Python/django_ORM/Login_Registration.zip new file mode 100644 index 00000000..c56c06f7 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/Login_Registration.zip differ diff --git a/prajesh_gohel/Python/django_ORM/Quote_Dash_Exam.zip b/prajesh_gohel/Python/django_ORM/Quote_Dash_Exam.zip new file mode 100644 index 00000000..b0ec1cfb Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/Quote_Dash_Exam.zip differ diff --git a/prajesh_gohel/Python/django_ORM/SemiRestful_Users.zip b/prajesh_gohel/Python/django_ORM/SemiRestful_Users.zip new file mode 100644 index 00000000..72a749aa Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/SemiRestful_Users.zip differ diff --git a/prajesh_gohel/Python/django_ORM/belt_reviewer.txt b/prajesh_gohel/Python/django_ORM/belt_reviewer.txt new file mode 100644 index 00000000..a59209fc --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/belt_reviewer.txt @@ -0,0 +1,38 @@ +** Conceptual Questions ** + +1. What is the flow of information in a typical request, from when we type an address on our browser, to when we receive the response on our browser? + + Say we are at localhost:8000 and we want to get to localhost:8000/users. The first thing that will happen is the browser will send an HTTP GET request for everything in /users. Then, the server processes all of that information and sends a GET method over to the browser, where it is converted into HTML, CSS, and JavaScript. + +2. What is MVC, OOP and procedural programming? Why would we use each? + + MVC stands for model-view-controller, and it is a type of framework that separates the information into different parts to ease the process of creating backend. + OOP stands for object-oriented-programming, and it refers to organizing information in "objects" instead of "actions"; it allows us to manipulate the objects themselves when creating backend. + +3. What is jQuery and why do we use it? + + jQuery is a library that utilizes JavaScript code and simplifies it to lessen the amount of code you would normally need with pure JavaScript. + +4. What are some ways to make your website uniform across multiple browsers? + + One way to ensure uniformity is to validate your HTML code with w3validator: this site checks not only any errors you have made in your HTML but also warns you about browser compatibility. + +5. What are the differences between submitting a form via method="post" vs method="get"? + + A get method is a nonsecure method that is used to get to another route. A post method is a more secure route that protects any information coming in (including passwords, email, etc), and spits it back out to a different route that has a get method. + +6. What are the advantages/disadvantages of sending data to the server in the url vs making a post request? + + The biggest disadvantage of not using a post request is all of the information that was inputted in a form will be displayed in the url itself when the form is submitted. This can be extremely dangerous as hackers can easily take that information and do whatever they want with it. + +7. Why should we never render a page on a post request. + + The post method handles all of the processing from the submitted form; it will not allow you to actually render anything. If you did make it to where it renders AND handles a post request, a person would be resubmitting that data from the form every-time they refresh the page. + +8. You notice that when you click submit on a form, your app breaks. Describe how you would approach debugging this problem. + + The first thing to do is to put in a print function in the route that it is going to in order to see if the browser is actually getting to that particular route or function. If not, see what you can do to fix the path. If it does, check any syntax issues, key errors, etc., until your form finally submits properly. Just do double check, see if the information is actually stored in the database. + +9. What is an ORM and why do we use it? What are its advantages and also its disadvantages. + + ORM stands for object-relational-mapping, and it allows a developer to create and run SQL codes using all of the backend. There is usually a file called "models" that stores the information for the tables and relationships of those tables. The big advantage is it can save time if you know the ORM syntax. The big disadvantage is it can be difficult to actually visualize the tables, so a browser is normally recommended if using ORM. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..76ab6d8a Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..9e4e9237 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..f3c5459f Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..5a6c999b Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..756b71d5 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..a1d4df38 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/admin.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/apps.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/apps.py new file mode 100644 index 00000000..cdee0922 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class BlogsAppConfig(AppConfig): + name = 'blogs_app' diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/0001_initial.py new file mode 100644 index 00000000..5207db14 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/0001_initial.py @@ -0,0 +1,51 @@ +# Generated by Django 2.0.7 on 2018-07-17 15:35 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Admin', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='Blog', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('desc', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='Comment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('comment', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('blog', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='blogs_app.Blog')), + ], + ), + migrations.AddField( + model_name='admin', + name='blogs', + field=models.ManyToManyField(related_name='admins', to='blogs_app.Blog'), + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..f0b9412f Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/0002_comment.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/0002_comment.cpython-37.pyc new file mode 100644 index 00000000..54c37086 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/0002_comment.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..c7bf1787 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/models.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/models.py new file mode 100644 index 00000000..227bbc73 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/models.py @@ -0,0 +1,20 @@ +from __future__ import unicode_literals +from django.db import models + +class Blog(models.Model): + name = models.CharField(max_length=255) + desc = models.TextField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) +class Comment(models.Model): + comment = models.CharField(max_length=255) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + blog = models.ForeignKey(Blog, related_name = "comments", on_delete=models.CASCADE) +class Admin(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + email = models.CharField(max_length=255) + blogs = models.ManyToManyField(Blog, related_name = "admins") + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/templates/blogs/index.html b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/templates/blogs/index.html new file mode 100644 index 00000000..9d6f674d --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/templates/blogs/index.html @@ -0,0 +1,17 @@ + + + + + Create a blog + + +
+ {% csrf_token %} + + + + + +
+ + diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/tests.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/urls.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/urls.py new file mode 100644 index 00000000..da60a642 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls import url +from . import views +urlpatterns = [ + url(r'^$', views.index), + url(r'^blogs/$', views.display), + url(r'^blogs/new/$', views.new), + url(r'^blogs/create/$', views.create), + url(r'^blogs/(?P\d+)/$', views.show), + url(r'^blogs/(?P\d+)/edit/', views.edit), + url(r'^blogs/(?P\d+)/delete/', views.destroy) +] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/views.py b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/views.py new file mode 100644 index 00000000..ef105080 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/views.py @@ -0,0 +1,35 @@ +from django.shortcuts import render, HttpResponse, redirect + +def index(request): + return render(request, 'blogs/index.html') + +def display(request): + response = "Placeholder to later display all the list of blogs" + return HttpResponse(response) + +def new(request): + return render(request, "blogs/index.html") + +def create(request): + if request.method == "POST": + print("*"*50) + print(request.POST) + print(request.POST['name']) + print(request.POST['desc']) + request.session['name'] = "test" # more on session below + print("*"*50) + return redirect("/") + else: + return redirect("/") + +def show(request, number): + print(number) + return HttpResponse("show method " + number) + +def edit(request, number): + print(number) + return HttpResponse("Placeholder to edit blog " + number) + +def destroy(request, number): + print(number) + return redirect('/') diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..9e5b48f8 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..8593b86c Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..9c0338da Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/admin.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/apps.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/apps.py new file mode 100644 index 00000000..a9ac4998 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class BookAuthorsConfig(AppConfig): + name = 'book_authors' diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/0001_initial.py new file mode 100644 index 00000000..e6b002c4 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# Generated by Django 2.0.7 on 2018-07-17 19:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Author', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('desc', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('authors', models.ManyToManyField(related_name='books', to='book_authors.Author')), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/0002_author_notes.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/0002_author_notes.py new file mode 100644 index 00000000..8162d61a --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/0002_author_notes.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.7 on 2018-07-17 20:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('book_authors', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='author', + name='notes', + field=models.TextField(default='null'), + preserve_default=False, + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..00ac7340 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/0002_author_notes.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/0002_author_notes.cpython-37.pyc new file mode 100644 index 00000000..cfb5516c Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/0002_author_notes.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..a94dd5d9 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/models.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/models.py new file mode 100644 index 00000000..2951f42e --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/models.py @@ -0,0 +1,21 @@ +from __future__ import unicode_literals +from django.db import models + +class Author(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + email = models.CharField(max_length = 255) + notes = models.TextField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __repr__(self): + return "".format(self.first_name, self.last_name, self.email) + +class Book(models.Model): + name = models.CharField(max_length = 255) + desc = models.TextField() + authors = models.ManyToManyField(Author, related_name = "books") + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __repr__(self): + return "".format(self.name, self.desc) diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/tests.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/views.py b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/book_authors/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..1f308314 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..3d641071 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..8a65a3d8 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/admin.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/apps.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/apps.py new file mode 100644 index 00000000..107ce9ec --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class DojoNinjasConfig(AppConfig): + name = 'dojo_ninjas' diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0001_initial.py new file mode 100644 index 00000000..bbcb4bbe --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0001_initial.py @@ -0,0 +1,37 @@ +# Generated by Django 2.0.7 on 2018-07-17 17:49 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Dojo', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('city', models.CharField(max_length=255)), + ('state', models.CharField(max_length=2)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='Ninja', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('ninja', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ninjas', to='dojo_ninjas.Dojo')), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0002_auto_20180717_1807.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0002_auto_20180717_1807.py new file mode 100644 index 00000000..246ca4a8 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0002_auto_20180717_1807.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.7 on 2018-07-17 18:07 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('dojo_ninjas', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='ninja', + old_name='ninja', + new_name='dojo', + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0003_dojo_desc.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0003_dojo_desc.py new file mode 100644 index 00000000..07065de2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/0003_dojo_desc.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.7 on 2018-07-17 19:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dojo_ninjas', '0002_auto_20180717_1807'), + ] + + operations = [ + migrations.AddField( + model_name='dojo', + name='desc', + field=models.TextField(default=1), + preserve_default=False, + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..86d2ac35 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0002_auto_20180717_1807.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0002_auto_20180717_1807.cpython-37.pyc new file mode 100644 index 00000000..f3aed3e2 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0002_auto_20180717_1807.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0003_dojo_desc.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0003_dojo_desc.cpython-37.pyc new file mode 100644 index 00000000..ee5e8d2f Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/0003_dojo_desc.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..ec8181b4 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/models.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/models.py new file mode 100644 index 00000000..6d384ac1 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/models.py @@ -0,0 +1,21 @@ +from __future__ import unicode_literals +from django.db import models + +class Dojo(models.Model): + name = models.CharField(max_length = 255) + city = models.CharField(max_length = 255) + state = models.CharField(max_length = 2) + desc = models.TextField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __repr__(self): + return "".format(self.name, self.city, self.state) + +class Ninja(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + dojo = models.ForeignKey(Dojo, related_name = "ninjas", on_delete = models.CASCADE) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __repr__(self): + return "".format(self.first_name, self.last_name, self.dojo) diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/tests.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/views.py b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/dojo_ninjas/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..4f9deae6 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..348f286b Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..3cfc1694 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/admin.py b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/apps.py b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/apps.py new file mode 100644 index 00000000..493837b2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class LikeBooksConfig(AppConfig): + name = 'like_books' diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/0001_initial.py new file mode 100644 index 00000000..5fc153e3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/0001_initial.py @@ -0,0 +1,46 @@ +# Generated by Django 2.0.7 on 2018-07-17 20:58 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('desc', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.AddField( + model_name='book', + name='liked_users', + field=models.ManyToManyField(related_name='liked_books', to='like_books.User'), + ), + migrations.AddField( + model_name='book', + name='uploader', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='uploaded_books', to='like_books.User'), + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..397908e9 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..c7f6a954 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/models.py b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/models.py new file mode 100644 index 00000000..4a4ce8e4 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/models.py @@ -0,0 +1,21 @@ +from __future__ import unicode_literals +from django.db import models + +class User(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + email = models.CharField(max_length = 255) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __repr__(self): + return "".format(self.first_name, self.last_name, self.email) + +class Book(models.Model): + name = models.CharField(max_length = 255) + desc = models.TextField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + uploader = models.ForeignKey(User, related_name = "uploaded_books", on_delete = models.CASCADE) + liked_users = models.ManyToManyField(User, related_name = "liked_books") + def __repr__(self): + return "".format(self.name, self.desc) diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/tests.py b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/views.py b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/views.py new file mode 100644 index 00000000..30001835 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/like_books/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render, HttpResponse, redirect + +def index(request): + response = "placeholder" + return HttpResponse(response) diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..bb3af5bf Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..eea8a28a Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..59682a00 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..ed44e73e Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..f418f076 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/admin.py b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/apps.py b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/apps.py new file mode 100644 index 00000000..861dd6e2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SurveysConfig(AppConfig): + name = 'surveys' diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..dddcf5be Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/models.py b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/tests.py b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/urls.py b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/urls.py new file mode 100644 index 00000000..3b00b011 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url, include +from . import views +urlpatterns = [ + url(r'^$', views.display), + url(r'^new/$', views.new), +] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/views.py b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/views.py new file mode 100644 index 00000000..cae7ab3a --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/surveys/views.py @@ -0,0 +1,8 @@ +from django.shortcuts import render, HttpResponse +def display(request): + response = "placeholder to display all the surveys created" + return HttpResponse(response) + +def new(request): + response = "placeholder for users to add a new survey" + return HttpResponse(response) diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..5186dfca Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..400e6759 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..ae548664 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..7380da6b Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..091389b3 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/users/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/admin.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/users/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/apps.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/apps.py new file mode 100644 index 00000000..4ce1fabc --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/users/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + name = 'users' diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/0001_initial.py new file mode 100644 index 00000000..3c4b6380 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 2.0.7 on 2018-07-17 16:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email_address', models.CharField(max_length=255)), + ('age', models.IntegerField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..9fa60b96 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..e6360411 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/apps/users/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/models.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/models.py new file mode 100644 index 00000000..0fa0625e --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/users/models.py @@ -0,0 +1,12 @@ +from __future__ import unicode_literals +from django.db import models + +class User(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + email_address = models.CharField(max_length = 255) + age = models.IntegerField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __repr__(self): + return "".format(self.first_name, self.last_name, self.email_address, self.age) diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/tests.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/urls.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/urls.py new file mode 100644 index 00000000..33dc983c --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/users/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls import url +from . import views +urlpatterns = [ + url(r'^register/$', views.register), + url(r'^login/$', views.login), + url(r'^users/$', views.users), + url(r'^users/new/$', views.new), +] diff --git a/prajesh_gohel/Python/django_ORM/blogs/apps/users/views.py b/prajesh_gohel/Python/django_ORM/blogs/apps/users/views.py new file mode 100644 index 00000000..fd206cbc --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/apps/users/views.py @@ -0,0 +1,16 @@ +from django.shortcuts import render, HttpResponse, redirect + +def register(request): + response = "placeholder for users to create a new user record" + return HttpResponse(response) + +def login(request): + response = "placeholder to login users" + return HttpResponse(response) + +def users(request): + response = "placeholder to later display all the list of users" + return HttpResponse(response) + +def new(request): + return redirect('/register') diff --git a/prajesh_gohel/Python/django_ORM/blogs/blogs/__init__.py b/prajesh_gohel/Python/django_ORM/blogs/blogs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..03a4c4c6 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/settings.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/settings.cpython-37.pyc new file mode 100644 index 00000000..184e8bdd Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/settings.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..e0a2e3be Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/wsgi.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 00000000..133115f2 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/blogs/__pycache__/wsgi.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/blogs/settings.py b/prajesh_gohel/Python/django_ORM/blogs/blogs/settings.py new file mode 100644 index 00000000..80f525c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/blogs/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for blogs project. + +Generated by 'django-admin startproject' using Django 1.10. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'czh%^r*e4x@gf*)44#(tbff#i)hfn%mp^f6=_@h(g8%bnx=36-' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.like_books', + 'apps.book_authors', + 'apps.dojo_ninjas', + 'apps.users', + 'apps.surveys', + 'apps.blogs_app', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'blogs.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'blogs.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/prajesh_gohel/Python/django_ORM/blogs/blogs/urls.py b/prajesh_gohel/Python/django_ORM/blogs/blogs/urls.py new file mode 100644 index 00000000..f83aecf5 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/blogs/urls.py @@ -0,0 +1,22 @@ +"""blogs URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include + +urlpatterns = [ + url(r'^', include('apps.blogs_app.urls')), + url(r'^surveys/', include('apps.surveys.urls')), + url(r'^', include('apps.users.urls')), +] diff --git a/prajesh_gohel/Python/django_ORM/blogs/blogs/wsgi.py b/prajesh_gohel/Python/django_ORM/blogs/blogs/wsgi.py new file mode 100644 index 00000000..cb779443 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/blogs/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for blogs project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blogs.settings") + +application = get_wsgi_application() diff --git a/prajesh_gohel/Python/django_ORM/blogs/db.sqlite3 b/prajesh_gohel/Python/django_ORM/blogs/db.sqlite3 new file mode 100644 index 00000000..2ff9bb71 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/blogs/db.sqlite3 differ diff --git a/prajesh_gohel/Python/django_ORM/blogs/manage.py b/prajesh_gohel/Python/django_ORM/blogs/manage.py new file mode 100755 index 00000000..e0eccd90 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/blogs/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blogs.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/prajesh_gohel/Python/django_ORM/book_authors.txt b/prajesh_gohel/Python/django_ORM/book_authors.txt new file mode 100644 index 00000000..0ed7539a --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/book_authors.txt @@ -0,0 +1,17 @@ +1. Change the name of the 5th book to C# + + In [7]: b = Book.objects.get(id=2) + + In [8]: b.name = "C#" + + In [9]: b.save() + +2. Change the first_name of the 5th author to Ketu + +3. For 3rd book, remove first author + + In [37]: Book.objects.get(id=4).authors.get(id=2).delete() + +4. Assign the fourth author to the first 5 books (or in other words, all the books) + + In [30]: Author.objects.get(id=4).books.add(Book.objects.get(id=6)) diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/__init__.py b/prajesh_gohel/Python/django_ORM/courses/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..b051cdb7 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__init__.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..6aac1389 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..b916a247 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..ea30aa81 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..e697fb0c Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..7cc5d5a8 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/admin.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/apps.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/apps.py new file mode 100644 index 00000000..c60f8fad --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CoursesAppConfig(AppConfig): + name = 'courses_app' diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/0001_initial.py new file mode 100644 index 00000000..e8d67676 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# Generated by Django 2.0.7 on 2018-07-18 19:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Course', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('desc', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/0002_comment.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/0002_comment.py new file mode 100644 index 00000000..7ef19f80 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/0002_comment.py @@ -0,0 +1,24 @@ +# Generated by Django 2.0.7 on 2018-07-18 20:50 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses_app', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Comment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('text', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='courses_app.Course')), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..6f971df5 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/0002_comment.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/0002_comment.cpython-37.pyc new file mode 100644 index 00000000..fa5d9b9a Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/0002_comment.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..8e6a83ad Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/models.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/models.py new file mode 100644 index 00000000..11e85d3a --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/models.py @@ -0,0 +1,44 @@ +from __future__ import unicode_literals +from django.db import models + +class CourseManager(models.Manager): + def basic_validator(self, postData): + errors = {} + if len(postData['name']) < 1: + errors['name'] = "Please input a course name!" + + elif len(postData['name']) < 5: + errors['name'] = "Name needs to be at least 5 characters!" + + if len(postData['desc']) < 1: + errors['desc'] = "Please input a description for your course!" + + elif len(postData['desc']) < 15: + errors['desc'] = "Description must be at least 15 characters!" + + return errors + + def comment_validator(self, postData): + errors = {} + if len(postData['comment']) < 1: + errors['comment'] = "You need to write a comment!" + + return errors + +class Course(models.Model): + name = models.CharField(max_length = 255) + desc = models.TextField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = CourseManager() + def __repr__(self): + return "".format(self.name, self.desc, self.created_at) + +class Comment(models.Model): + text = models.TextField() + course = models.ForeignKey(Course, related_name = "comments", on_delete = models.CASCADE) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = CourseManager() + def __repr__(self): + return "".format(self.text) diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/comments.html b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/comments.html new file mode 100644 index 00000000..9a2f1cf4 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/comments.html @@ -0,0 +1,28 @@ + + + + + Display Comments + + + +
+ {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+ {% csrf_token %} +

Add a Comment:

+ + +
+ Go back +

All Comments:

+ {% for comment in comments %} +

{{comment.text}}

+ {% endfor %} +
+ + diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/confirm.html b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/confirm.html new file mode 100644 index 00000000..8d70ef78 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/confirm.html @@ -0,0 +1,19 @@ + + + + + Delete Course + + + +
+

Are you sure you want to delete the following course?

+

Name: {{course.name}}

+

Description: {{course.desc}}

+
+ No + Yes +
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/index.html b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/index.html new file mode 100644 index 00000000..01334013 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/templates/courses/index.html @@ -0,0 +1,55 @@ + + + + + Courses + + + + +
+ {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+ {% csrf_token %} +

Add a new course:

+
+ + +
+
+ + +
+ +
+ + + + + + + + + + + {% for course in courses %} + + + + + + + {% endfor %} + +
Course NameDescriptionDate AddedActions
{{course.name}}{{course.desc}}{{course.created_at}} Remove | Comments
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/tests.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/urls.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/urls.py new file mode 100644 index 00000000..0229f4fc --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/urls.py @@ -0,0 +1,11 @@ +from django.urls import path, include +from . import views + +urlpatterns = [ + path('', views.index), + path('create/', views.create), + path('destroy//', views.confirm), + path('destroy//delete/', views.delete), + path('comments//', views.comments), + path('comments//add/', views.add), +] diff --git a/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/views.py b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/views.py new file mode 100644 index 00000000..9a6e0ddb --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/apps/courses_app/views.py @@ -0,0 +1,69 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.contrib import messages +from .models import * + +def index(request): + context = { + "courses": Course.objects.all() + } + + return render(request, 'courses/index.html', context) + +def create(request): + errors = Course.objects.basic_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + else: + Course.objects.create(name=request.POST['name'], desc=request.POST['desc']) + return redirect('/') + + print("*"*80) + print("Someone tried to bypass the Post method, they have been redirected") + print("*"*80) + return redirect('/') + +def confirm(request, id): + context = { + "course": Course.objects.get(id=int(id)) + } + + return render(request, 'courses/confirm.html', context) + +def delete(request, id): + delete_course = Course.objects.get(id=int(id)) + delete_course.delete() + return redirect('/') + +def comments(request, id): + c = Course.objects.get(id=int(id)) + context = { + "course": c, + "comments": c.comments.all() + } + + return render(request, 'courses/comments.html', context) + +def add(request, id): + errors = Course.objects.comment_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/comments/'+id+'/') + + else: + create_comment = Course.objects.get(id=int(id)) + create_comment.comments.create(text=request.POST['comment']) + create_comment.save() + return redirect('/comments/'+id+'/') + + print("*"*80) + print("Someone tried to bypass the Post method, they have been redirected") + print("*"*80) + return redirect('/') diff --git a/prajesh_gohel/Python/django_ORM/courses/courses/__init__.py b/prajesh_gohel/Python/django_ORM/courses/courses/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..dfaa122b Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/settings.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/settings.cpython-37.pyc new file mode 100644 index 00000000..83694c8c Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/settings.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..9106e427 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/wsgi.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 00000000..b31705bc Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/courses/__pycache__/wsgi.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/courses/courses/settings.py b/prajesh_gohel/Python/django_ORM/courses/courses/settings.py new file mode 100644 index 00000000..dc669e93 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/courses/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for courses project. + +Generated by 'django-admin startproject' using Django 2.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'x&2&+i(3pqpnxkbt+h#7!5dl+_^9bga9=4$wbqb8$f0g-ousxl' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.courses_app', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'courses.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'courses.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/prajesh_gohel/Python/django_ORM/courses/courses/urls.py b/prajesh_gohel/Python/django_ORM/courses/courses/urls.py new file mode 100644 index 00000000..70fd53f6 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/courses/urls.py @@ -0,0 +1,20 @@ +"""courses URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.urls import path, include + +urlpatterns = [ + path('', include('apps.courses_app.urls')), +] diff --git a/prajesh_gohel/Python/django_ORM/courses/courses/wsgi.py b/prajesh_gohel/Python/django_ORM/courses/courses/wsgi.py new file mode 100644 index 00000000..b88197d5 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/courses/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for courses project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "courses.settings") + +application = get_wsgi_application() diff --git a/prajesh_gohel/Python/django_ORM/courses/db.sqlite3 b/prajesh_gohel/Python/django_ORM/courses/db.sqlite3 new file mode 100644 index 00000000..df59b2a5 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/courses/db.sqlite3 differ diff --git a/prajesh_gohel/Python/django_ORM/courses/manage.py b/prajesh_gohel/Python/django_ORM/courses/manage.py new file mode 100755 index 00000000..10a14164 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/courses/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "courses.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/prajesh_gohel/Python/django_ORM/dojo_ninjas.txt b/prajesh_gohel/Python/django_ORM/dojo_ninjas.txt new file mode 100644 index 00000000..d1c4e066 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/dojo_ninjas.txt @@ -0,0 +1,35 @@ +1. Create 3 dojos + + In [3]: Dojo.objects.create(name="CodingDojo Silicon Valley", city="Mountain Vie + ...: w", state="CA") + +2. Delete the three dojos you created (e.g. Dojo.objects.get(id=1).delete()) + + In [15]: a = Dojo.objects.all() + + In [16]: a.delete() + +3. Create 3 additional dojos by using Dojo.objects.create + + See 1. + +4. Create 3 ninjas that belong to each dojo you created + + In [5]: Ninja.objects.create(first_name="Salman", last_name="Khan", dojo=Dojo.ob + ...: jects.get(id=1)) + + In [6]: Ninja.objects.create(first_name="Michael", last_name="Scott", dojo=Dojo. + ...: objects.get(id=1)) + + In [7]: Ninja.objects.create(first_name="Thea", last_name="Queen", dojo=Dojo.obj + ...: ects.get(id=1)) + + (rinse and repeat) + +5. Be able to retrieve all ninjas that belong to the first Dojo + + In [15]: Dojo.objects.first().ninjas.all() + +6. Be able to retrieve all ninjas that belong to the last Dojo + + In [16]: Dojo.objects.last().ninjas.all() diff --git a/prajesh_gohel/Python/django_ORM/exam_1_info.txt b/prajesh_gohel/Python/django_ORM/exam_1_info.txt new file mode 100644 index 00000000..594e0eea --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/exam_1_info.txt @@ -0,0 +1,25 @@ +For a red belt: + ***DONE*** Login and Registration with validations + ***DONE*** Validation errors should appear on the page + ***DONE*** Logout feature + ***DONE*** Adding of Quotes + ***DONE*** Validation for empty entries should apply and should display error messages + ***DONE*** Logged in user must be able to delete quotes that they have posted + ***DONE*** “Posted by” link must send user to a page of all quotes by the quote poster + ***DONE*** Quote dashboard page should say “Welcome {{ User }}” + ***DONE*** User can edit their account data in the Edit My Account Page + ***DONE*** HTML and CSS reflect the wireframe to at least 75% accuracy +For a black belt: + You must be able to deploy your work to Amazon EC2 and provide the IP address or subdomain/domain name to where your work has been deployed + Please note that Heroku deployment is not honored + ***DONE*** Edit My Account Page should pre populate form fields with current user data in database + Like button + Each quote should display the number of likes + User can only like a quote once + ***DONE*** Edit My Account page should validate empty fields, email regex, and check that email is not already in use +Also: + Create a short video walking through the features of your app. Show your validations working. There is no need to speak or show your code. + Remove your github repo after deploying. + The wireframe is available for download here. +Don’t worry about: + What the prompts are asking for. Just ask if you are unsure about what the goals are! diff --git a/prajesh_gohel/Python/django_ORM/exam_2_info.txt b/prajesh_gohel/Python/django_ORM/exam_2_info.txt new file mode 100644 index 00000000..4462d42d --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/exam_2_info.txt @@ -0,0 +1,25 @@ +For a red belt: + **DONE** Login and Registration with validations + **DONE** Validation errors should appear on the page + **DONE** Logout feature + **DONE** Dashboard + **DONE** "Cancel" link appears if the logged user is the one who created the job + **DONE** "Cancel" link removes the job from the database + **DONE** "Edit" link appears if the logged user is the one who created the job + **DONE** "Edit" link routes to the edit page + **DONE** Dashboard should say "Welcome {{user}}" + **DONE** "View" link routes to the individual job page + **DONE** Add a job + **DONE** Validation for empty input fields + **DONE** Title must be greater than three characters long + **DONE** Description must be greater than ten characters long + **DONE** HTML and CSS reflect the wireframe to at least 75% accuracy + +For a black belt: + You must be able to deploy your work to Amazon EC2 and provide the IP address or subdomain/domain name to where your work has been deployed + Please note that Heroku deployment is not honored + **DONE** "Add" link must add the job to the My Jobs list that is unique to the user + **DONE** When a job is added, it must also be removed from the jobs table + **DONE** "Add To My Jobs" link on the individual job page must do the same as the "Add" link on the dashboard + **DONE** Edit page input fields must be pre-populated with current data from the database + **DONE** Done link on the user's My Jobs list deletes the job from the database diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..806c5578 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..934c1d08 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..49271b92 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..f27595c9 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..34236035 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..06961348 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/admin.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/apps.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/apps.py new file mode 100644 index 00000000..7cd7f6c8 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AddjobConfig(AppConfig): + name = 'addJob' diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..73ed1974 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/models.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/templates/handy_helper_exam/addJob.html b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/templates/handy_helper_exam/addJob.html new file mode 100644 index 00000000..8c8a37c0 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/templates/handy_helper_exam/addJob.html @@ -0,0 +1,43 @@ + + + + + Welcome + + + + + + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+ +
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/tests.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/urls.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/urls.py new file mode 100644 index 00000000..aa35144f --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.add), + path('insert/', views.insert), +] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/views.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/views.py new file mode 100644 index 00000000..4c483bbb --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/addJob/views.py @@ -0,0 +1,22 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.contrib import messages +from ..dashboard.models import * +from ..login.models import * + +def add(request): + return render(request, 'handy_helper_exam/addJob.html') + +def insert(request): + errors = Job.objects.job_validation(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/addJob') + + else: + Job.objects.create(title = request.POST['title'], desc = request.POST['desc'], location = request.POST['location'], user = User.objects.get(email = request.session['email'])) + return redirect('/dashboard') + + return redirect('/addJob') diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..be31fc24 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..af08201d Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..a6cc4b1e Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..68c2ecd0 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..8f0f4c30 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/admin.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/apps.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/apps.py new file mode 100644 index 00000000..50878e76 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class DashboardConfig(AppConfig): + name = 'dashboard' diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/0001_initial.py new file mode 100644 index 00000000..006bb7ec --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 2.0.7 on 2018-07-24 15:29 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('login', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Job', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255)), + ('desc', models.TextField()), + ('location', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='jobs', to='login.User')), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/0002_job_user_jobs.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/0002_job_user_jobs.py new file mode 100644 index 00000000..d9f75665 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/0002_job_user_jobs.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.7 on 2018-07-24 16:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('login', '0001_initial'), + ('dashboard', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='job', + name='user_jobs', + field=models.ManyToManyField(related_name='jobs_for_user', to='login.User'), + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..c6a10552 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/0002_job_user_jobs.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/0002_job_user_jobs.cpython-37.pyc new file mode 100644 index 00000000..f2c904b3 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/0002_job_user_jobs.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..d4f61bef Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/models.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/models.py new file mode 100644 index 00000000..af6b41b0 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/models.py @@ -0,0 +1,34 @@ +from __future__ import unicode_literals +from django.db import models + +class JobManager(models.Manager): + def job_validation(self, postData): + errors = {} + if len(postData['title']) < 1: + errors['title'] = "You must input a title!" + + elif len(postData['title']) < 4: + errors['title'] = "Title must be at least four characters!" + + if len(postData['desc']) < 1: + errors['desc'] = "You must input a description!" + + elif len(postData['desc']) < 11: + errors['desc'] = "Description must be at least ten characters!" + + if len(postData['location']) < 1: + errors['location'] = "You must input a location!" + + return errors + +class Job(models.Model): + title = models.CharField(max_length = 255) + desc = models.TextField() + location = models.CharField(max_length = 255) + user = models.ForeignKey('login.User', related_name = 'jobs', on_delete = models.CASCADE) + user_jobs = models.ManyToManyField('login.User', related_name = 'jobs_for_user') + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = JobManager() + def __repr__(self): + return "".format(self.title, self.desc, self.location) diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/templates/handy_helper_exam/dash.html b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/templates/handy_helper_exam/dash.html new file mode 100644 index 00000000..ddcebb83 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/templates/handy_helper_exam/dash.html @@ -0,0 +1,67 @@ + + + + + Welcome + + + + + +
+
+ + + + + + + + + + + {% for job in jobs%} + {% if job not in added_jobs %} + + + + + {% if user.id == job.user.id %} + + {% endif %} + + {% endif %} + {% endfor %} + +
JobLocationAction
{{job.title}}{{job.location}} View Add Edit Cancel
+ + + + + + + {% for job in added_jobs %} + + + {% endfor %} + +
My Jobs + Action +
{{job.title}} + View Done +
+
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/tests.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/urls.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/urls.py new file mode 100644 index 00000000..63e59fcf --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index), + path('logout/', views.logout), + path('destroy//', views.destroy), + path('add//', views.add), +] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/views.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/views.py new file mode 100644 index 00000000..e9dc8be7 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/dashboard/views.py @@ -0,0 +1,28 @@ +from django.shortcuts import render, HttpResponse, redirect +from ..login.models import * +from .models import * + +def index(request): + context = { + 'user': User.objects.get(email=request.session['email']), + 'jobs': Job.objects.all(), + 'added_jobs': Job.objects.filter(user_jobs=User.objects.get(email=request.session['email'])), + } + + return render(request, 'handy_helper_exam/dash.html', context) + +def logout(request): + del request.session['email'] + request.session['logged_in'] = False + return redirect('/') + +def destroy(request, id): + job = Job.objects.get(id=int(id)) + job.delete() + return redirect('/dashboard') + +def add(request, id): + this_user = User.objects.get(email=request.session['email']) + this_job = Job.objects.get(id=int(id)) + this_job.user_jobs.add(this_user) + return redirect('/dashboard') diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..0452aa81 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..97865bcb Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..23d490e1 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..3d5d7071 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..5fa0eb31 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/admin.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/apps.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/apps.py new file mode 100644 index 00000000..9cf0b81c --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class EditConfig(AppConfig): + name = 'edit' diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..6c45b8ed Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/models.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/templates/handy_helper_exam/edit.html b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/templates/handy_helper_exam/edit.html new file mode 100644 index 00000000..06be4071 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/templates/handy_helper_exam/edit.html @@ -0,0 +1,43 @@ + + + + + Edit + + + + + + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+ +
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/tests.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/urls.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/urls.py new file mode 100644 index 00000000..fef17030 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('/', views.editpage), + path('/update/', views.update), +] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/views.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/views.py new file mode 100644 index 00000000..53b3ff28 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/edit/views.py @@ -0,0 +1,28 @@ +from django.shortcuts import render, HttpResponse, redirect +from ..dashboard.models import * + +def editpage(request, id): + context = { + "job": Job.objects.get(id=int(id)) + } + + return render(request, 'handy_helper_exam/edit.html', context) + +def update(request, id): + errors = Job.objects.job_validation(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/edit/'+id+'/') + + else: + edit_job = Job.objects.get(id=int(id)) + edit_job.title = request.POST['title'] + edit_job.desc = request.POST['desc'] + edit_job.location = request.POST['location'] + edit_job.save() + return redirect('/dashboard') + + return redirect('/edit/'+id+'/') diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..e5ed763a Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..fbbce87a Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..a3701521 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..c79b5064 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..b8318878 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/admin.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/apps.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/apps.py new file mode 100644 index 00000000..be1c1733 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class LoginConfig(AppConfig): + name = 'login' diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/0001_initial.py new file mode 100644 index 00000000..acf36ed0 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 2.0.7 on 2018-07-24 15:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('password', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..768f7826 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..4c224cda Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/models.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/models.py new file mode 100644 index 00000000..7e6f923a --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/models.py @@ -0,0 +1,77 @@ +from __future__ import unicode_literals +from django.db import models +import re +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') + +class UserManager(models.Manager): + def registration_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + if len(postData['first_name']) < 1: + errors['first_name'] = "You must input a first name!" + + elif len(postData['first_name']) < 2: + errors['first_name'] = "First name must be more than two characters!" + + elif not postData['first_name'].isalpha(): + errors['first_name'] = "Please use letters for your name only" + + if len(postData['last_name']) < 1: + errors['last_name'] = "You must input a last name!" + + elif len(postData['last_name']) < 2: + errors['last_name'] = "Last name must be more than two characters!" + + elif not postData['last_name'].isalpha(): + errors['last_name'] = "Please use letters for your name only" + + if len(postData['email']) < 1: + errors['email'] = "Please input an email address!" + + elif len(result) != 0: + errors['email'] = "This email has already been taken!!!!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + if len(postData['password']) < 1: + errors['password'] = "Please input a password!" + + elif len(postData['password']) < 8: + errors['password'] = "Password must be at least 8 characters long!" + + if len(postData['pass_confirm']) < 1: + errors['pass_confirm'] = "Please confirm your password!" + + elif postData['password'] != postData['pass_confirm']: + errors['pass_confirm'] = "Passwords must match!" + + return errors + + def login_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + if len(postData['email']) < 1: + errors['email'] = "Please input your email address!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + elif len(result) == 0: + errors['email'] = "Login failed" + + if len(postData['passlog']) < 1: + errors['passlog'] = "Please input a password!" + + return errors + +class User(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + email = models.CharField(max_length = 255) + password = models.CharField(max_length = 255) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = UserManager() + def __repr__(self): + return "".format(self.first_name, self.last_name, self.email, self.password) diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/templates/handy_helper_exam/index.html b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/templates/handy_helper_exam/index.html new file mode 100644 index 00000000..68156e14 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/templates/handy_helper_exam/index.html @@ -0,0 +1,68 @@ + + + + + Login And Register + + + + + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+
+
+ {% csrf_token %} +

Login:

+
+
+ + +
+
+ + +
+
+ +
+
+ {% csrf_token %} +

Registration:

+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/tests.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/urls.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/urls.py new file mode 100644 index 00000000..2168e171 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/urls.py @@ -0,0 +1,8 @@ +from django.urls import path, include +from . import views + +urlpatterns = [ + path('', views.index), + path('register/', views.register), + path('verify/', views.verify), +] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/views.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/views.py new file mode 100644 index 00000000..dc9ed2ac --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/login/views.py @@ -0,0 +1,50 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.contrib import messages +from .models import * +import bcrypt + +def index(request): + if 'logged_in' not in request.session: + request.session['logged_in'] = False + + return render(request, 'handy_helper_exam/index.html') + +def register(request): + errors = User.objects.registration_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + else: + pw_hash = bcrypt.hashpw(request.POST['password'].encode(), bcrypt.gensalt()).decode() + User.objects.create(first_name=request.POST['first_name'], last_name=request.POST['last_name'], email=request.POST['email'], password=pw_hash) + request.session['email'] = request.POST['email'] + request.session['logged_in'] = True + return redirect('/dashboard') + + return redirect('/') + +def verify(request): + errors = User.objects.login_validator(request.POST) + user = User.objects.filter(email=request.POST['email']) + + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + elif not bcrypt.checkpw(request.POST['passlog'].encode(), user[0].password.encode()): + messages.error(request, "Login failed") + return redirect('/') + + else: + request.session['email'] = request.POST['email'] + request.session['logged_in'] = True + return redirect('/dashboard') + + return redirect('/') diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..396d1475 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..c127cad0 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..d72f21b9 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..bef1aca2 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..caecad85 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/admin.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/apps.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/apps.py new file mode 100644 index 00000000..a17c9940 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ViewConfig(AppConfig): + name = 'view' diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..5d691c40 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/models.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/templates/handy_helper_exam/display.html b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/templates/handy_helper_exam/display.html new file mode 100644 index 00000000..e7bfa902 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/templates/handy_helper_exam/display.html @@ -0,0 +1,29 @@ + + + + + User's Quotes + + + + + +
+

{{job.title}}

+
+

{{job.desc}}

+

{{job.location}}

+

Posted by: {{job.user.first_name}} {{job.user.last_name}}

+

Posted on: {{job.created_at}}

+
+ Add To My Jobs +
+ + diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/tests.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/urls.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/urls.py new file mode 100644 index 00000000..0b0c85fc --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('/', views.display), +] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/views.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/views.py new file mode 100644 index 00000000..bc42fda9 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/apps/view/views.py @@ -0,0 +1,10 @@ +from django.shortcuts import render, HttpResponse, redirect +from ..login.models import * +from ..dashboard.models import * + +def display(request, id): + context = { + 'job': Job.objects.get(id=int(id)) + } + + return render(request, 'handy_helper_exam/display.html', context) diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/db.sqlite3 b/prajesh_gohel/Python/django_ORM/handy_helper_exam/db.sqlite3 new file mode 100644 index 00000000..fff35f1a Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/db.sqlite3 differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__init__.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..afbd7e2d Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/settings.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/settings.cpython-37.pyc new file mode 100644 index 00000000..7e577c4d Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/settings.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..0061e6df Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/wsgi.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 00000000..a34b6271 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/__pycache__/wsgi.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/settings.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/settings.py new file mode 100644 index 00000000..67f68628 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for handy_helper_exam project. + +Generated by 'django-admin startproject' using Django 2.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '3$5hp)d!1l5g6-8e2n_-gzx*9be)4g6@d%vonmaka=^bwep+@x' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.login', + 'apps.dashboard', + 'apps.addJob', + 'apps.view', + 'apps.edit', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'handy_helper_exam.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'handy_helper_exam.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/urls.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/urls.py new file mode 100644 index 00000000..f9193ccc --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/urls.py @@ -0,0 +1,24 @@ +"""handy_helper_exam URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.urls import path, include + +urlpatterns = [ + path('', include('apps.login.urls')), + path('dashboard/', include('apps.dashboard.urls')), + path('addJob/', include('apps.addJob.urls')), + path('view/', include('apps.view.urls')), + path('edit/', include('apps.edit.urls')), +] diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/wsgi.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/wsgi.py new file mode 100644 index 00000000..13234f71 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/handy_helper_exam/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for handy_helper_exam project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "handy_helper_exam.settings") + +application = get_wsgi_application() diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/manage.py b/prajesh_gohel/Python/django_ORM/handy_helper_exam/manage.py new file mode 100755 index 00000000..2b7f4f9e --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "handy_helper_exam.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/prajesh_gohel/Python/django_ORM/handy_helper_exam/requirements.txt b/prajesh_gohel/Python/django_ORM/handy_helper_exam/requirements.txt new file mode 100644 index 00000000..ce31c57e --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/handy_helper_exam/requirements.txt @@ -0,0 +1,21 @@ +appnope==0.1.0 +backcall==0.1.0 +bcrypt==3.1.4 +cffi==1.11.5 +decorator==4.3.0 +Django==2.0.7 +ipython==6.4.0 +ipython-genutils==0.2.0 +jedi==0.12.1 +parso==0.3.1 +pexpect==4.6.0 +pickleshare==0.7.4 +prompt-toolkit==1.0.15 +ptyprocess==0.6.0 +pycparser==2.18 +Pygments==2.2.0 +pytz==2018.5 +simplegeneric==0.8.1 +six==1.11.0 +traitlets==4.3.2 +wcwidth==0.1.7 diff --git a/prajesh_gohel/Python/django_ORM/like_books.txt b/prajesh_gohel/Python/django_ORM/like_books.txt new file mode 100644 index 00000000..a4c63fb5 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/like_books.txt @@ -0,0 +1,16 @@ +1. Have the all the users create/upload 2 books. + + In [18]: Book.objects.create(name="12 Rules of Life", desc="byebye", uploader=Us + ...: er.objects.get(id=3)) + + rinse and repeat + +2. Have the users like the books. + + In [23]: User.objects.get(id=1).liked_books.add(Book.objects.last()) + + rinse and repeat + +3. Display all users who uploaded/liked the books. + + In [43]: Book.objects.get(id=3).liked_users.all() diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/__init__.py b/prajesh_gohel/Python/django_ORM/login_register/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/apps/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..faeb5974 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/apps/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__init__.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..9d7db05e Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..3efc2885 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..f23e4692 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..cb3b2c80 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..bb338174 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/admin.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/apps.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/apps.py new file mode 100644 index 00000000..21c0f4b6 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class LoginRegisterAppConfig(AppConfig): + name = 'login_register_app' diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/0001_initial.py new file mode 100644 index 00000000..e4f4ef93 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 2.0.7 on 2018-07-18 22:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('password', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..38e687f0 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..0ac9bec3 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/models.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/models.py new file mode 100644 index 00000000..cf77a459 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/models.py @@ -0,0 +1,77 @@ +from __future__ import unicode_literals +from django.db import models +import re +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') + +class UserManager(models.Manager): + def registration_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + if len(postData['first_name']) < 1: + errors['first_name'] = "You must input a first name!" + + elif len(postData['first_name']) < 2: + errors['first_name'] = "First name must be more than two characters!" + + elif not postData['first_name'].isalpha(): + errors['first_name'] = "Please use letters for your name only" + + if len(postData['last_name']) < 1: + errors['last_name'] = "You must input a last name!" + + elif len(postData['last_name']) < 2: + errors['last_name'] = "Last name must be more than two characters!" + + elif not postData['last_name'].isalpha(): + errors['last_name'] = "Please use letters for your name only" + + if len(postData['email']) < 1: + errors['email'] = "Please input an email address!" + + elif len(result) != 0: + errors['email'] = "This email has already been taken!!!!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + if len(postData['password']) < 1: + errors['password'] = "Please input a password!" + + elif len(postData['password']) < 8: + errors['password'] = "Password must be at least 8 characters long!" + + if len(postData['pass_confirm']) < 1: + errors['pass_confirm'] = "Please confirm your password!" + + elif postData['password'] != postData['pass_confirm']: + errors['pass_confirm'] = "Passwords must match!" + + return errors + + def login_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + if len(postData['email']) < 1: + errors['email'] = "Please input your email address!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + elif len(result) == 0: + errors['email'] = "Login failed" + + if len(postData['passlog']) < 1: + errors['passlog'] = "Please input a password!" + + return errors + +class User(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + email = models.CharField(max_length = 255) + password = models.CharField(max_length = 255) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = UserManager() + def __repr__(self): + return "User object: {} {} {} {}".format(self.first_name, self.last_name, self.email, self.password) diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/templates/login_register/index.html b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/templates/login_register/index.html new file mode 100644 index 00000000..68156e14 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/templates/login_register/index.html @@ -0,0 +1,68 @@ + + + + + Login And Register + + + + + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+
+
+ {% csrf_token %} +

Login:

+
+
+ + +
+
+ + +
+
+ +
+
+ {% csrf_token %} +

Registration:

+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/templates/login_register/success.html b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/templates/login_register/success.html new file mode 100644 index 00000000..2e5a0d16 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/templates/login_register/success.html @@ -0,0 +1,16 @@ + + + + + Welcome + + + +
+
+

You have been logged in, {{request.session.first_name}}

+
+ Logout +
+ + diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/tests.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/urls.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/urls.py new file mode 100644 index 00000000..bc652c30 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index), + path('register/', views.register), + path('verify/', views.verify), + path('success/', views.success), + path('log_out/', views.log_out), +] diff --git a/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/views.py b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/views.py new file mode 100644 index 00000000..c7241d12 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/apps/login_register_app/views.py @@ -0,0 +1,64 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.contrib import messages +from .models import * +import bcrypt + +def index(request): + if 'logged_in' not in request.session: + request.session['logged_in'] = False + + return render(request, 'login_register/index.html') + +def register(request): + errors = User.objects.registration_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + else: + pw_hash = bcrypt.hashpw(request.POST['password'].encode(), bcrypt.gensalt()).decode() + User.objects.create(first_name=request.POST['first_name'], last_name=request.POST['last_name'], email=request.POST['email'], password=pw_hash) + request.session['email'] = request.POST['email'] + request.session['logged_in'] = True + return redirect('/success') + + return redirect('/') + +def verify(request): + errors = User.objects.login_validator(request.POST) + try: + user = User.objects.get(email=request.POST['email']) + + except: + messages.error(request, "Login Failed") + return redirect('/') + + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + elif not bcrypt.checkpw(request.POST['passlog'].encode(), user[0].password.encode()): + messages.error(request, "Login failed") + return redirect('/') + + else: + request.session['email'] = request.POST['email'] + request.session['logged_in'] = True + return redirect('/success') + +def success(request): + if 'first_name' not in request.session: + return redirect('/') + + return render(request, 'login_register/success.html') + +def log_out(request): + del request.session['email'] + request.session['logged_in'] = False + return redirect('/') diff --git a/prajesh_gohel/Python/django_ORM/login_register/db.sqlite3 b/prajesh_gohel/Python/django_ORM/login_register/db.sqlite3 new file mode 100644 index 00000000..e431eec8 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/db.sqlite3 differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/login_register/__init__.py b/prajesh_gohel/Python/django_ORM/login_register/login_register/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..c7ce85f4 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/settings.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/settings.cpython-37.pyc new file mode 100644 index 00000000..a7f0c9bc Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/settings.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..7ba9463f Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/wsgi.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 00000000..ca848630 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/login_register/login_register/__pycache__/wsgi.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/login_register/login_register/settings.py b/prajesh_gohel/Python/django_ORM/login_register/login_register/settings.py new file mode 100644 index 00000000..6fdf423f --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/login_register/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for login_register project. + +Generated by 'django-admin startproject' using Django 2.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '-)e)gg1zfv4(d8mlp=i0o#0jd_!e^vinv181yvs=qe@-gz4$i5' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.login_register_app', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'login_register.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'login_register.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/prajesh_gohel/Python/django_ORM/login_register/login_register/urls.py b/prajesh_gohel/Python/django_ORM/login_register/login_register/urls.py new file mode 100644 index 00000000..1cc01ed5 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/login_register/urls.py @@ -0,0 +1,20 @@ +"""login_register URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.urls import path, include + +urlpatterns = [ + path('', include('apps.login_register_app.urls')), +] diff --git a/prajesh_gohel/Python/django_ORM/login_register/login_register/wsgi.py b/prajesh_gohel/Python/django_ORM/login_register/login_register/wsgi.py new file mode 100644 index 00000000..9284c442 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/login_register/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for login_register project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "login_register.settings") + +application = get_wsgi_application() diff --git a/prajesh_gohel/Python/django_ORM/login_register/manage.py b/prajesh_gohel/Python/django_ORM/login_register/manage.py new file mode 100755 index 00000000..06ee3162 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/login_register/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "login_register.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/__init__.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..5cf63b2d Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__init__.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..3a5bc5b7 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..8d7c264b Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/apps.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/apps.cpython-37.pyc new file mode 100644 index 00000000..a68fc8c8 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/apps.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..5b9b0ac3 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..63e14462 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..b3d25914 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/admin.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/apps.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/apps.py new file mode 100644 index 00000000..1ca6df11 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class QuotesConfig(AppConfig): + name = 'quotes' diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0001_initial.py new file mode 100644 index 00000000..4f3049cd --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 2.0.7 on 2018-07-20 14:57 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('users', '0002_auto_20180720_1438'), + ] + + operations = [ + migrations.CreateModel( + name='Quote', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quote', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quotes', to='users.User')), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0002_quote_author.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0002_quote_author.py new file mode 100644 index 00000000..7feceea2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0002_quote_author.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.7 on 2018-07-20 16:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quotes', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='quote', + name='author', + field=models.CharField(default='null', max_length=255), + preserve_default=False, + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0003_like.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0003_like.py new file mode 100644 index 00000000..eba6b102 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0003_like.py @@ -0,0 +1,26 @@ +# Generated by Django 2.0.7 on 2018-07-20 18:04 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0002_auto_20180720_1438'), + ('quotes', '0002_quote_author'), + ] + + operations = [ + migrations.CreateModel( + name='Like', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('likes', models.IntegerField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('quote_likes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='likes_for_quote', to='quotes.Quote')), + ('user_likes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='likes_from_user', to='users.User')), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0004_auto_20180720_1824.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0004_auto_20180720_1824.py new file mode 100644 index 00000000..3ab2f1ba --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0004_auto_20180720_1824.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.7 on 2018-07-20 18:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quotes', '0003_like'), + ] + + operations = [ + migrations.AlterField( + model_name='like', + name='likes', + field=models.CharField(max_length=255), + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0005_auto_20180720_1827.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0005_auto_20180720_1827.py new file mode 100644 index 00000000..8875ff2c --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0005_auto_20180720_1827.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.7 on 2018-07-20 18:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quotes', '0004_auto_20180720_1824'), + ] + + operations = [ + migrations.AlterField( + model_name='like', + name='likes', + field=models.IntegerField(), + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0006_auto_20180720_1849.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0006_auto_20180720_1849.py new file mode 100644 index 00000000..9e5f51e0 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/0006_auto_20180720_1849.py @@ -0,0 +1,30 @@ +# Generated by Django 2.0.7 on 2018-07-20 18:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0002_auto_20180720_1438'), + ('quotes', '0005_auto_20180720_1827'), + ] + + operations = [ + migrations.RemoveField( + model_name='like', + name='quote_likes', + ), + migrations.RemoveField( + model_name='like', + name='user_likes', + ), + migrations.AddField( + model_name='quote', + name='user_likes', + field=models.ManyToManyField(related_name='quote_likes', to='users.User'), + ), + migrations.DeleteModel( + name='Like', + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..e20bf4f9 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0002_quote_author.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0002_quote_author.cpython-37.pyc new file mode 100644 index 00000000..2b28f6a9 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0002_quote_author.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0003_like.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0003_like.cpython-37.pyc new file mode 100644 index 00000000..d7a923b8 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0003_like.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0004_auto_20180720_1824.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0004_auto_20180720_1824.cpython-37.pyc new file mode 100644 index 00000000..8c7db6c7 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0004_auto_20180720_1824.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0005_auto_20180720_1827.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0005_auto_20180720_1827.cpython-37.pyc new file mode 100644 index 00000000..c03feadf Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0005_auto_20180720_1827.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0006_auto_20180720_1849.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0006_auto_20180720_1849.cpython-37.pyc new file mode 100644 index 00000000..5ae0f158 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/0006_auto_20180720_1849.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..0036678d Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/models.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/models.py new file mode 100644 index 00000000..983de862 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/models.py @@ -0,0 +1,24 @@ +from __future__ import unicode_literals +from django.db import models + +class QuoteManager(models.Manager): + def simple_validator(self, postData): + errors = {} + if len(postData['author']) < 1: + errors['author'] = "Please input an author!" + + if len(postData['quote']) < 1: + errors['quote'] = "You must input a quote, silly!" + + return errors + +class Quote(models.Model): + author = models.CharField(max_length = 255) + quote = models.TextField() + user = models.ForeignKey('users.User', related_name = "quotes", on_delete = models.CASCADE) + user_likes = models.ManyToManyField('users.User', related_name = "quote_likes") + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = QuoteManager() + def __repr__(self): + return "".format(self.quote) diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/templates/quote_dash_exam/main_page.html b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/templates/quote_dash_exam/main_page.html new file mode 100644 index 00000000..36dc5afa --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/templates/quote_dash_exam/main_page.html @@ -0,0 +1,61 @@ + + + + + Quotes + + + + + +
+ {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+
+

All Quotes:

+ {% for quote in quotes %} +
+

"{{quote.quote}}"

+

- {{quote.author}}

+

Posted by {{quote.user.first_name}} {{quote.user.last_name}}

+
+ + + + +
+ {% if user.id == quote.user_id%} + Delete + {% endif %} +
+ {% endfor %} +
+
+ {% csrf_token %} +

Post a quote:

+
+ + +
+
+

Quote:

+ +
+ +
+
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/tests.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/urls.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/urls.py new file mode 100644 index 00000000..9a22fd7a --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.main), + path('post/', views.post), + path('destroy//', views.destroy), + path('log_out/', views.log_out), +] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/views.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/views.py new file mode 100644 index 00000000..edba359e --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/quotes/views.py @@ -0,0 +1,41 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.contrib import messages +from .models import * +from ..users.models import * +import bcrypt + +def main(request): + if request.session['logged_in'] == False: + return redirect('/') + + context = { + 'user': User.objects.get(email = request.session['email']), + 'quotes': Quote.objects.all().order_by('-created_at'), + } + + return render(request, 'quote_dash_exam/main_page.html', context) + +def post(request): + errors = Quote.objects.simple_validator(request.POST) + + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/quotes') + + Quote.objects.create(author = request.POST['author'], quote = request.POST['quote'], user = User.objects.get(email = request.session['email'])) + return redirect('/quotes') + + return redirect('/quotes') + +def destroy(request, id): + delete = Quote.objects.get(id = int(id)) + delete.delete() + return redirect('/quotes') + +def log_out(request): + del request.session['email'] + request.session['logged_in'] = False + return redirect('/') diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__init__.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..d63f88a9 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..7b6ca614 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..b88c058c Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..dea269aa Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..43821115 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/admin.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/apps.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/apps.py new file mode 100644 index 00000000..4ce1fabc --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + name = 'users' diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/0001_initial.py new file mode 100644 index 00000000..6c9b3d56 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/0001_initial.py @@ -0,0 +1,41 @@ +# Generated by Django 2.0.7 on 2018-07-20 14:37 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Quote', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quote', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('password', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.AddField( + model_name='quote', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quotes', to='users.User'), + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/0002_auto_20180720_1438.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/0002_auto_20180720_1438.py new file mode 100644 index 00000000..6ed8616d --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/0002_auto_20180720_1438.py @@ -0,0 +1,20 @@ +# Generated by Django 2.0.7 on 2018-07-20 14:38 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='quote', + name='user', + ), + migrations.DeleteModel( + name='Quote', + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..1d921d86 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/0002_auto_20180720_1438.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/0002_auto_20180720_1438.cpython-37.pyc new file mode 100644 index 00000000..0c9ab913 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/0002_auto_20180720_1438.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..51ddae84 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/models.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/models.py new file mode 100644 index 00000000..30fb54bb --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/models.py @@ -0,0 +1,106 @@ +from __future__ import unicode_literals +from django.db import models +import re + +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') + +class UserManager(models.Manager): + def registration_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + if len(postData['first_name']) < 1: + errors['first_name'] = "You must input a first name!" + + elif len(postData['first_name']) < 2: + errors['first_name'] = "First name must be more than two characters!" + + elif not postData['first_name'].isalpha(): + errors['first_name'] = "Please use letters for your name only" + + if len(postData['last_name']) < 1: + errors['last_name'] = "You must input a last name!" + + elif len(postData['last_name']) < 2: + errors['last_name'] = "Last name must be more than two characters!" + + elif not postData['last_name'].isalpha(): + errors['last_name'] = "Please use letters for your name only" + + if len(postData['email']) < 1: + errors['email'] = "Please input an email address!" + + elif len(result) != 0: + errors['email'] = "This email has already been taken!!!!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + if len(postData['password']) < 1: + errors['password'] = "Please input a password!" + + elif len(postData['password']) < 8: + errors['password'] = "Password must be at least 8 characters long!" + + if len(postData['pass_confirm']) < 1: + errors['pass_confirm'] = "Please confirm your password!" + + elif postData['password'] != postData['pass_confirm']: + errors['pass_confirm'] = "Passwords must match!" + + return errors + + def login_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + if len(postData['email']) < 1: + errors['email'] = "Please input your email address!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + elif len(result) == 0: + errors['email'] = "Login failed" + + if len(postData['passlog']) < 1: + errors['passlog'] = "Please input a password!" + + return errors + + def update_validator(self, postData): + errors = {} + if len(postData['first_name']) < 1: + errors['first_name'] = "You must input a first name!" + + elif len(postData['first_name']) < 2: + errors['first_name'] = "First name must be more than two characters!" + + elif not postData['first_name'].isalpha(): + errors['first_name'] = "Please use letters for your name only" + + if len(postData['last_name']) < 1: + errors['last_name'] = "You must input a last name!" + + elif len(postData['last_name']) < 2: + errors['last_name'] = "Last name must be more than two characters!" + + elif not postData['last_name'].isalpha(): + errors['last_name'] = "Please use letters for your name only" + + if len(postData['email']) < 1: + errors['email'] = "Please input an email address!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + return errors + +class User(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + email = models.CharField(max_length = 255) + password = models.CharField(max_length = 255) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = UserManager() + def __repr__(self): + return "".format(self.first_name, self.last_name, self.email, self.password) diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/display.html b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/display.html new file mode 100644 index 00000000..cfe78e5e --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/display.html @@ -0,0 +1,28 @@ + + + + + User's Quotes + + + + + +
+ {% for i in user_quotes %} +
+

"{{i.quote}}"

+

- {{i.author}}

+
+ {% endfor %} +
+ + diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/edit.html b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/edit.html new file mode 100644 index 00000000..8825fc2d --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/edit.html @@ -0,0 +1,43 @@ + + + + + Edit + + + + + + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+ +
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/index.html b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/index.html new file mode 100644 index 00000000..68156e14 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/templates/quote_dash_exam/index.html @@ -0,0 +1,68 @@ + + + + + Login And Register + + + + + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+
+
+ {% csrf_token %} +

Login:

+
+
+ + +
+
+ + +
+
+ +
+
+ {% csrf_token %} +

Registration:

+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/tests.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/urls.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/urls.py new file mode 100644 index 00000000..dabc2331 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index), + path('register/', views.register), + path('verify/', views.verify), + path('user//', views.display), + path('myaccount//', views.edit), + path('myaccount//update/', views.update), +] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/views.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/views.py new file mode 100644 index 00000000..231006c7 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/apps/users/views.py @@ -0,0 +1,85 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.contrib import messages +from .models import * +from ..quotes.models import * +import bcrypt + +def index(request): + if 'logged_in' not in request.session: + request.session['logged_in'] = False + return render(request, 'quote_dash_exam/index.html') + +def register(request): + errors = User.objects.registration_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + else: + pw_hash = bcrypt.hashpw(request.POST['password'].encode(), bcrypt.gensalt()).decode() + User.objects.create(first_name=request.POST['first_name'], last_name=request.POST['last_name'], email=request.POST['email'], password=pw_hash) + request.session['email'] = request.POST['email'] + request.session['logged_in'] = True + return redirect('/quotes') + + return redirect('/') + +def verify(request): + errors = User.objects.login_validator(request.POST) + user = User.objects.filter(email=request.POST['email']) + + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + elif not bcrypt.checkpw(request.POST['passlog'].encode(), user[0].password.encode()): + messages.error(request, "Login failed") + return redirect('/') + + else: + request.session['email'] = request.POST['email'] + request.session['logged_in'] = True + return redirect('/quotes') + + return redirect('/') + +def display(request, id): + context = { + 'user': User.objects.get(id = int(id)), + 'user_quotes': Quote.objects.filter(user_id = int(id)), + } + + return render(request, 'quote_dash_exam/display.html', context) + +def edit(request, id): + context = { + "user": User.objects.get(email = request.session['email']) + } + + return render(request, 'quote_dash_exam/edit.html', context) + +def update(request, id): + errors = User.objects.update_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/myaccount/'+id+'/') + + else: + edit_user = User.objects.get(id=int(id)) + edit_user.first_name = request.POST['first_name'] + edit_user.last_name = request.POST['last_name'] + edit_user.email = request.POST['email'] + edit_user.save() + request.session['email'] = request.POST['email'] + return redirect('/quotes') + + return redirect('/myaccount/'+id+'/') diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/db.sqlite3 b/prajesh_gohel/Python/django_ORM/quote_dash_exam/db.sqlite3 new file mode 100644 index 00000000..e7ce8c12 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/db.sqlite3 differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/manage.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/manage.py new file mode 100755 index 00000000..66650772 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "quote_dash_exam.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__init__.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..a751daf4 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/settings.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/settings.cpython-37.pyc new file mode 100644 index 00000000..7f2ecc7d Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/settings.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..d538472f Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/wsgi.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 00000000..1015f2e9 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/__pycache__/wsgi.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/settings.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/settings.py new file mode 100644 index 00000000..29df5848 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/settings.py @@ -0,0 +1,122 @@ +""" +Django settings for quote_dash_exam project. + +Generated by 'django-admin startproject' using Django 2.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'nr*ccw4_dwer5r^&x12%4&(!_jlowh&g4cvzw_da)%1j&n7eh=' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.quotes', + 'apps.users', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'quote_dash_exam.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'quote_dash_exam.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/urls.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/urls.py new file mode 100644 index 00000000..a811febb --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/urls.py @@ -0,0 +1,21 @@ +"""quote_dash_exam URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.urls import path, include + +urlpatterns = [ + path('', include('apps.users.urls')), + path('quotes/', include('apps.quotes.urls')), +] diff --git a/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/wsgi.py b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/wsgi.py new file mode 100644 index 00000000..59523f71 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/quote_dash_exam/quote_dash_exam/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for quote_dash_exam project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "quote_dash_exam.settings") + +application = get_wsgi_application() diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/__init__.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..74a89a02 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__init__.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..0f41fb1a Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..73bb7ae3 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..d7be5076 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..39776cb7 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..2ab64eb0 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/admin.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/apps.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/apps.py new file mode 100644 index 00000000..4ce1fabc --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + name = 'users' diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/0001_initial.py new file mode 100644 index 00000000..0b07324c --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 2.0.7 on 2018-07-17 22:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..45a59fe1 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..41b9dde5 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/models.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/models.py new file mode 100644 index 00000000..3d25cdc0 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/models.py @@ -0,0 +1,54 @@ +from __future__ import unicode_literals +from django.db import models +import re +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') + +class UserManager(models.Manager): + def basic_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + if len(postData['first_name']) < 1: + errors['first_name'] = "You must input a first name!" + + elif not postData['first_name'].isalpha(): + errors['first_name'] = "Please use letters for your name only" + + if len(postData['last_name']) < 1: + errors['last_name'] = "You must input a last name!" + + elif not postData['last_name'].isalpha(): + errors['last_name'] = "Please use letters for your name only" + + if len(postData['email']) < 1: + errors['email'] = "Please input an email address!" + + elif len(result) != 0: + errors['email'] = "This email has already been taken!!!!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + return errors + + def edit_validator(self, postData): + errors = {} + if not postData['first_name'].isalpha(): + errors['first_name'] = "Please use letters for your name only" + + if not postData['last_name'].isalpha(): + errors['last_name'] = "Please use letters for your name only" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + return errors + +class User(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + email = models.CharField(max_length = 255) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = UserManager() + def __repr__(self): + return "".format(self.first_name, self.last_name, self.email) diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/display.html b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/display.html new file mode 100644 index 00000000..3d10cf91 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/display.html @@ -0,0 +1,21 @@ + + + + + Profile + + + +
+

User {{user.id}}

+

Full Name: {{user.first_name}} {{user.last_name}}

+

Email: {{user.email}}

+

Created At: {{user.created_at}}

+
+ Edit + Delete + Back +
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/edit.html b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/edit.html new file mode 100644 index 00000000..7d42475c --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/edit.html @@ -0,0 +1,35 @@ + + + + + Edit + + + +
+ {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+ {% csrf_token %} +

Edit User {{user.id}}

+
+ + +
+
+ + +
+
+ + +
+ +
+ Go Back +
+ + diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/index.html b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/index.html new file mode 100644 index 00000000..0a01b74a --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/index.html @@ -0,0 +1,38 @@ + + + + + List of Users + + + +
+

Users

+ + + + + + + + + + + + + {% for user in users %} + + + + + + + + + {% endfor %} + +
idFull NameEmailCreated AtUpdated AtActions
{{user.id}} {{user.first_name}} {{user.last_name}}{{user.email}}{{user.created_at}}{{user.updated_at}} Show Edit Delete
+ Add a new user +
+ + diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/new.html b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/new.html new file mode 100644 index 00000000..ade243c6 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/templates/semirestful_users/new.html @@ -0,0 +1,34 @@ + + + + + Create a User + + + +
+ {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+ {% csrf_token %} +

Add a new user

+
+ + +
+
+ + +
+
+ + +
+ +
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/tests.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/urls.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/urls.py new file mode 100644 index 00000000..257ef17d --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/urls.py @@ -0,0 +1,12 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index), + path('new/', views.new), + path('new/create/', views.create), + path('destroy/', views.delete), + path('/edit/', views.edit), + path('/', views.display), + path('/edit/update/', views.update), +] diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/views.py b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/views.py new file mode 100644 index 00000000..9b3e7666 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/apps/users/views.py @@ -0,0 +1,66 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.contrib import messages +from .models import * + +def index(request): + context = { + "users": User.objects.all() + } + + return render(request, 'semirestful_users/index.html', context) + +def new(request): + return render(request, 'semirestful_users/new.html') + +def create(request): + errors = User.objects.basic_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/new') + + else: + User.objects.create(first_name=request.POST['first_name'], last_name=request.POST['last_name'], email=request.POST['email']) + return redirect('/') + + return redirect('/new') + +def delete(request, id): + delete_user = User.objects.get(id=int(id)) + delete_user.delete() + return redirect('/') + +def display(request, id): + context = { + "user": User.objects.get(id=int(id)) + } + + return render(request, 'semirestful_users/display.html', context) + +def edit(request, id): + context = { + "user": User.objects.get(id=int(id)) + } + + return render(request, 'semirestful_users/edit.html', context) + +def update(request, id): + errors = User.objects.edit_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/'+id+'/edit') + + else: + edit_user = User.objects.get(id=int(id)) + edit_user.first_name = request.POST['first_name'] + edit_user.last_name = request.POST['last_name'] + edit_user.email = request.POST['email'] + edit_user.save() + return redirect('/') + + return redirect('/'+id+'/edit') diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/db.sqlite3 b/prajesh_gohel/Python/django_ORM/semirestful_users/db.sqlite3 new file mode 100644 index 00000000..5c7847bd Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/db.sqlite3 differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/manage.py b/prajesh_gohel/Python/django_ORM/semirestful_users/manage.py new file mode 100755 index 00000000..aeda35f8 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "semirestful_users.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__init__.py b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..941d19ec Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/settings.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/settings.cpython-37.pyc new file mode 100644 index 00000000..beb173ff Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/settings.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..93807dd4 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/wsgi.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 00000000..f1cbf921 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/__pycache__/wsgi.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/settings.py b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/settings.py new file mode 100644 index 00000000..b84171a0 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for semirestful_users project. + +Generated by 'django-admin startproject' using Django 2.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'un58rk4zt($wt%hd45qgkqr3p-8-*omsszhj1itcr40v6f%wy=' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.users', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'semirestful_users.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'semirestful_users.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/urls.py b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/urls.py new file mode 100644 index 00000000..f605e512 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/urls.py @@ -0,0 +1,20 @@ +"""semirestful_users URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.urls import path, include + +urlpatterns = [ + path('', include('apps.users.urls')), +] diff --git a/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/wsgi.py b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/wsgi.py new file mode 100644 index 00000000..d044da8e --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/semirestful_users/semirestful_users/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for semirestful_users project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "semirestful_users.settings") + +application = get_wsgi_application() diff --git a/prajesh_gohel/Python/django_ORM/users.txt b/prajesh_gohel/Python/django_ORM/users.txt new file mode 100644 index 00000000..f0f540d7 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/users.txt @@ -0,0 +1,37 @@ +1. Know how to retrieve all users. + + In [6]: User.objects.all() + Out[6]: , , ]> + +2. Know how to get the last user. + + In [7]: User.objects.last() + Out[7]: + +3. Create a few records in the users + + In [2]: User.objects.create(first_name="Prajesh", last_name="Gohel", email_addre + ...: ss="prajeshgohel@gmail.com", age=19) + +4. Know how to get the first user. + + In [9]: User.objects.first() + Out[9]: + +5. Get the record of the user whose id is 3 and UPDATE the person's last_name to something else. Know how to do this directly in the console using .get and .save. + + In [10]: a = User.objects.get(id=3) + In [12]: a.last_name = "BabyBoy" + In [14]: a.save() + +6. Know how to delete a record of a user whose id is 4 (use something like User.objects.get(id=2).delete...). + + In [15]: a = User.objects.get(id=2) + + In [16]: a.delete() + Out[16]: (1, {'users.User': 1}) + +7. Know how to get the users sorted by their first name (order by first_name DESC) + + In [4]: User.objects.order_by("first_name") + Out[4]: , ] diff --git a/prajesh_gohel/Python/django_ORM/wall.zip b/prajesh_gohel/Python/django_ORM/wall.zip new file mode 100644 index 00000000..de99d696 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall.zip differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/__init__.py b/prajesh_gohel/Python/django_ORM/wall/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..16f75e82 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__init__.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..e517011b Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/admin.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/admin.cpython-37.pyc new file mode 100644 index 00000000..7e09c472 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/admin.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/models.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/models.cpython-37.pyc new file mode 100644 index 00000000..2a7b5316 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/models.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..7487ccf8 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/views.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/views.cpython-37.pyc new file mode 100644 index 00000000..0b7374fc Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/__pycache__/views.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/admin.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/apps.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/apps.py new file mode 100644 index 00000000..4cb7ca7c --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class WallAppConfig(AppConfig): + name = 'wall_app' diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/0001_initial.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/0001_initial.py new file mode 100644 index 00000000..f65d2066 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# Generated by Django 2.0.7 on 2018-07-19 19:01 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Message', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('message', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('birthday', models.DateField()), + ('password', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.AddField( + model_name='message', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='wall_app.User'), + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/0002_comment.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/0002_comment.py new file mode 100644 index 00000000..01a83551 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/0002_comment.py @@ -0,0 +1,25 @@ +# Generated by Django 2.0.7 on 2018-07-20 03:23 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wall_app', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Comment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('comment', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('message_comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments_in_message', to='wall_app.Message')), + ('user_comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments_from_user', to='wall_app.User')), + ], + ), + ] diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__init__.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/0001_initial.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 00000000..53551429 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/0002_comment.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/0002_comment.cpython-37.pyc new file mode 100644 index 00000000..20aee159 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/0002_comment.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..0d81686e Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/models.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/models.py new file mode 100644 index 00000000..73c016e3 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/models.py @@ -0,0 +1,103 @@ +from __future__ import unicode_literals +from django.db import models +from datetime import date +import datetime +import re +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') + +class UserManager(models.Manager): + def registration_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + today = date.today() + born = datetime.datetime.strptime(postData['birthday'], "%Y-%m-%d") + age = today.year - born.year - ((today.month, today.day) < (born.month, born.day)) + if len(postData['first_name']) < 1: + errors['first_name'] = "You must input a first name!" + + elif len(postData['first_name']) < 2: + errors['first_name'] = "First name must be more than two characters!" + + elif not postData['first_name'].isalpha(): + errors['first_name'] = "Please use letters for your name only" + + if len(postData['last_name']) < 1: + errors['last_name'] = "You must input a last name!" + + elif len(postData['last_name']) < 2: + errors['last_name'] = "Last name must be more than two characters!" + + elif not postData['last_name'].isalpha(): + errors['last_name'] = "Please use letters for your name only" + + if age < 13: + errors['birthday'] = "You must be 13 years or older to register!" + + if len(postData['email']) < 1: + errors['email'] = "Please input an email address!" + + elif len(result) != 0: + errors['email'] = "This email has already been taken!!!!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + if len(postData['password']) < 1: + errors['password'] = "Please input a password!" + + elif len(postData['password']) < 8: + errors['password'] = "Password must be at least 8 characters long!" + + if len(postData['pass_confirm']) < 1: + errors['pass_confirm'] = "Please confirm your password!" + + elif postData['password'] != postData['pass_confirm']: + errors['pass_confirm'] = "Passwords must match!" + + return errors + + def login_validator(self, postData): + errors = {} + result = User.objects.filter(email=postData['email']) + if len(postData['email']) < 1: + errors['email'] = "Please input your email address!" + + elif not EMAIL_REGEX.match(postData['email']): + errors['email'] = "Needs a valid email address!" + + elif len(result) == 0: + errors['email'] = "Login failed" + + if len(postData['passlog']) < 1: + errors['passlog'] = "Please input a password!" + + return errors + +class User(models.Model): + first_name = models.CharField(max_length = 255) + last_name = models.CharField(max_length = 255) + email = models.CharField(max_length = 255) + birthday = models.DateField() + password = models.CharField(max_length = 255) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + objects = UserManager() + def __repr__(self): + return "".format(self.first_name, self.last_name, self.email, self.birthday) + +class Message(models.Model): + user = models.ForeignKey(User, related_name = "messages", on_delete = models.CASCADE) + message = models.TextField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __repr__(self): + return "".format(self.message) + +class Comment(models.Model): + comment = models.TextField() + user_comment = models.ForeignKey(User, related_name = "comments_from_user", on_delete = models.CASCADE) + message_comment = models.ForeignKey(Message, related_name = "comments_in_message", on_delete = models.CASCADE) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __repr__(self): + return "".format(self.comment) diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/templates/wall/index.html b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/templates/wall/index.html new file mode 100644 index 00000000..d11bdeae --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/templates/wall/index.html @@ -0,0 +1,74 @@ + + + + + Login And Register + + + + + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} +
+
+
+ {% csrf_token %} +

Login:

+
+
+ + +
+
+ + +
+
+ +
+
+ {% csrf_token %} +

Registration:

+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ +
+
+
+ + diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/templates/wall/wall.html b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/templates/wall/wall.html new file mode 100644 index 00000000..d5d6e00b --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/templates/wall/wall.html @@ -0,0 +1,50 @@ + + + + + Welcome + + + + + +
+
+ {% csrf_token %} +
+

Post a message

+ +
+ +
+ {% for message in messages %} +
{{message.user.first_name}} {{message.user.last_name}} - {{message.created_at}}
+

{{message.message}}

+
+ {% for comment in comments %} + {% if message.id == comment.message_comment_id %} +
{{comment.user_comment.first_name}} {{comment.user_comment.last_name}} - {{comment.created_at}}
+

{{comment.comment}}

+ {% endif %} + {% endfor %} +
+ {% csrf_token %} +
+

Post a comment

+ +
+ +
+
+ {% endfor %} +
+ + diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/tests.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/urls.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/urls.py new file mode 100644 index 00000000..bacb50a5 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/urls.py @@ -0,0 +1,12 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index), + path('register/', views.register), + path('verify/', views.verify), + path('wall/', views.wall), + path('wall/post/', views.post), + # path('wall/comment/', views.comment), + path('log_out/', views.log_out), +] diff --git a/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/views.py b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/views.py new file mode 100644 index 00000000..64e842d6 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/apps/wall_app/views.py @@ -0,0 +1,81 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.contrib import messages +from .models import * +import datetime +import bcrypt + +def index(request): + if 'logged_in' not in request.session: + request.session['logged_in'] = False + + if 'email' in request.session: + del request.session['email'] + request.session['logged_in'] = False + + return render(request, 'wall/index.html') + +def register(request): + errors = User.objects.registration_validator(request.POST) + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + else: + pw_hash = bcrypt.hashpw(request.POST['password'].encode(), bcrypt.gensalt()).decode() + User.objects.create(first_name=request.POST['first_name'], last_name=request.POST['last_name'], email=request.POST['email'], birthday=datetime.datetime.strptime(request.POST['birthday'], "%Y-%m-%d"), password=pw_hash) + request.session['email'] = request.POST['email'] + request.session['logged_in'] = True + return redirect('/wall') + + return redirect('/') + +def verify(request): + errors = User.objects.login_validator(request.POST) + user = User.objects.filter(email=request.POST['email']) + + if request.method == 'POST': + if len(errors): + for key, value in errors.items(): + messages.error(request, value) + + return redirect('/') + + elif not bcrypt.checkpw(request.POST['passlog'].encode(), user[0].password.encode()): + messages.error(request, "Login failed") + return redirect('/') + + else: + request.session['email'] = request.POST['email'] + request.session['logged_in'] = True + return redirect('/wall') + +def wall(request): + if request.session['logged_in'] == False: + return redirect('/') + + context = { + "user": User.objects.get(email=request.session['email']), + "messages": Message.objects.all().order_by("-created_at"), + "comments": Comment.objects.all() + } + + return render(request, 'wall/wall.html', context) + +def post(request): + if request.method == 'POST': + Message.objects.create(user=User.objects.get(email=request.session['email']), message=request.POST['message']) + return redirect('/wall') + + return redirect('/wall') + +# def comment(request): +# if request.method == 'POST': +# + +def log_out(request): + del request.session['email'] + request.session['logged_in'] = False + return redirect('/') diff --git a/prajesh_gohel/Python/django_ORM/wall/db.sqlite3 b/prajesh_gohel/Python/django_ORM/wall/db.sqlite3 new file mode 100644 index 00000000..351d9d78 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/db.sqlite3 differ diff --git a/prajesh_gohel/Python/django_ORM/wall/manage.py b/prajesh_gohel/Python/django_ORM/wall/manage.py new file mode 100755 index 00000000..42b1662c --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wall.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/prajesh_gohel/Python/django_ORM/wall/wall/__init__.py b/prajesh_gohel/Python/django_ORM/wall/wall/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..835aa0fa Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/settings.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/settings.cpython-37.pyc new file mode 100644 index 00000000..4b127fdc Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/settings.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/urls.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/urls.cpython-37.pyc new file mode 100644 index 00000000..24759247 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/urls.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/wsgi.cpython-37.pyc b/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 00000000..e968c0b7 Binary files /dev/null and b/prajesh_gohel/Python/django_ORM/wall/wall/__pycache__/wsgi.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/django_ORM/wall/wall/settings.py b/prajesh_gohel/Python/django_ORM/wall/wall/settings.py new file mode 100644 index 00000000..2d4495de --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/wall/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for wall project. + +Generated by 'django-admin startproject' using Django 2.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '-dcg0^b0ttv&zi12#!ca)_9lmuu=o8_0gh0z2tnp&mj+nh95zw' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.wall_app', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'wall.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'wall.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/prajesh_gohel/Python/django_ORM/wall/wall/urls.py b/prajesh_gohel/Python/django_ORM/wall/wall/urls.py new file mode 100644 index 00000000..c2abe54a --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/wall/urls.py @@ -0,0 +1,20 @@ +"""wall URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.urls import path, include + +urlpatterns = [ + path('', include('apps.wall_app.urls')), +] diff --git a/prajesh_gohel/Python/django_ORM/wall/wall/wsgi.py b/prajesh_gohel/Python/django_ORM/wall/wall/wsgi.py new file mode 100644 index 00000000..1e9de855 --- /dev/null +++ b/prajesh_gohel/Python/django_ORM/wall/wall/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for wall project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wall.settings") + +application = get_wsgi_application() diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/iptest b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/iptest new file mode 100755 index 00000000..88db894a --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/iptest @@ -0,0 +1,11 @@ +#!/Users/Darwin/Documents/Coding-Dojo/python_july_2018/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/python3.7 + +# -*- coding: utf-8 -*- +import re +import sys + +from IPython.testing.iptestcontroller import main + +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/iptest3 b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/iptest3 new file mode 100755 index 00000000..88db894a --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/iptest3 @@ -0,0 +1,11 @@ +#!/Users/Darwin/Documents/Coding-Dojo/python_july_2018/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/python3.7 + +# -*- coding: utf-8 -*- +import re +import sys + +from IPython.testing.iptestcontroller import main + +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/ipython b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/ipython new file mode 100755 index 00000000..9d4124ba --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/ipython @@ -0,0 +1,11 @@ +#!/Users/Darwin/Documents/Coding-Dojo/python_july_2018/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/python3.7 + +# -*- coding: utf-8 -*- +import re +import sys + +from IPython import start_ipython + +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) + sys.exit(start_ipython()) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/ipython3 b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/ipython3 new file mode 100755 index 00000000..9d4124ba --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/ipython3 @@ -0,0 +1,11 @@ +#!/Users/Darwin/Documents/Coding-Dojo/python_july_2018/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/python3.7 + +# -*- coding: utf-8 -*- +import re +import sys + +from IPython import start_ipython + +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) + sys.exit(start_ipython()) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/pygmentize b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/pygmentize new file mode 100755 index 00000000..0a414bd2 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/pygmentize @@ -0,0 +1,11 @@ +#!/Users/Darwin/Documents/Coding-Dojo/python_july_2018/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/bin/python3.7 + +# -*- coding: utf-8 -*- +import re +import sys + +from pygments.cmdline import main + +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/__pycache__/rlcompleter.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/__pycache__/rlcompleter.cpython-37.pyc new file mode 100644 index 00000000..880cca1d Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/__pycache__/rlcompleter.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/__pycache__/site.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/__pycache__/site.cpython-37.pyc index 6aa258dd..127cf56c 100644 Binary files a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/__pycache__/site.cpython-37.pyc and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/__pycache__/site.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/distutils/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/distutils/__pycache__/__init__.cpython-37.pyc index 54184ea7..4e98fae5 100644 Binary files a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/distutils/__pycache__/__init__.cpython-37.pyc and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/distutils/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__init__.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__init__.py new file mode 100644 index 00000000..d3a5d635 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__init__.py @@ -0,0 +1,151 @@ +# encoding: utf-8 +""" +IPython: tools for interactive and parallel computing in Python. + +http://ipython.org +""" +#----------------------------------------------------------------------------- +# Copyright (c) 2008-2011, IPython Development Team. +# Copyright (c) 2001-2007, Fernando Perez +# Copyright (c) 2001, Janko Hauser +# Copyright (c) 2001, Nathaniel Gray +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os +import sys + +#----------------------------------------------------------------------------- +# Setup everything +#----------------------------------------------------------------------------- + +# Don't forget to also update setup.py when this changes! +if sys.version_info < (3,3): + raise ImportError( +""" +IPython 6.0+ does not support Python 2.6, 2.7, 3.0, 3.1, or 3.2. +When using Python 2.7, please install IPython 5.x LTS Long Term Support version. +Beginning with IPython 6.0, Python 3.3 and above is required. + +See IPython `README.rst` file for more information: + + https://github.com/ipython/ipython/blob/master/README.rst + +""") + +# Make it easy to import extensions - they are always directly on pythonpath. +# Therefore, non-IPython modules can be added to extensions directory. +# This should probably be in ipapp.py. +sys.path.append(os.path.join(os.path.dirname(__file__), "extensions")) + +#----------------------------------------------------------------------------- +# Setup the top level names +#----------------------------------------------------------------------------- + +from .core.getipython import get_ipython +from .core import release +from .core.application import Application +from .terminal.embed import embed + +from .core.interactiveshell import InteractiveShell +from .testing import test +from .utils.sysinfo import sys_info +from .utils.frame import extract_module_locals + +# Release data +__author__ = '%s <%s>' % (release.author, release.author_email) +__license__ = release.license +__version__ = release.version +version_info = release.version_info + +def embed_kernel(module=None, local_ns=None, **kwargs): + """Embed and start an IPython kernel in a given scope. + + If you don't want the kernel to initialize the namespace + from the scope of the surrounding function, + and/or you want to load full IPython configuration, + you probably want `IPython.start_kernel()` instead. + + Parameters + ---------- + module : ModuleType, optional + The module to load into IPython globals (default: caller) + local_ns : dict, optional + The namespace to load into IPython user namespace (default: caller) + + kwargs : various, optional + Further keyword args are relayed to the IPKernelApp constructor, + allowing configuration of the Kernel. Will only have an effect + on the first embed_kernel call for a given process. + """ + + (caller_module, caller_locals) = extract_module_locals(1) + if module is None: + module = caller_module + if local_ns is None: + local_ns = caller_locals + + # Only import .zmq when we really need it + from ipykernel.embed import embed_kernel as real_embed_kernel + real_embed_kernel(module=module, local_ns=local_ns, **kwargs) + +def start_ipython(argv=None, **kwargs): + """Launch a normal IPython instance (as opposed to embedded) + + `IPython.embed()` puts a shell in a particular calling scope, + such as a function or method for debugging purposes, + which is often not desirable. + + `start_ipython()` does full, regular IPython initialization, + including loading startup files, configuration, etc. + much of which is skipped by `embed()`. + + This is a public API method, and will survive implementation changes. + + Parameters + ---------- + + argv : list or None, optional + If unspecified or None, IPython will parse command-line options from sys.argv. + To prevent any command-line parsing, pass an empty list: `argv=[]`. + user_ns : dict, optional + specify this dictionary to initialize the IPython user namespace with particular values. + kwargs : various, optional + Any other kwargs will be passed to the Application constructor, + such as `config`. + """ + from IPython.terminal.ipapp import launch_new_instance + return launch_new_instance(argv=argv, **kwargs) + +def start_kernel(argv=None, **kwargs): + """Launch a normal IPython kernel instance (as opposed to embedded) + + `IPython.embed_kernel()` puts a shell in a particular calling scope, + such as a function or method for debugging purposes, + which is often not desirable. + + `start_kernel()` does full, regular IPython initialization, + including loading startup files, configuration, etc. + much of which is skipped by `embed()`. + + Parameters + ---------- + + argv : list or None, optional + If unspecified or None, IPython will parse command-line options from sys.argv. + To prevent any command-line parsing, pass an empty list: `argv=[]`. + user_ns : dict, optional + specify this dictionary to initialize the IPython user namespace with particular values. + kwargs : various, optional + Any other kwargs will be passed to the Application constructor, + such as `config`. + """ + from IPython.kernel.zmq.kernelapp import launch_new_instance + return launch_new_instance(argv=argv, **kwargs) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__main__.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__main__.py new file mode 100644 index 00000000..d5123f33 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__main__.py @@ -0,0 +1,14 @@ +# encoding: utf-8 +"""Terminal-based IPython entry point. +""" +#----------------------------------------------------------------------------- +# Copyright (c) 2012, IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +from IPython import start_ipython + +start_ipython() diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..046fc92e Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/__main__.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/__main__.cpython-37.pyc new file mode 100644 index 00000000..814fd853 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/__main__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/config.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/config.cpython-37.pyc new file mode 100644 index 00000000..85354626 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/config.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/consoleapp.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/consoleapp.cpython-37.pyc new file mode 100644 index 00000000..4636b97b Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/consoleapp.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/display.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/display.cpython-37.pyc new file mode 100644 index 00000000..1c7e1da3 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/display.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/frontend.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/frontend.cpython-37.pyc new file mode 100644 index 00000000..44deee17 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/frontend.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/html.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/html.cpython-37.pyc new file mode 100644 index 00000000..52960a74 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/html.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/nbconvert.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/nbconvert.cpython-37.pyc new file mode 100644 index 00000000..6f340040 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/nbconvert.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/nbformat.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/nbformat.cpython-37.pyc new file mode 100644 index 00000000..99a29eff Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/nbformat.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/parallel.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/parallel.cpython-37.pyc new file mode 100644 index 00000000..ff008465 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/parallel.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/paths.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/paths.cpython-37.pyc new file mode 100644 index 00000000..be070b49 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/paths.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/qt.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/qt.cpython-37.pyc new file mode 100644 index 00000000..36dfe5c4 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/__pycache__/qt.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/config.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/config.py new file mode 100644 index 00000000..cf2bacaf --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/config.py @@ -0,0 +1,19 @@ +""" +Shim to maintain backwards compatibility with old IPython.config imports. +""" +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + +import sys +from warnings import warn + +from IPython.utils.shimmodule import ShimModule, ShimWarning + +warn("The `IPython.config` package has been deprecated since IPython 4.0. " + "You should import from traitlets.config instead.", ShimWarning) + + +# Unconditionally insert the shim into sys.modules so that further import calls +# trigger the custom attribute access above + +sys.modules['IPython.config'] = ShimModule(src='IPython.config', mirror='traitlets.config') diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/consoleapp.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/consoleapp.py new file mode 100644 index 00000000..14903bdc --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/consoleapp.py @@ -0,0 +1,12 @@ +""" +Shim to maintain backwards compatibility with old IPython.consoleapp imports. +""" +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + +from warnings import warn + +warn("The `IPython.consoleapp` package has been deprecated. " + "You should import from jupyter_client.consoleapp instead.") + +from jupyter_client.consoleapp import * diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__init__.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/__init__.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..b2fcb1b7 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/__init__.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/alias.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/alias.cpython-37.pyc new file mode 100644 index 00000000..b8a91014 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/alias.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/application.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/application.cpython-37.pyc new file mode 100644 index 00000000..eb3df8e8 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/application.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/autocall.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/autocall.cpython-37.pyc new file mode 100644 index 00000000..d1b20044 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/autocall.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/builtin_trap.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/builtin_trap.cpython-37.pyc new file mode 100644 index 00000000..16c06b36 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/builtin_trap.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/compilerop.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/compilerop.cpython-37.pyc new file mode 100644 index 00000000..43605046 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/compilerop.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/completer.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/completer.cpython-37.pyc new file mode 100644 index 00000000..77ddc7b0 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/completer.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/completerlib.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/completerlib.cpython-37.pyc new file mode 100644 index 00000000..09bf044d Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/completerlib.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/crashhandler.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/crashhandler.cpython-37.pyc new file mode 100644 index 00000000..98360802 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/crashhandler.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/debugger.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/debugger.cpython-37.pyc new file mode 100644 index 00000000..852d7ca7 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/debugger.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/display.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/display.cpython-37.pyc new file mode 100644 index 00000000..e7113ef5 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/display.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/display_trap.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/display_trap.cpython-37.pyc new file mode 100644 index 00000000..bc4fb3b1 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/display_trap.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/displayhook.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/displayhook.cpython-37.pyc new file mode 100644 index 00000000..f14df251 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/displayhook.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/displaypub.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/displaypub.cpython-37.pyc new file mode 100644 index 00000000..dec41f49 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/displaypub.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/error.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/error.cpython-37.pyc new file mode 100644 index 00000000..92f186c0 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/error.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/events.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/events.cpython-37.pyc new file mode 100644 index 00000000..9845bdac Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/events.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/excolors.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/excolors.cpython-37.pyc new file mode 100644 index 00000000..d2d9c71a Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/excolors.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/extensions.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/extensions.cpython-37.pyc new file mode 100644 index 00000000..79778311 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/extensions.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/formatters.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/formatters.cpython-37.pyc new file mode 100644 index 00000000..d7efbe5d Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/formatters.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/getipython.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/getipython.cpython-37.pyc new file mode 100644 index 00000000..905c4144 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/getipython.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/history.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/history.cpython-37.pyc new file mode 100644 index 00000000..cd4f7af5 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/history.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/historyapp.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/historyapp.cpython-37.pyc new file mode 100644 index 00000000..36c7978d Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/historyapp.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/hooks.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/hooks.cpython-37.pyc new file mode 100644 index 00000000..5fa92901 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/hooks.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/inputsplitter.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/inputsplitter.cpython-37.pyc new file mode 100644 index 00000000..f3c2edf7 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/inputsplitter.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/inputtransformer.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/inputtransformer.cpython-37.pyc new file mode 100644 index 00000000..87f30ebe Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/inputtransformer.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/interactiveshell.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/interactiveshell.cpython-37.pyc new file mode 100644 index 00000000..7e9487f6 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/interactiveshell.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/latex_symbols.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/latex_symbols.cpython-37.pyc new file mode 100644 index 00000000..e03c1062 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/latex_symbols.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/logger.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/logger.cpython-37.pyc new file mode 100644 index 00000000..36adf4f8 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/logger.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/macro.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/macro.cpython-37.pyc new file mode 100644 index 00000000..5a0fb8ec Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/macro.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/magic.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/magic.cpython-37.pyc new file mode 100644 index 00000000..ae9086e1 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/magic.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/magic_arguments.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/magic_arguments.cpython-37.pyc new file mode 100644 index 00000000..fafa18c3 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/magic_arguments.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/oinspect.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/oinspect.cpython-37.pyc new file mode 100644 index 00000000..7f66e319 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/oinspect.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/page.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/page.cpython-37.pyc new file mode 100644 index 00000000..ec2d7d8b Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/page.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/payload.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/payload.cpython-37.pyc new file mode 100644 index 00000000..ef0ca366 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/payload.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/payloadpage.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/payloadpage.cpython-37.pyc new file mode 100644 index 00000000..e125d9ba Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/payloadpage.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/prefilter.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/prefilter.cpython-37.pyc new file mode 100644 index 00000000..7aa6a402 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/prefilter.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/profileapp.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/profileapp.cpython-37.pyc new file mode 100644 index 00000000..aba618f8 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/profileapp.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/profiledir.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/profiledir.cpython-37.pyc new file mode 100644 index 00000000..18256d8f Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/profiledir.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/prompts.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/prompts.cpython-37.pyc new file mode 100644 index 00000000..20a2bda7 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/prompts.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/pylabtools.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/pylabtools.cpython-37.pyc new file mode 100644 index 00000000..a807910f Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/pylabtools.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/release.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/release.cpython-37.pyc new file mode 100644 index 00000000..07a6090b Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/release.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/shellapp.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/shellapp.cpython-37.pyc new file mode 100644 index 00000000..f10f09c3 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/shellapp.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/splitinput.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/splitinput.cpython-37.pyc new file mode 100644 index 00000000..3d5f5eab Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/splitinput.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/ultratb.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/ultratb.cpython-37.pyc new file mode 100644 index 00000000..52705241 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/ultratb.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/usage.cpython-37.pyc b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/usage.cpython-37.pyc new file mode 100644 index 00000000..a722bd28 Binary files /dev/null and b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/__pycache__/usage.cpython-37.pyc differ diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/alias.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/alias.py new file mode 100644 index 00000000..ee377d5c --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/alias.py @@ -0,0 +1,256 @@ +# encoding: utf-8 +""" +System command aliases. + +Authors: + +* Fernando Perez +* Brian Granger +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2008-2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os +import re +import sys + +from traitlets.config.configurable import Configurable +from IPython.core.error import UsageError + +from traitlets import List, Instance +from logging import error + +#----------------------------------------------------------------------------- +# Utilities +#----------------------------------------------------------------------------- + +# This is used as the pattern for calls to split_user_input. +shell_line_split = re.compile(r'^(\s*)()(\S+)(.*$)') + +def default_aliases(): + """Return list of shell aliases to auto-define. + """ + # Note: the aliases defined here should be safe to use on a kernel + # regardless of what frontend it is attached to. Frontends that use a + # kernel in-process can define additional aliases that will only work in + # their case. For example, things like 'less' or 'clear' that manipulate + # the terminal should NOT be declared here, as they will only work if the + # kernel is running inside a true terminal, and not over the network. + + if os.name == 'posix': + default_aliases = [('mkdir', 'mkdir'), ('rmdir', 'rmdir'), + ('mv', 'mv'), ('rm', 'rm'), ('cp', 'cp'), + ('cat', 'cat'), + ] + # Useful set of ls aliases. The GNU and BSD options are a little + # different, so we make aliases that provide as similar as possible + # behavior in ipython, by passing the right flags for each platform + if sys.platform.startswith('linux'): + ls_aliases = [('ls', 'ls -F --color'), + # long ls + ('ll', 'ls -F -o --color'), + # ls normal files only + ('lf', 'ls -F -o --color %l | grep ^-'), + # ls symbolic links + ('lk', 'ls -F -o --color %l | grep ^l'), + # directories or links to directories, + ('ldir', 'ls -F -o --color %l | grep /$'), + # things which are executable + ('lx', 'ls -F -o --color %l | grep ^-..x'), + ] + elif sys.platform.startswith('openbsd') or sys.platform.startswith('netbsd'): + # OpenBSD, NetBSD. The ls implementation on these platforms do not support + # the -G switch and lack the ability to use colorized output. + ls_aliases = [('ls', 'ls -F'), + # long ls + ('ll', 'ls -F -l'), + # ls normal files only + ('lf', 'ls -F -l %l | grep ^-'), + # ls symbolic links + ('lk', 'ls -F -l %l | grep ^l'), + # directories or links to directories, + ('ldir', 'ls -F -l %l | grep /$'), + # things which are executable + ('lx', 'ls -F -l %l | grep ^-..x'), + ] + else: + # BSD, OSX, etc. + ls_aliases = [('ls', 'ls -F -G'), + # long ls + ('ll', 'ls -F -l -G'), + # ls normal files only + ('lf', 'ls -F -l -G %l | grep ^-'), + # ls symbolic links + ('lk', 'ls -F -l -G %l | grep ^l'), + # directories or links to directories, + ('ldir', 'ls -F -G -l %l | grep /$'), + # things which are executable + ('lx', 'ls -F -l -G %l | grep ^-..x'), + ] + default_aliases = default_aliases + ls_aliases + elif os.name in ['nt', 'dos']: + default_aliases = [('ls', 'dir /on'), + ('ddir', 'dir /ad /on'), ('ldir', 'dir /ad /on'), + ('mkdir', 'mkdir'), ('rmdir', 'rmdir'), + ('echo', 'echo'), ('ren', 'ren'), ('copy', 'copy'), + ] + else: + default_aliases = [] + + return default_aliases + + +class AliasError(Exception): + pass + + +class InvalidAliasError(AliasError): + pass + +class Alias(object): + """Callable object storing the details of one alias. + + Instances are registered as magic functions to allow use of aliases. + """ + + # Prepare blacklist + blacklist = {'cd','popd','pushd','dhist','alias','unalias'} + + def __init__(self, shell, name, cmd): + self.shell = shell + self.name = name + self.cmd = cmd + self.__doc__ = "Alias for `!{}`".format(cmd) + self.nargs = self.validate() + + def validate(self): + """Validate the alias, and return the number of arguments.""" + if self.name in self.blacklist: + raise InvalidAliasError("The name %s can't be aliased " + "because it is a keyword or builtin." % self.name) + try: + caller = self.shell.magics_manager.magics['line'][self.name] + except KeyError: + pass + else: + if not isinstance(caller, Alias): + raise InvalidAliasError("The name %s can't be aliased " + "because it is another magic command." % self.name) + + if not (isinstance(self.cmd, str)): + raise InvalidAliasError("An alias command must be a string, " + "got: %r" % self.cmd) + + nargs = self.cmd.count('%s') - self.cmd.count('%%s') + + if (nargs > 0) and (self.cmd.find('%l') >= 0): + raise InvalidAliasError('The %s and %l specifiers are mutually ' + 'exclusive in alias definitions.') + + return nargs + + def __repr__(self): + return "".format(self.name, self.cmd) + + def __call__(self, rest=''): + cmd = self.cmd + nargs = self.nargs + # Expand the %l special to be the user's input line + if cmd.find('%l') >= 0: + cmd = cmd.replace('%l', rest) + rest = '' + + if nargs==0: + if cmd.find('%%s') >= 1: + cmd = cmd.replace('%%s', '%s') + # Simple, argument-less aliases + cmd = '%s %s' % (cmd, rest) + else: + # Handle aliases with positional arguments + args = rest.split(None, nargs) + if len(args) < nargs: + raise UsageError('Alias <%s> requires %s arguments, %s given.' % + (self.name, nargs, len(args))) + cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:])) + + self.shell.system(cmd) + +#----------------------------------------------------------------------------- +# Main AliasManager class +#----------------------------------------------------------------------------- + +class AliasManager(Configurable): + + default_aliases = List(default_aliases()).tag(config=True) + user_aliases = List(default_value=[]).tag(config=True) + shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True) + + def __init__(self, shell=None, **kwargs): + super(AliasManager, self).__init__(shell=shell, **kwargs) + # For convenient access + self.linemagics = self.shell.magics_manager.magics['line'] + self.init_aliases() + + def init_aliases(self): + # Load default & user aliases + for name, cmd in self.default_aliases + self.user_aliases: + self.soft_define_alias(name, cmd) + + @property + def aliases(self): + return [(n, func.cmd) for (n, func) in self.linemagics.items() + if isinstance(func, Alias)] + + def soft_define_alias(self, name, cmd): + """Define an alias, but don't raise on an AliasError.""" + try: + self.define_alias(name, cmd) + except AliasError as e: + error("Invalid alias: %s" % e) + + def define_alias(self, name, cmd): + """Define a new alias after validating it. + + This will raise an :exc:`AliasError` if there are validation + problems. + """ + caller = Alias(shell=self.shell, name=name, cmd=cmd) + self.shell.magics_manager.register_function(caller, magic_kind='line', + magic_name=name) + + def get_alias(self, name): + """Return an alias, or None if no alias by that name exists.""" + aname = self.linemagics.get(name, None) + return aname if isinstance(aname, Alias) else None + + def is_alias(self, name): + """Return whether or not a given name has been defined as an alias""" + return self.get_alias(name) is not None + + def undefine_alias(self, name): + if self.is_alias(name): + del self.linemagics[name] + else: + raise ValueError('%s is not an alias' % name) + + def clear_aliases(self): + for name, cmd in self.aliases: + self.undefine_alias(name) + + def retrieve_alias(self, name): + """Retrieve the command to which an alias expands.""" + caller = self.get_alias(name) + if caller: + return caller.cmd + else: + raise ValueError('%s is not an alias' % name) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/application.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/application.py new file mode 100644 index 00000000..fea2b50f --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/application.py @@ -0,0 +1,462 @@ +# encoding: utf-8 +""" +An application for IPython. + +All top-level applications should use the classes in this module for +handling configuration and creating configurables. + +The job of an :class:`Application` is to create the master configuration +object and then create the configurable objects, passing the config to them. +""" + +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + +import atexit +from copy import deepcopy +import glob +import logging +import os +import shutil +import sys + +from traitlets.config.application import Application, catch_config_error +from traitlets.config.loader import ConfigFileNotFound, PyFileConfigLoader +from IPython.core import release, crashhandler +from IPython.core.profiledir import ProfileDir, ProfileDirError +from IPython.paths import get_ipython_dir, get_ipython_package_dir +from IPython.utils.path import ensure_dir_exists +from traitlets import ( + List, Unicode, Type, Bool, Set, Instance, Undefined, + default, observe, +) + +if os.name == 'nt': + programdata = os.environ.get('PROGRAMDATA', None) + if programdata: + SYSTEM_CONFIG_DIRS = [os.path.join(programdata, 'ipython')] + else: # PROGRAMDATA is not defined by default on XP. + SYSTEM_CONFIG_DIRS = [] +else: + SYSTEM_CONFIG_DIRS = [ + "/usr/local/etc/ipython", + "/etc/ipython", + ] + + +ENV_CONFIG_DIRS = [] +_env_config_dir = os.path.join(sys.prefix, 'etc', 'ipython') +if _env_config_dir not in SYSTEM_CONFIG_DIRS: + # only add ENV_CONFIG if sys.prefix is not already included + ENV_CONFIG_DIRS.append(_env_config_dir) + + +_envvar = os.environ.get('IPYTHON_SUPPRESS_CONFIG_ERRORS') +if _envvar in {None, ''}: + IPYTHON_SUPPRESS_CONFIG_ERRORS = None +else: + if _envvar.lower() in {'1','true'}: + IPYTHON_SUPPRESS_CONFIG_ERRORS = True + elif _envvar.lower() in {'0','false'} : + IPYTHON_SUPPRESS_CONFIG_ERRORS = False + else: + sys.exit("Unsupported value for environment variable: 'IPYTHON_SUPPRESS_CONFIG_ERRORS' is set to '%s' which is none of {'0', '1', 'false', 'true', ''}."% _envvar ) + +# aliases and flags + +base_aliases = { + 'profile-dir' : 'ProfileDir.location', + 'profile' : 'BaseIPythonApplication.profile', + 'ipython-dir' : 'BaseIPythonApplication.ipython_dir', + 'log-level' : 'Application.log_level', + 'config' : 'BaseIPythonApplication.extra_config_file', +} + +base_flags = dict( + debug = ({'Application' : {'log_level' : logging.DEBUG}}, + "set log level to logging.DEBUG (maximize logging output)"), + quiet = ({'Application' : {'log_level' : logging.CRITICAL}}, + "set log level to logging.CRITICAL (minimize logging output)"), + init = ({'BaseIPythonApplication' : { + 'copy_config_files' : True, + 'auto_create' : True} + }, """Initialize profile with default config files. This is equivalent + to running `ipython profile create ` prior to startup. + """) +) + +class ProfileAwareConfigLoader(PyFileConfigLoader): + """A Python file config loader that is aware of IPython profiles.""" + def load_subconfig(self, fname, path=None, profile=None): + if profile is not None: + try: + profile_dir = ProfileDir.find_profile_dir_by_name( + get_ipython_dir(), + profile, + ) + except ProfileDirError: + return + path = profile_dir.location + return super(ProfileAwareConfigLoader, self).load_subconfig(fname, path=path) + +class BaseIPythonApplication(Application): + + name = u'ipython' + description = Unicode(u'IPython: an enhanced interactive Python shell.') + version = Unicode(release.version) + + aliases = base_aliases + flags = base_flags + classes = List([ProfileDir]) + + # enable `load_subconfig('cfg.py', profile='name')` + python_config_loader_class = ProfileAwareConfigLoader + + # Track whether the config_file has changed, + # because some logic happens only if we aren't using the default. + config_file_specified = Set() + + config_file_name = Unicode() + @default('config_file_name') + def _config_file_name_default(self): + return self.name.replace('-','_') + u'_config.py' + @observe('config_file_name') + def _config_file_name_changed(self, change): + if change['new'] != change['old']: + self.config_file_specified.add(change['new']) + + # The directory that contains IPython's builtin profiles. + builtin_profile_dir = Unicode( + os.path.join(get_ipython_package_dir(), u'config', u'profile', u'default') + ) + + config_file_paths = List(Unicode()) + @default('config_file_paths') + def _config_file_paths_default(self): + return [os.getcwd()] + + extra_config_file = Unicode( + help="""Path to an extra config file to load. + + If specified, load this config file in addition to any other IPython config. + """).tag(config=True) + @observe('extra_config_file') + def _extra_config_file_changed(self, change): + old = change['old'] + new = change['new'] + try: + self.config_files.remove(old) + except ValueError: + pass + self.config_file_specified.add(new) + self.config_files.append(new) + + profile = Unicode(u'default', + help="""The IPython profile to use.""" + ).tag(config=True) + + @observe('profile') + def _profile_changed(self, change): + self.builtin_profile_dir = os.path.join( + get_ipython_package_dir(), u'config', u'profile', change['new'] + ) + + ipython_dir = Unicode( + help=""" + The name of the IPython directory. This directory is used for logging + configuration (through profiles), history storage, etc. The default + is usually $HOME/.ipython. This option can also be specified through + the environment variable IPYTHONDIR. + """ + ).tag(config=True) + @default('ipython_dir') + def _ipython_dir_default(self): + d = get_ipython_dir() + self._ipython_dir_changed({ + 'name': 'ipython_dir', + 'old': d, + 'new': d, + }) + return d + + _in_init_profile_dir = False + profile_dir = Instance(ProfileDir, allow_none=True) + @default('profile_dir') + def _profile_dir_default(self): + # avoid recursion + if self._in_init_profile_dir: + return + # profile_dir requested early, force initialization + self.init_profile_dir() + return self.profile_dir + + overwrite = Bool(False, + help="""Whether to overwrite existing config files when copying""" + ).tag(config=True) + auto_create = Bool(False, + help="""Whether to create profile dir if it doesn't exist""" + ).tag(config=True) + + config_files = List(Unicode()) + @default('config_files') + def _config_files_default(self): + return [self.config_file_name] + + copy_config_files = Bool(False, + help="""Whether to install the default config files into the profile dir. + If a new profile is being created, and IPython contains config files for that + profile, then they will be staged into the new directory. Otherwise, + default config files will be automatically generated. + """).tag(config=True) + + verbose_crash = Bool(False, + help="""Create a massive crash report when IPython encounters what may be an + internal error. The default is to append a short message to the + usual traceback""").tag(config=True) + + # The class to use as the crash handler. + crash_handler_class = Type(crashhandler.CrashHandler) + + @catch_config_error + def __init__(self, **kwargs): + super(BaseIPythonApplication, self).__init__(**kwargs) + # ensure current working directory exists + try: + os.getcwd() + except: + # exit if cwd doesn't exist + self.log.error("Current working directory doesn't exist.") + self.exit(1) + + #------------------------------------------------------------------------- + # Various stages of Application creation + #------------------------------------------------------------------------- + + deprecated_subcommands = {} + + def initialize_subcommand(self, subc, argv=None): + if subc in self.deprecated_subcommands: + self.log.warning("Subcommand `ipython {sub}` is deprecated and will be removed " + "in future versions.".format(sub=subc)) + self.log.warning("You likely want to use `jupyter {sub}` in the " + "future".format(sub=subc)) + return super(BaseIPythonApplication, self).initialize_subcommand(subc, argv) + + def init_crash_handler(self): + """Create a crash handler, typically setting sys.excepthook to it.""" + self.crash_handler = self.crash_handler_class(self) + sys.excepthook = self.excepthook + def unset_crashhandler(): + sys.excepthook = sys.__excepthook__ + atexit.register(unset_crashhandler) + + def excepthook(self, etype, evalue, tb): + """this is sys.excepthook after init_crashhandler + + set self.verbose_crash=True to use our full crashhandler, instead of + a regular traceback with a short message (crash_handler_lite) + """ + + if self.verbose_crash: + return self.crash_handler(etype, evalue, tb) + else: + return crashhandler.crash_handler_lite(etype, evalue, tb) + + @observe('ipython_dir') + def _ipython_dir_changed(self, change): + old = change['old'] + new = change['new'] + if old is not Undefined: + str_old = os.path.abspath(old) + if str_old in sys.path: + sys.path.remove(str_old) + str_path = os.path.abspath(new) + sys.path.append(str_path) + ensure_dir_exists(new) + readme = os.path.join(new, 'README') + readme_src = os.path.join(get_ipython_package_dir(), u'config', u'profile', 'README') + if not os.path.exists(readme) and os.path.exists(readme_src): + shutil.copy(readme_src, readme) + for d in ('extensions', 'nbextensions'): + path = os.path.join(new, d) + try: + ensure_dir_exists(path) + except OSError as e: + # this will not be EEXIST + self.log.error("couldn't create path %s: %s", path, e) + self.log.debug("IPYTHONDIR set to: %s" % new) + + def load_config_file(self, suppress_errors=IPYTHON_SUPPRESS_CONFIG_ERRORS): + """Load the config file. + + By default, errors in loading config are handled, and a warning + printed on screen. For testing, the suppress_errors option is set + to False, so errors will make tests fail. + + `supress_errors` default value is to be `None` in which case the + behavior default to the one of `traitlets.Application`. + + The default value can be set : + - to `False` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '0', or 'false' (case insensitive). + - to `True` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '1' or 'true' (case insensitive). + - to `None` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '' (empty string) or leaving it unset. + + Any other value are invalid, and will make IPython exit with a non-zero return code. + """ + + + self.log.debug("Searching path %s for config files", self.config_file_paths) + base_config = 'ipython_config.py' + self.log.debug("Attempting to load config file: %s" % + base_config) + try: + if suppress_errors is not None: + old_value = Application.raise_config_file_errors + Application.raise_config_file_errors = not suppress_errors; + Application.load_config_file( + self, + base_config, + path=self.config_file_paths + ) + except ConfigFileNotFound: + # ignore errors loading parent + self.log.debug("Config file %s not found", base_config) + pass + if suppress_errors is not None: + Application.raise_config_file_errors = old_value + + for config_file_name in self.config_files: + if not config_file_name or config_file_name == base_config: + continue + self.log.debug("Attempting to load config file: %s" % + self.config_file_name) + try: + Application.load_config_file( + self, + config_file_name, + path=self.config_file_paths + ) + except ConfigFileNotFound: + # Only warn if the default config file was NOT being used. + if config_file_name in self.config_file_specified: + msg = self.log.warning + else: + msg = self.log.debug + msg("Config file not found, skipping: %s", config_file_name) + except Exception: + # For testing purposes. + if not suppress_errors: + raise + self.log.warning("Error loading config file: %s" % + self.config_file_name, exc_info=True) + + def init_profile_dir(self): + """initialize the profile dir""" + self._in_init_profile_dir = True + if self.profile_dir is not None: + # already ran + return + if 'ProfileDir.location' not in self.config: + # location not specified, find by profile name + try: + p = ProfileDir.find_profile_dir_by_name(self.ipython_dir, self.profile, self.config) + except ProfileDirError: + # not found, maybe create it (always create default profile) + if self.auto_create or self.profile == 'default': + try: + p = ProfileDir.create_profile_dir_by_name(self.ipython_dir, self.profile, self.config) + except ProfileDirError: + self.log.fatal("Could not create profile: %r"%self.profile) + self.exit(1) + else: + self.log.info("Created profile dir: %r"%p.location) + else: + self.log.fatal("Profile %r not found."%self.profile) + self.exit(1) + else: + self.log.debug("Using existing profile dir: %r"%p.location) + else: + location = self.config.ProfileDir.location + # location is fully specified + try: + p = ProfileDir.find_profile_dir(location, self.config) + except ProfileDirError: + # not found, maybe create it + if self.auto_create: + try: + p = ProfileDir.create_profile_dir(location, self.config) + except ProfileDirError: + self.log.fatal("Could not create profile directory: %r"%location) + self.exit(1) + else: + self.log.debug("Creating new profile dir: %r"%location) + else: + self.log.fatal("Profile directory %r not found."%location) + self.exit(1) + else: + self.log.info("Using existing profile dir: %r"%location) + # if profile_dir is specified explicitly, set profile name + dir_name = os.path.basename(p.location) + if dir_name.startswith('profile_'): + self.profile = dir_name[8:] + + self.profile_dir = p + self.config_file_paths.append(p.location) + self._in_init_profile_dir = False + + def init_config_files(self): + """[optionally] copy default config files into profile dir.""" + self.config_file_paths.extend(ENV_CONFIG_DIRS) + self.config_file_paths.extend(SYSTEM_CONFIG_DIRS) + # copy config files + path = self.builtin_profile_dir + if self.copy_config_files: + src = self.profile + + cfg = self.config_file_name + if path and os.path.exists(os.path.join(path, cfg)): + self.log.warning("Staging %r from %s into %r [overwrite=%s]"%( + cfg, src, self.profile_dir.location, self.overwrite) + ) + self.profile_dir.copy_config_file(cfg, path=path, overwrite=self.overwrite) + else: + self.stage_default_config_file() + else: + # Still stage *bundled* config files, but not generated ones + # This is necessary for `ipython profile=sympy` to load the profile + # on the first go + files = glob.glob(os.path.join(path, '*.py')) + for fullpath in files: + cfg = os.path.basename(fullpath) + if self.profile_dir.copy_config_file(cfg, path=path, overwrite=False): + # file was copied + self.log.warning("Staging bundled %s from %s into %r"%( + cfg, self.profile, self.profile_dir.location) + ) + + + def stage_default_config_file(self): + """auto generate default config file, and stage it into the profile.""" + s = self.generate_config_file() + fname = os.path.join(self.profile_dir.location, self.config_file_name) + if self.overwrite or not os.path.exists(fname): + self.log.warning("Generating default config file: %r"%(fname)) + with open(fname, 'w') as f: + f.write(s) + + @catch_config_error + def initialize(self, argv=None): + # don't hook up crash handler before parsing command-line + self.parse_command_line(argv) + self.init_crash_handler() + if self.subapp is not None: + # stop here if subapp is taking over + return + # save a copy of CLI config to re-load after config files + # so that it has highest priority + cl_config = deepcopy(self.config) + self.init_profile_dir() + self.init_config_files() + self.load_config_file() + # enforce cl-opts override configfile opts: + self.update_config(cl_config) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/autocall.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/autocall.py new file mode 100644 index 00000000..bab7f859 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/autocall.py @@ -0,0 +1,70 @@ +# encoding: utf-8 +""" +Autocall capabilities for IPython.core. + +Authors: + +* Brian Granger +* Fernando Perez +* Thomas Kluyver + +Notes +----- +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2008-2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +class IPyAutocall(object): + """ Instances of this class are always autocalled + + This happens regardless of 'autocall' variable state. Use this to + develop macro-like mechanisms. + """ + _ip = None + rewrite = True + def __init__(self, ip=None): + self._ip = ip + + def set_ip(self, ip): + """ Will be used to set _ip point to current ipython instance b/f call + + Override this method if you don't want this to happen. + + """ + self._ip = ip + + +class ExitAutocall(IPyAutocall): + """An autocallable object which will be added to the user namespace so that + exit, exit(), quit or quit() are all valid ways to close the shell.""" + rewrite = False + + def __call__(self): + self._ip.ask_exit() + +class ZMQExitAutocall(ExitAutocall): + """Exit IPython. Autocallable, so it needn't be explicitly called. + + Parameters + ---------- + keep_kernel : bool + If True, leave the kernel alive. Otherwise, tell the kernel to exit too + (default). + """ + def __call__(self, keep_kernel=False): + self._ip.keepkernel_on_exit = keep_kernel + self._ip.ask_exit() diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/builtin_trap.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/builtin_trap.py new file mode 100644 index 00000000..a8ea4abc --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/builtin_trap.py @@ -0,0 +1,86 @@ +""" +A context manager for managing things injected into :mod:`builtins`. +""" +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. +import builtins as builtin_mod + +from traitlets.config.configurable import Configurable + +from traitlets import Instance + + +class __BuiltinUndefined(object): pass +BuiltinUndefined = __BuiltinUndefined() + +class __HideBuiltin(object): pass +HideBuiltin = __HideBuiltin() + + +class BuiltinTrap(Configurable): + + shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', + allow_none=True) + + def __init__(self, shell=None): + super(BuiltinTrap, self).__init__(shell=shell, config=None) + self._orig_builtins = {} + # We define this to track if a single BuiltinTrap is nested. + # Only turn off the trap when the outermost call to __exit__ is made. + self._nested_level = 0 + self.shell = shell + # builtins we always add - if set to HideBuiltin, they will just + # be removed instead of being replaced by something else + self.auto_builtins = {'exit': HideBuiltin, + 'quit': HideBuiltin, + 'get_ipython': self.shell.get_ipython, + } + + def __enter__(self): + if self._nested_level == 0: + self.activate() + self._nested_level += 1 + # I return self, so callers can use add_builtin in a with clause. + return self + + def __exit__(self, type, value, traceback): + if self._nested_level == 1: + self.deactivate() + self._nested_level -= 1 + # Returning False will cause exceptions to propagate + return False + + def add_builtin(self, key, value): + """Add a builtin and save the original.""" + bdict = builtin_mod.__dict__ + orig = bdict.get(key, BuiltinUndefined) + if value is HideBuiltin: + if orig is not BuiltinUndefined: #same as 'key in bdict' + self._orig_builtins[key] = orig + del bdict[key] + else: + self._orig_builtins[key] = orig + bdict[key] = value + + def remove_builtin(self, key, orig): + """Remove an added builtin and re-set the original.""" + if orig is BuiltinUndefined: + del builtin_mod.__dict__[key] + else: + builtin_mod.__dict__[key] = orig + + def activate(self): + """Store ipython references in the __builtin__ namespace.""" + + add_builtin = self.add_builtin + for name, func in self.auto_builtins.items(): + add_builtin(name, func) + + def deactivate(self): + """Remove any builtins which might have been added by add_builtins, or + restore overwritten ones to their previous values.""" + remove_builtin = self.remove_builtin + for key, val in self._orig_builtins.items(): + remove_builtin(key, val) + self._orig_builtins.clear() + self._builtins_added = False diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/compilerop.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/compilerop.py new file mode 100644 index 00000000..3dc083c9 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/compilerop.py @@ -0,0 +1,143 @@ +"""Compiler tools with improved interactive support. + +Provides compilation machinery similar to codeop, but with caching support so +we can provide interactive tracebacks. + +Authors +------- +* Robert Kern +* Fernando Perez +* Thomas Kluyver +""" + +# Note: though it might be more natural to name this module 'compiler', that +# name is in the stdlib and name collisions with the stdlib tend to produce +# weird problems (often with third-party tools). + +#----------------------------------------------------------------------------- +# Copyright (C) 2010-2011 The IPython Development Team. +# +# Distributed under the terms of the BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +# Stdlib imports +import __future__ +from ast import PyCF_ONLY_AST +import codeop +import functools +import hashlib +import linecache +import operator +import time + +#----------------------------------------------------------------------------- +# Constants +#----------------------------------------------------------------------------- + +# Roughtly equal to PyCF_MASK | PyCF_MASK_OBSOLETE as defined in pythonrun.h, +# this is used as a bitmask to extract future-related code flags. +PyCF_MASK = functools.reduce(operator.or_, + (getattr(__future__, fname).compiler_flag + for fname in __future__.all_feature_names)) + +#----------------------------------------------------------------------------- +# Local utilities +#----------------------------------------------------------------------------- + +def code_name(code, number=0): + """ Compute a (probably) unique name for code for caching. + + This now expects code to be unicode. + """ + hash_digest = hashlib.sha1(code.encode("utf-8")).hexdigest() + # Include the number and 12 characters of the hash in the name. It's + # pretty much impossible that in a single session we'll have collisions + # even with truncated hashes, and the full one makes tracebacks too long + return ''.format(number, hash_digest[:12]) + +#----------------------------------------------------------------------------- +# Classes and functions +#----------------------------------------------------------------------------- + +class CachingCompiler(codeop.Compile): + """A compiler that caches code compiled from interactive statements. + """ + + def __init__(self): + codeop.Compile.__init__(self) + + # This is ugly, but it must be done this way to allow multiple + # simultaneous ipython instances to coexist. Since Python itself + # directly accesses the data structures in the linecache module, and + # the cache therein is global, we must work with that data structure. + # We must hold a reference to the original checkcache routine and call + # that in our own check_cache() below, but the special IPython cache + # must also be shared by all IPython instances. If we were to hold + # separate caches (one in each CachingCompiler instance), any call made + # by Python itself to linecache.checkcache() would obliterate the + # cached data from the other IPython instances. + if not hasattr(linecache, '_ipython_cache'): + linecache._ipython_cache = {} + if not hasattr(linecache, '_checkcache_ori'): + linecache._checkcache_ori = linecache.checkcache + # Now, we must monkeypatch the linecache directly so that parts of the + # stdlib that call it outside our control go through our codepath + # (otherwise we'd lose our tracebacks). + linecache.checkcache = check_linecache_ipython + + def ast_parse(self, source, filename='', symbol='exec'): + """Parse code to an AST with the current compiler flags active. + + Arguments are exactly the same as ast.parse (in the standard library), + and are passed to the built-in compile function.""" + return compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1) + + def reset_compiler_flags(self): + """Reset compiler flags to default state.""" + # This value is copied from codeop.Compile.__init__, so if that ever + # changes, it will need to be updated. + self.flags = codeop.PyCF_DONT_IMPLY_DEDENT + + @property + def compiler_flags(self): + """Flags currently active in the compilation process. + """ + return self.flags + + def cache(self, code, number=0): + """Make a name for a block of code, and cache the code. + + Parameters + ---------- + code : str + The Python source code to cache. + number : int + A number which forms part of the code's name. Used for the execution + counter. + + Returns + ------- + The name of the cached code (as a string). Pass this as the filename + argument to compilation, so that tracebacks are correctly hooked up. + """ + name = code_name(code, number) + entry = (len(code), time.time(), + [line+'\n' for line in code.splitlines()], name) + linecache.cache[name] = entry + linecache._ipython_cache[name] = entry + return name + +def check_linecache_ipython(*args): + """Call linecache.checkcache() safely protecting our cached values. + """ + # First call the original checkcache as intended + linecache._checkcache_ori(*args) + # Then, update back the cache with our data, so that tracebacks related + # to our compiled codes can be produced. + linecache.cache.update(linecache._ipython_cache) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/completer.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/completer.py new file mode 100644 index 00000000..fbc25355 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/completer.py @@ -0,0 +1,2060 @@ +"""Completion for IPython. + +This module started as fork of the rlcompleter module in the Python standard +library. The original enhancements made to rlcompleter have been sent +upstream and were accepted as of Python 2.3, + +This module now support a wide variety of completion mechanism both available +for normal classic Python code, as well as completer for IPython specific +Syntax like magics. + +Latex and Unicode completion +============================ + +IPython and compatible frontends not only can complete your code, but can help +you to input a wide range of characters. In particular we allow you to insert +a unicode character using the tab completion mechanism. + +Forward latex/unicode completion +-------------------------------- + +Forward completion allows you to easily type a unicode character using its latex +name, or unicode long description. To do so type a backslash follow by the +relevant name and press tab: + + +Using latex completion: + +.. code:: + + \\alpha + α + +or using unicode completion: + + +.. code:: + + \\greek small letter alpha + α + + +Only valid Python identifiers will complete. Combining characters (like arrow or +dots) are also available, unlike latex they need to be put after the their +counterpart that is to say, `F\\\\vec` is correct, not `\\\\vecF`. + +Some browsers are known to display combining characters incorrectly. + +Backward latex completion +------------------------- + +It is sometime challenging to know how to type a character, if you are using +IPython, or any compatible frontend you can prepend backslash to the character +and press `` to expand it to its latex form. + +.. code:: + + \\α + \\alpha + + +Both forward and backward completions can be deactivated by setting the +``Completer.backslash_combining_completions`` option to ``False``. + + +Experimental +============ + +Starting with IPython 6.0, this module can make use of the Jedi library to +generate completions both using static analysis of the code, and dynamically +inspecting multiple namespaces. The APIs attached to this new mechanism is +unstable and will raise unless use in an :any:`provisionalcompleter` context +manager. + +You will find that the following are experimental: + + - :any:`provisionalcompleter` + - :any:`IPCompleter.completions` + - :any:`Completion` + - :any:`rectify_completions` + +.. note:: + + better name for :any:`rectify_completions` ? + +We welcome any feedback on these new API, and we also encourage you to try this +module in debug mode (start IPython with ``--Completer.debug=True``) in order +to have extra logging information is :any:`jedi` is crashing, or if current +IPython completer pending deprecations are returning results not yet handled +by :any:`jedi` + +Using Jedi for tab completion allow snippets like the following to work without +having to execute any code: + + >>> myvar = ['hello', 42] + ... myvar[1].bi + +Tab completion will be able to infer that ``myvar[1]`` is a real number without +executing any code unlike the previously available ``IPCompleter.greedy`` +option. + +Be sure to update :any:`jedi` to the latest stable version or to try the +current development version to get better completions. +""" + + +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. +# +# Some of this code originated from rlcompleter in the Python standard library +# Copyright (C) 2001 Python Software Foundation, www.python.org + + +import __main__ +import builtins as builtin_mod +import glob +import time +import inspect +import itertools +import keyword +import os +import re +import sys +import unicodedata +import string +import warnings + +from contextlib import contextmanager +from importlib import import_module +from typing import Iterator, List, Tuple, Iterable, Union +from types import SimpleNamespace + +from traitlets.config.configurable import Configurable +from IPython.core.error import TryNext +from IPython.core.inputsplitter import ESC_MAGIC +from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol +from IPython.core.oinspect import InspectColors +from IPython.utils import generics +from IPython.utils.dir2 import dir2, get_real_method +from IPython.utils.process import arg_split +from traitlets import Bool, Enum, observe, Int + +# skip module docstests +skip_doctest = True + +try: + import jedi + jedi.settings.case_insensitive_completion = False + import jedi.api.helpers + import jedi.api.classes + JEDI_INSTALLED = True +except ImportError: + JEDI_INSTALLED = False +#----------------------------------------------------------------------------- +# Globals +#----------------------------------------------------------------------------- + +# Public API +__all__ = ['Completer','IPCompleter'] + +if sys.platform == 'win32': + PROTECTABLES = ' ' +else: + PROTECTABLES = ' ()[]{}?=\\|;:\'#*"^&' + +# Protect against returning an enormous number of completions which the frontend +# may have trouble processing. +MATCHES_LIMIT = 500 + +_deprecation_readline_sentinel = object() + + +class ProvisionalCompleterWarning(FutureWarning): + """ + Exception raise by an experimental feature in this module. + + Wrap code in :any:`provisionalcompleter` context manager if you + are certain you want to use an unstable feature. + """ + pass + +warnings.filterwarnings('error', category=ProvisionalCompleterWarning) + +@contextmanager +def provisionalcompleter(action='ignore'): + """ + + + This contest manager has to be used in any place where unstable completer + behavior and API may be called. + + >>> with provisionalcompleter(): + ... completer.do_experimetal_things() # works + + >>> completer.do_experimental_things() # raises. + + .. note:: Unstable + + By using this context manager you agree that the API in use may change + without warning, and that you won't complain if they do so. + + You also understand that if the API is not to you liking you should report + a bug to explain your use case upstream and improve the API and will loose + credibility if you complain after the API is make stable. + + We'll be happy to get your feedback , feature request and improvement on + any of the unstable APIs ! + """ + with warnings.catch_warnings(): + warnings.filterwarnings(action, category=ProvisionalCompleterWarning) + yield + + +def has_open_quotes(s): + """Return whether a string has open quotes. + + This simply counts whether the number of quote characters of either type in + the string is odd. + + Returns + ------- + If there is an open quote, the quote character is returned. Else, return + False. + """ + # We check " first, then ', so complex cases with nested quotes will get + # the " to take precedence. + if s.count('"') % 2: + return '"' + elif s.count("'") % 2: + return "'" + else: + return False + + +def protect_filename(s, protectables=PROTECTABLES): + """Escape a string to protect certain characters.""" + if set(s) & set(protectables): + if sys.platform == "win32": + return '"' + s + '"' + else: + return "".join(("\\" + c if c in protectables else c) for c in s) + else: + return s + + +def expand_user(path:str) -> Tuple[str, bool, str]: + """Expand ``~``-style usernames in strings. + + This is similar to :func:`os.path.expanduser`, but it computes and returns + extra information that will be useful if the input was being used in + computing completions, and you wish to return the completions with the + original '~' instead of its expanded value. + + Parameters + ---------- + path : str + String to be expanded. If no ~ is present, the output is the same as the + input. + + Returns + ------- + newpath : str + Result of ~ expansion in the input path. + tilde_expand : bool + Whether any expansion was performed or not. + tilde_val : str + The value that ~ was replaced with. + """ + # Default values + tilde_expand = False + tilde_val = '' + newpath = path + + if path.startswith('~'): + tilde_expand = True + rest = len(path)-1 + newpath = os.path.expanduser(path) + if rest: + tilde_val = newpath[:-rest] + else: + tilde_val = newpath + + return newpath, tilde_expand, tilde_val + + +def compress_user(path:str, tilde_expand:bool, tilde_val:str) -> str: + """Does the opposite of expand_user, with its outputs. + """ + if tilde_expand: + return path.replace(tilde_val, '~') + else: + return path + + +def completions_sorting_key(word): + """key for sorting completions + + This does several things: + + - Demote any completions starting with underscores to the end + - Insert any %magic and %%cellmagic completions in the alphabetical order + by their name + """ + prio1, prio2 = 0, 0 + + if word.startswith('__'): + prio1 = 2 + elif word.startswith('_'): + prio1 = 1 + + if word.endswith('='): + prio1 = -1 + + if word.startswith('%%'): + # If there's another % in there, this is something else, so leave it alone + if not "%" in word[2:]: + word = word[2:] + prio2 = 2 + elif word.startswith('%'): + if not "%" in word[1:]: + word = word[1:] + prio2 = 1 + + return prio1, word, prio2 + + +class _FakeJediCompletion: + """ + This is a workaround to communicate to the UI that Jedi has crashed and to + report a bug. Will be used only id :any:`IPCompleter.debug` is set to true. + + Added in IPython 6.0 so should likely be removed for 7.0 + + """ + + def __init__(self, name): + + self.name = name + self.complete = name + self.type = 'crashed' + self.name_with_symbols = name + self.signature = '' + self._origin = 'fake' + + def __repr__(self): + return '' + + +class Completion: + """ + Completion object used and return by IPython completers. + + .. warning:: Unstable + + This function is unstable, API may change without warning. + It will also raise unless use in proper context manager. + + This act as a middle ground :any:`Completion` object between the + :any:`jedi.api.classes.Completion` object and the Prompt Toolkit completion + object. While Jedi need a lot of information about evaluator and how the + code should be ran/inspected, PromptToolkit (and other frontend) mostly + need user facing information. + + - Which range should be replaced replaced by what. + - Some metadata (like completion type), or meta information to displayed to + the use user. + + For debugging purpose we can also store the origin of the completion (``jedi``, + ``IPython.python_matches``, ``IPython.magics_matches``...). + """ + + __slots__ = ['start', 'end', 'text', 'type', 'signature', '_origin'] + + def __init__(self, start: int, end: int, text: str, *, type: str=None, _origin='', signature='') -> None: + warnings.warn("``Completion`` is a provisional API (as of IPython 6.0). " + "It may change without warnings. " + "Use in corresponding context manager.", + category=ProvisionalCompleterWarning, stacklevel=2) + + self.start = start + self.end = end + self.text = text + self.type = type + self.signature = signature + self._origin = _origin + + def __repr__(self): + return '' % \ + (self.start, self.end, self.text, self.type or '?', self.signature or '?') + + def __eq__(self, other)->Bool: + """ + Equality and hash do not hash the type (as some completer may not be + able to infer the type), but are use to (partially) de-duplicate + completion. + + Completely de-duplicating completion is a bit tricker that just + comparing as it depends on surrounding text, which Completions are not + aware of. + """ + return self.start == other.start and \ + self.end == other.end and \ + self.text == other.text + + def __hash__(self): + return hash((self.start, self.end, self.text)) + + +_IC = Iterable[Completion] + + +def _deduplicate_completions(text: str, completions: _IC)-> _IC: + """ + Deduplicate a set of completions. + + .. warning:: Unstable + + This function is unstable, API may change without warning. + + Parameters + ---------- + text: str + text that should be completed. + completions: Iterator[Completion] + iterator over the completions to deduplicate + + Yields + ------ + `Completions` objects + + + Completions coming from multiple sources, may be different but end up having + the same effect when applied to ``text``. If this is the case, this will + consider completions as equal and only emit the first encountered. + + Not folded in `completions()` yet for debugging purpose, and to detect when + the IPython completer does return things that Jedi does not, but should be + at some point. + """ + completions = list(completions) + if not completions: + return + + new_start = min(c.start for c in completions) + new_end = max(c.end for c in completions) + + seen = set() + for c in completions: + new_text = text[new_start:c.start] + c.text + text[c.end:new_end] + if new_text not in seen: + yield c + seen.add(new_text) + + +def rectify_completions(text: str, completions: _IC, *, _debug=False)->_IC: + """ + Rectify a set of completions to all have the same ``start`` and ``end`` + + .. warning:: Unstable + + This function is unstable, API may change without warning. + It will also raise unless use in proper context manager. + + Parameters + ---------- + text: str + text that should be completed. + completions: Iterator[Completion] + iterator over the completions to rectify + + + :any:`jedi.api.classes.Completion` s returned by Jedi may not have the same start and end, though + the Jupyter Protocol requires them to behave like so. This will readjust + the completion to have the same ``start`` and ``end`` by padding both + extremities with surrounding text. + + During stabilisation should support a ``_debug`` option to log which + completion are return by the IPython completer and not found in Jedi in + order to make upstream bug report. + """ + warnings.warn("`rectify_completions` is a provisional API (as of IPython 6.0). " + "It may change without warnings. " + "Use in corresponding context manager.", + category=ProvisionalCompleterWarning, stacklevel=2) + + completions = list(completions) + if not completions: + return + starts = (c.start for c in completions) + ends = (c.end for c in completions) + + new_start = min(starts) + new_end = max(ends) + + seen_jedi = set() + seen_python_matches = set() + for c in completions: + new_text = text[new_start:c.start] + c.text + text[c.end:new_end] + if c._origin == 'jedi': + seen_jedi.add(new_text) + elif c._origin == 'IPCompleter.python_matches': + seen_python_matches.add(new_text) + yield Completion(new_start, new_end, new_text, type=c.type, _origin=c._origin, signature=c.signature) + diff = seen_python_matches.difference(seen_jedi) + if diff and _debug: + print('IPython.python matches have extras:', diff) + + +if sys.platform == 'win32': + DELIMS = ' \t\n`!@#$^&*()=+[{]}|;\'",<>?' +else: + DELIMS = ' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?' + +GREEDY_DELIMS = ' =\r\n' + + +class CompletionSplitter(object): + """An object to split an input line in a manner similar to readline. + + By having our own implementation, we can expose readline-like completion in + a uniform manner to all frontends. This object only needs to be given the + line of text to be split and the cursor position on said line, and it + returns the 'word' to be completed on at the cursor after splitting the + entire line. + + What characters are used as splitting delimiters can be controlled by + setting the ``delims`` attribute (this is a property that internally + automatically builds the necessary regular expression)""" + + # Private interface + + # A string of delimiter characters. The default value makes sense for + # IPython's most typical usage patterns. + _delims = DELIMS + + # The expression (a normal string) to be compiled into a regular expression + # for actual splitting. We store it as an attribute mostly for ease of + # debugging, since this type of code can be so tricky to debug. + _delim_expr = None + + # The regular expression that does the actual splitting + _delim_re = None + + def __init__(self, delims=None): + delims = CompletionSplitter._delims if delims is None else delims + self.delims = delims + + @property + def delims(self): + """Return the string of delimiter characters.""" + return self._delims + + @delims.setter + def delims(self, delims): + """Set the delimiters for line splitting.""" + expr = '[' + ''.join('\\'+ c for c in delims) + ']' + self._delim_re = re.compile(expr) + self._delims = delims + self._delim_expr = expr + + def split_line(self, line, cursor_pos=None): + """Split a line of text with a cursor at the given position. + """ + l = line if cursor_pos is None else line[:cursor_pos] + return self._delim_re.split(l)[-1] + + + +class Completer(Configurable): + + greedy = Bool(False, + help="""Activate greedy completion + PENDING DEPRECTION. this is now mostly taken care of with Jedi. + + This will enable completion on elements of lists, results of function calls, etc., + but can be unsafe because the code is actually evaluated on TAB. + """ + ).tag(config=True) + + use_jedi = Bool(default_value=False, + help="Experimental: Use Jedi to generate autocompletions. " + "Off by default.").tag(config=True) + + jedi_compute_type_timeout = Int(default_value=400, + help="""Experimental: restrict time (in milliseconds) during which Jedi can compute types. + Set to 0 to stop computing types. Non-zero value lower than 100ms may hurt + performance by preventing jedi to build its cache. + """).tag(config=True) + + debug = Bool(default_value=False, + help='Enable debug for the Completer. Mostly print extra ' + 'information for experimental jedi integration.')\ + .tag(config=True) + + backslash_combining_completions = Bool(True, + help="Enable unicode completions, e.g. \\alpha . " + "Includes completion of latex commands, unicode names, and expanding " + "unicode characters back to latex commands.").tag(config=True) + + + + def __init__(self, namespace=None, global_namespace=None, **kwargs): + """Create a new completer for the command line. + + Completer(namespace=ns, global_namespace=ns2) -> completer instance. + + If unspecified, the default namespace where completions are performed + is __main__ (technically, __main__.__dict__). Namespaces should be + given as dictionaries. + + An optional second namespace can be given. This allows the completer + to handle cases where both the local and global scopes need to be + distinguished. + """ + + # Don't bind to namespace quite yet, but flag whether the user wants a + # specific namespace or to use __main__.__dict__. This will allow us + # to bind to __main__.__dict__ at completion time, not now. + if namespace is None: + self.use_main_ns = True + else: + self.use_main_ns = False + self.namespace = namespace + + # The global namespace, if given, can be bound directly + if global_namespace is None: + self.global_namespace = {} + else: + self.global_namespace = global_namespace + + super(Completer, self).__init__(**kwargs) + + def complete(self, text, state): + """Return the next possible completion for 'text'. + + This is called successively with state == 0, 1, 2, ... until it + returns None. The completion should begin with 'text'. + + """ + if self.use_main_ns: + self.namespace = __main__.__dict__ + + if state == 0: + if "." in text: + self.matches = self.attr_matches(text) + else: + self.matches = self.global_matches(text) + try: + return self.matches[state] + except IndexError: + return None + + def global_matches(self, text): + """Compute matches when text is a simple name. + + Return a list of all keywords, built-in functions and names currently + defined in self.namespace or self.global_namespace that match. + + """ + matches = [] + match_append = matches.append + n = len(text) + for lst in [keyword.kwlist, + builtin_mod.__dict__.keys(), + self.namespace.keys(), + self.global_namespace.keys()]: + for word in lst: + if word[:n] == text and word != "__builtins__": + match_append(word) + + snake_case_re = re.compile(r"[^_]+(_[^_]+)+?\Z") + for lst in [self.namespace.keys(), + self.global_namespace.keys()]: + shortened = {"_".join([sub[0] for sub in word.split('_')]) : word + for word in lst if snake_case_re.match(word)} + for word in shortened.keys(): + if word[:n] == text and word != "__builtins__": + match_append(shortened[word]) + return matches + + def attr_matches(self, text): + """Compute matches when text contains a dot. + + Assuming the text is of the form NAME.NAME....[NAME], and is + evaluatable in self.namespace or self.global_namespace, it will be + evaluated and its attributes (as revealed by dir()) are used as + possible completions. (For class instances, class members are + also considered.) + + WARNING: this can still invoke arbitrary C code, if an object + with a __getattr__ hook is evaluated. + + """ + + # Another option, seems to work great. Catches things like ''. + m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) + + if m: + expr, attr = m.group(1, 3) + elif self.greedy: + m2 = re.match(r"(.+)\.(\w*)$", self.line_buffer) + if not m2: + return [] + expr, attr = m2.group(1,2) + else: + return [] + + try: + obj = eval(expr, self.namespace) + except: + try: + obj = eval(expr, self.global_namespace) + except: + return [] + + if self.limit_to__all__ and hasattr(obj, '__all__'): + words = get__all__entries(obj) + else: + words = dir2(obj) + + try: + words = generics.complete_object(obj, words) + except TryNext: + pass + except AssertionError: + raise + except Exception: + # Silence errors from completion function + #raise # dbg + pass + # Build match list to return + n = len(attr) + return [u"%s.%s" % (expr, w) for w in words if w[:n] == attr ] + + +def get__all__entries(obj): + """returns the strings in the __all__ attribute""" + try: + words = getattr(obj, '__all__') + except: + return [] + + return [w for w in words if isinstance(w, str)] + + +def match_dict_keys(keys: List[str], prefix: str, delims: str): + """Used by dict_key_matches, matching the prefix to a list of keys + + Parameters + ========== + keys: + list of keys in dictionary currently being completed. + prefix: + Part of the text already typed by the user. e.g. `mydict[b'fo` + delims: + String of delimiters to consider when finding the current key. + + Returns + ======= + + A tuple of three elements: ``quote``, ``token_start``, ``matched``, with + ``quote`` being the quote that need to be used to close current string. + ``token_start`` the position where the replacement should start occurring, + ``matches`` a list of replacement/completion + + """ + if not prefix: + return None, 0, [repr(k) for k in keys + if isinstance(k, (str, bytes))] + quote_match = re.search('["\']', prefix) + quote = quote_match.group() + try: + prefix_str = eval(prefix + quote, {}) + except Exception: + return None, 0, [] + + pattern = '[^' + ''.join('\\' + c for c in delims) + ']*$' + token_match = re.search(pattern, prefix, re.UNICODE) + token_start = token_match.start() + token_prefix = token_match.group() + + matched = [] + for key in keys: + try: + if not key.startswith(prefix_str): + continue + except (AttributeError, TypeError, UnicodeError): + # Python 3+ TypeError on b'a'.startswith('a') or vice-versa + continue + + # reformat remainder of key to begin with prefix + rem = key[len(prefix_str):] + # force repr wrapped in ' + rem_repr = repr(rem + '"') if isinstance(rem, str) else repr(rem + b'"') + if rem_repr.startswith('u') and prefix[0] not in 'uU': + # Found key is unicode, but prefix is Py2 string. + # Therefore attempt to interpret key as string. + try: + rem_repr = repr(rem.encode('ascii') + '"') + except UnicodeEncodeError: + continue + + rem_repr = rem_repr[1 + rem_repr.index("'"):-2] + if quote == '"': + # The entered prefix is quoted with ", + # but the match is quoted with '. + # A contained " hence needs escaping for comparison: + rem_repr = rem_repr.replace('"', '\\"') + + # then reinsert prefix from start of token + matched.append('%s%s' % (token_prefix, rem_repr)) + return quote, token_start, matched + + +def cursor_to_position(text:str, line:int, column:int)->int: + """ + + Convert the (line,column) position of the cursor in text to an offset in a + string. + + Parameters + ---------- + + text : str + The text in which to calculate the cursor offset + line : int + Line of the cursor; 0-indexed + column : int + Column of the cursor 0-indexed + + Return + ------ + Position of the cursor in ``text``, 0-indexed. + + See Also + -------- + position_to_cursor: reciprocal of this function + + """ + lines = text.split('\n') + assert line <= len(lines), '{} <= {}'.format(str(line), str(len(lines))) + + return sum(len(l) + 1 for l in lines[:line]) + column + +def position_to_cursor(text:str, offset:int)->Tuple[int, int]: + """ + Convert the position of the cursor in text (0 indexed) to a line + number(0-indexed) and a column number (0-indexed) pair + + Position should be a valid position in ``text``. + + Parameters + ---------- + + text : str + The text in which to calculate the cursor offset + offset : int + Position of the cursor in ``text``, 0-indexed. + + Return + ------ + (line, column) : (int, int) + Line of the cursor; 0-indexed, column of the cursor 0-indexed + + + See Also + -------- + cursor_to_position : reciprocal of this function + + + """ + + assert 0 <= offset <= len(text) , "0 <= %s <= %s" % (offset , len(text)) + + before = text[:offset] + blines = before.split('\n') # ! splitnes trim trailing \n + line = before.count('\n') + col = len(blines[-1]) + return line, col + + +def _safe_isinstance(obj, module, class_name): + """Checks if obj is an instance of module.class_name if loaded + """ + return (module in sys.modules and + isinstance(obj, getattr(import_module(module), class_name))) + + +def back_unicode_name_matches(text): + u"""Match unicode characters back to unicode name + + This does ``☃`` -> ``\\snowman`` + + Note that snowman is not a valid python3 combining character but will be expanded. + Though it will not recombine back to the snowman character by the completion machinery. + + This will not either back-complete standard sequences like \\n, \\b ... + + Used on Python 3 only. + """ + if len(text)<2: + return u'', () + maybe_slash = text[-2] + if maybe_slash != '\\': + return u'', () + + char = text[-1] + # no expand on quote for completion in strings. + # nor backcomplete standard ascii keys + if char in string.ascii_letters or char in ['"',"'"]: + return u'', () + try : + unic = unicodedata.name(char) + return '\\'+char,['\\'+unic] + except KeyError: + pass + return u'', () + +def back_latex_name_matches(text:str): + """Match latex characters back to unicode name + + This does ``\\ℵ`` -> ``\\aleph`` + + Used on Python 3 only. + """ + if len(text)<2: + return u'', () + maybe_slash = text[-2] + if maybe_slash != '\\': + return u'', () + + + char = text[-1] + # no expand on quote for completion in strings. + # nor backcomplete standard ascii keys + if char in string.ascii_letters or char in ['"',"'"]: + return u'', () + try : + latex = reverse_latex_symbol[char] + # '\\' replace the \ as well + return '\\'+char,[latex] + except KeyError: + pass + return u'', () + + +def _formatparamchildren(parameter) -> str: + """ + Get parameter name and value from Jedi Private API + + Jedi does not expose a simple way to get `param=value` from its API. + + Parameter + ========= + + parameter: + Jedi's function `Param` + + Returns + ======= + + A string like 'a', 'b=1', '*args', '**kwargs' + + + """ + description = parameter.description + if not description.startswith('param '): + raise ValueError('Jedi function parameter description have change format.' + 'Expected "param ...", found %r".' % description) + return description[6:] + +def _make_signature(completion)-> str: + """ + Make the signature from a jedi completion + + Parameter + ========= + + completion: jedi.Completion + object does not complete a function type + + Returns + ======= + + a string consisting of the function signature, with the parenthesis but + without the function name. example: + `(a, *args, b=1, **kwargs)` + + """ + + return '(%s)'% ', '.join([f for f in (_formatparamchildren(p) for p in completion.params) if f]) + +class IPCompleter(Completer): + """Extension of the completer class with IPython-specific features""" + + @observe('greedy') + def _greedy_changed(self, change): + """update the splitter and readline delims when greedy is changed""" + if change['new']: + self.splitter.delims = GREEDY_DELIMS + else: + self.splitter.delims = DELIMS + + merge_completions = Bool(True, + help="""Whether to merge completion results into a single list + + If False, only the completion results from the first non-empty + completer will be returned. + """ + ).tag(config=True) + omit__names = Enum((0,1,2), default_value=2, + help="""Instruct the completer to omit private method names + + Specifically, when completing on ``object.``. + + When 2 [default]: all names that start with '_' will be excluded. + + When 1: all 'magic' names (``__foo__``) will be excluded. + + When 0: nothing will be excluded. + """ + ).tag(config=True) + limit_to__all__ = Bool(False, + help=""" + DEPRECATED as of version 5.0. + + Instruct the completer to use __all__ for the completion + + Specifically, when completing on ``object.``. + + When True: only those names in obj.__all__ will be included. + + When False [default]: the __all__ attribute is ignored + """, + ).tag(config=True) + + @observe('limit_to__all__') + def _limit_to_all_changed(self, change): + warnings.warn('`IPython.core.IPCompleter.limit_to__all__` configuration ' + 'value has been deprecated since IPython 5.0, will be made to have ' + 'no effects and then removed in future version of IPython.', + UserWarning) + + def __init__(self, shell=None, namespace=None, global_namespace=None, + use_readline=_deprecation_readline_sentinel, config=None, **kwargs): + """IPCompleter() -> completer + + Return a completer object. + + Parameters + ---------- + + shell + a pointer to the ipython shell itself. This is needed + because this completer knows about magic functions, and those can + only be accessed via the ipython instance. + + namespace : dict, optional + an optional dict where completions are performed. + + global_namespace : dict, optional + secondary optional dict for completions, to + handle cases (such as IPython embedded inside functions) where + both Python scopes are visible. + + use_readline : bool, optional + DEPRECATED, ignored since IPython 6.0, will have no effects + """ + + self.magic_escape = ESC_MAGIC + self.splitter = CompletionSplitter() + + if use_readline is not _deprecation_readline_sentinel: + warnings.warn('The `use_readline` parameter is deprecated and ignored since IPython 6.0.', + DeprecationWarning, stacklevel=2) + + # _greedy_changed() depends on splitter and readline being defined: + Completer.__init__(self, namespace=namespace, global_namespace=global_namespace, + config=config, **kwargs) + + # List where completion matches will be stored + self.matches = [] + self.shell = shell + # Regexp to split filenames with spaces in them + self.space_name_re = re.compile(r'([^\\] )') + # Hold a local ref. to glob.glob for speed + self.glob = glob.glob + + # Determine if we are running on 'dumb' terminals, like (X)Emacs + # buffers, to avoid completion problems. + term = os.environ.get('TERM','xterm') + self.dumb_terminal = term in ['dumb','emacs'] + + # Special handling of backslashes needed in win32 platforms + if sys.platform == "win32": + self.clean_glob = self._clean_glob_win32 + else: + self.clean_glob = self._clean_glob + + #regexp to parse docstring for function signature + self.docstring_sig_re = re.compile(r'^[\w|\s.]+\(([^)]*)\).*') + self.docstring_kwd_re = re.compile(r'[\s|\[]*(\w+)(?:\s*=\s*.*)') + #use this if positional argument name is also needed + #= re.compile(r'[\s|\[]*(\w+)(?:\s*=?\s*.*)') + + self.magic_arg_matchers = [ + self.magic_config_matches, + self.magic_color_matches, + ] + + # This is set externally by InteractiveShell + self.custom_completers = None + + @property + def matchers(self): + """All active matcher routines for completion""" + if self.use_jedi: + return [ + self.file_matches, + self.magic_matches, + self.dict_key_matches, + ] + else: + return [ + self.python_matches, + self.file_matches, + self.magic_matches, + self.python_func_kw_matches, + self.dict_key_matches, + ] + + def all_completions(self, text): + """ + Wrapper around the complete method for the benefit of emacs. + """ + return self.complete(text)[1] + + def _clean_glob(self, text): + return self.glob("%s*" % text) + + def _clean_glob_win32(self,text): + return [f.replace("\\","/") + for f in self.glob("%s*" % text)] + + def file_matches(self, text): + """Match filenames, expanding ~USER type strings. + + Most of the seemingly convoluted logic in this completer is an + attempt to handle filenames with spaces in them. And yet it's not + quite perfect, because Python's readline doesn't expose all of the + GNU readline details needed for this to be done correctly. + + For a filename with a space in it, the printed completions will be + only the parts after what's already been typed (instead of the + full completions, as is normally done). I don't think with the + current (as of Python 2.3) Python readline it's possible to do + better.""" + + # chars that require escaping with backslash - i.e. chars + # that readline treats incorrectly as delimiters, but we + # don't want to treat as delimiters in filename matching + # when escaped with backslash + if text.startswith('!'): + text = text[1:] + text_prefix = u'!' + else: + text_prefix = u'' + + text_until_cursor = self.text_until_cursor + # track strings with open quotes + open_quotes = has_open_quotes(text_until_cursor) + + if '(' in text_until_cursor or '[' in text_until_cursor: + lsplit = text + else: + try: + # arg_split ~ shlex.split, but with unicode bugs fixed by us + lsplit = arg_split(text_until_cursor)[-1] + except ValueError: + # typically an unmatched ", or backslash without escaped char. + if open_quotes: + lsplit = text_until_cursor.split(open_quotes)[-1] + else: + return [] + except IndexError: + # tab pressed on empty line + lsplit = "" + + if not open_quotes and lsplit != protect_filename(lsplit): + # if protectables are found, do matching on the whole escaped name + has_protectables = True + text0,text = text,lsplit + else: + has_protectables = False + text = os.path.expanduser(text) + + if text == "": + return [text_prefix + protect_filename(f) for f in self.glob("*")] + + # Compute the matches from the filesystem + if sys.platform == 'win32': + m0 = self.clean_glob(text) + else: + m0 = self.clean_glob(text.replace('\\', '')) + + if has_protectables: + # If we had protectables, we need to revert our changes to the + # beginning of filename so that we don't double-write the part + # of the filename we have so far + len_lsplit = len(lsplit) + matches = [text_prefix + text0 + + protect_filename(f[len_lsplit:]) for f in m0] + else: + if open_quotes: + # if we have a string with an open quote, we don't need to + # protect the names beyond the quote (and we _shouldn't_, as + # it would cause bugs when the filesystem call is made). + matches = m0 if sys.platform == "win32" else\ + [protect_filename(f, open_quotes) for f in m0] + else: + matches = [text_prefix + + protect_filename(f) for f in m0] + + # Mark directories in input list by appending '/' to their names. + return [x+'/' if os.path.isdir(x) else x for x in matches] + + def magic_matches(self, text): + """Match magics""" + # Get all shell magics now rather than statically, so magics loaded at + # runtime show up too. + lsm = self.shell.magics_manager.lsmagic() + line_magics = lsm['line'] + cell_magics = lsm['cell'] + pre = self.magic_escape + pre2 = pre+pre + + explicit_magic = text.startswith(pre) + + # Completion logic: + # - user gives %%: only do cell magics + # - user gives %: do both line and cell magics + # - no prefix: do both + # In other words, line magics are skipped if the user gives %% explicitly + # + # We also exclude magics that match any currently visible names: + # https://github.com/ipython/ipython/issues/4877, unless the user has + # typed a %: + # https://github.com/ipython/ipython/issues/10754 + bare_text = text.lstrip(pre) + global_matches = self.global_matches(bare_text) + if not explicit_magic: + def matches(magic): + """ + Filter magics, in particular remove magics that match + a name present in global namespace. + """ + return ( magic.startswith(bare_text) and + magic not in global_matches ) + else: + def matches(magic): + return magic.startswith(bare_text) + + comp = [ pre2+m for m in cell_magics if matches(m)] + if not text.startswith(pre2): + comp += [ pre+m for m in line_magics if matches(m)] + + return comp + + def magic_config_matches(self, text:str) -> List[str]: + """ Match class names and attributes for %config magic """ + texts = text.strip().split() + + if len(texts) > 0 and (texts[0] == 'config' or texts[0] == '%config'): + # get all configuration classes + classes = sorted(set([ c for c in self.shell.configurables + if c.__class__.class_traits(config=True) + ]), key=lambda x: x.__class__.__name__) + classnames = [ c.__class__.__name__ for c in classes ] + + # return all classnames if config or %config is given + if len(texts) == 1: + return classnames + + # match classname + classname_texts = texts[1].split('.') + classname = classname_texts[0] + classname_matches = [ c for c in classnames + if c.startswith(classname) ] + + # return matched classes or the matched class with attributes + if texts[1].find('.') < 0: + return classname_matches + elif len(classname_matches) == 1 and \ + classname_matches[0] == classname: + cls = classes[classnames.index(classname)].__class__ + help = cls.class_get_help() + # strip leading '--' from cl-args: + help = re.sub(re.compile(r'^--', re.MULTILINE), '', help) + return [ attr.split('=')[0] + for attr in help.strip().splitlines() + if attr.startswith(texts[1]) ] + return [] + + def magic_color_matches(self, text:str) -> List[str] : + """ Match color schemes for %colors magic""" + texts = text.split() + if text.endswith(' '): + # .split() strips off the trailing whitespace. Add '' back + # so that: '%colors ' -> ['%colors', ''] + texts.append('') + + if len(texts) == 2 and (texts[0] == 'colors' or texts[0] == '%colors'): + prefix = texts[1] + return [ color for color in InspectColors.keys() + if color.startswith(prefix) ] + return [] + + def _jedi_matches(self, cursor_column:int, cursor_line:int, text:str): + """ + + Return a list of :any:`jedi.api.Completions` object from a ``text`` and + cursor position. + + Parameters + ---------- + cursor_column : int + column position of the cursor in ``text``, 0-indexed. + cursor_line : int + line position of the cursor in ``text``, 0-indexed + text : str + text to complete + + Debugging + --------- + + If ``IPCompleter.debug`` is ``True`` may return a :any:`_FakeJediCompletion` + object containing a string with the Jedi debug information attached. + """ + namespaces = [self.namespace] + if self.global_namespace is not None: + namespaces.append(self.global_namespace) + + completion_filter = lambda x:x + offset = cursor_to_position(text, cursor_line, cursor_column) + # filter output if we are completing for object members + if offset: + pre = text[offset-1] + if pre == '.': + if self.omit__names == 2: + completion_filter = lambda c:not c.name.startswith('_') + elif self.omit__names == 1: + completion_filter = lambda c:not (c.name.startswith('__') and c.name.endswith('__')) + elif self.omit__names == 0: + completion_filter = lambda x:x + else: + raise ValueError("Don't understand self.omit__names == {}".format(self.omit__names)) + + interpreter = jedi.Interpreter( + text[:offset], namespaces, column=cursor_column, line=cursor_line + 1) + try_jedi = True + + try: + # should we check the type of the node is Error ? + try: + # jedi < 0.11 + from jedi.parser.tree import ErrorLeaf + except ImportError: + # jedi >= 0.11 + from parso.tree import ErrorLeaf + + next_to_last_tree = interpreter._get_module().tree_node.children[-2] + completing_string = False + if isinstance(next_to_last_tree, ErrorLeaf): + completing_string = next_to_last_tree.value.lstrip()[0] in {'"', "'"} + # if we are in a string jedi is likely not the right candidate for + # now. Skip it. + try_jedi = not completing_string + except Exception as e: + # many of things can go wrong, we are using private API just don't crash. + if self.debug: + print("Error detecting if completing a non-finished string :", e, '|') + + if not try_jedi: + return [] + try: + return filter(completion_filter, interpreter.completions()) + except Exception as e: + if self.debug: + return [_FakeJediCompletion('Oops Jedi has crashed, please report a bug with the following:\n"""\n%s\ns"""' % (e))] + else: + return [] + + def python_matches(self, text): + """Match attributes or global python names""" + if "." in text: + try: + matches = self.attr_matches(text) + if text.endswith('.') and self.omit__names: + if self.omit__names == 1: + # true if txt is _not_ a __ name, false otherwise: + no__name = (lambda txt: + re.match(r'.*\.__.*?__',txt) is None) + else: + # true if txt is _not_ a _ name, false otherwise: + no__name = (lambda txt: + re.match(r'\._.*?',txt[txt.rindex('.'):]) is None) + matches = filter(no__name, matches) + except NameError: + # catches . + matches = [] + else: + matches = self.global_matches(text) + return matches + + def _default_arguments_from_docstring(self, doc): + """Parse the first line of docstring for call signature. + + Docstring should be of the form 'min(iterable[, key=func])\n'. + It can also parse cython docstring of the form + 'Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)'. + """ + if doc is None: + return [] + + #care only the firstline + line = doc.lstrip().splitlines()[0] + + #p = re.compile(r'^[\w|\s.]+\(([^)]*)\).*') + #'min(iterable[, key=func])\n' -> 'iterable[, key=func]' + sig = self.docstring_sig_re.search(line) + if sig is None: + return [] + # iterable[, key=func]' -> ['iterable[' ,' key=func]'] + sig = sig.groups()[0].split(',') + ret = [] + for s in sig: + #re.compile(r'[\s|\[]*(\w+)(?:\s*=\s*.*)') + ret += self.docstring_kwd_re.findall(s) + return ret + + def _default_arguments(self, obj): + """Return the list of default arguments of obj if it is callable, + or empty list otherwise.""" + call_obj = obj + ret = [] + if inspect.isbuiltin(obj): + pass + elif not (inspect.isfunction(obj) or inspect.ismethod(obj)): + if inspect.isclass(obj): + #for cython embedsignature=True the constructor docstring + #belongs to the object itself not __init__ + ret += self._default_arguments_from_docstring( + getattr(obj, '__doc__', '')) + # for classes, check for __init__,__new__ + call_obj = (getattr(obj, '__init__', None) or + getattr(obj, '__new__', None)) + # for all others, check if they are __call__able + elif hasattr(obj, '__call__'): + call_obj = obj.__call__ + ret += self._default_arguments_from_docstring( + getattr(call_obj, '__doc__', '')) + + _keeps = (inspect.Parameter.KEYWORD_ONLY, + inspect.Parameter.POSITIONAL_OR_KEYWORD) + + try: + sig = inspect.signature(call_obj) + ret.extend(k for k, v in sig.parameters.items() if + v.kind in _keeps) + except ValueError: + pass + + return list(set(ret)) + + def python_func_kw_matches(self,text): + """Match named parameters (kwargs) of the last open function""" + + if "." in text: # a parameter cannot be dotted + return [] + try: regexp = self.__funcParamsRegex + except AttributeError: + regexp = self.__funcParamsRegex = re.compile(r''' + '.*?(?,a=1)", the candidate is "foo" + tokens = regexp.findall(self.text_until_cursor) + iterTokens = reversed(tokens); openPar = 0 + + for token in iterTokens: + if token == ')': + openPar -= 1 + elif token == '(': + openPar += 1 + if openPar > 0: + # found the last unclosed parenthesis + break + else: + return [] + # 2. Concatenate dotted names ("foo.bar" for "foo.bar(x, pa" ) + ids = [] + isId = re.compile(r'\w+$').match + + while True: + try: + ids.append(next(iterTokens)) + if not isId(ids[-1]): + ids.pop(); break + if not next(iterTokens) == '.': + break + except StopIteration: + break + + # Find all named arguments already assigned to, as to avoid suggesting + # them again + usedNamedArgs = set() + par_level = -1 + for token, next_token in zip(tokens, tokens[1:]): + if token == '(': + par_level += 1 + elif token == ')': + par_level -= 1 + + if par_level != 0: + continue + + if next_token != '=': + continue + + usedNamedArgs.add(token) + + # lookup the candidate callable matches either using global_matches + # or attr_matches for dotted names + if len(ids) == 1: + callableMatches = self.global_matches(ids[0]) + else: + callableMatches = self.attr_matches('.'.join(ids[::-1])) + argMatches = [] + for callableMatch in callableMatches: + try: + namedArgs = self._default_arguments(eval(callableMatch, + self.namespace)) + except: + continue + + # Remove used named arguments from the list, no need to show twice + for namedArg in set(namedArgs) - usedNamedArgs: + if namedArg.startswith(text): + argMatches.append(u"%s=" %namedArg) + return argMatches + + def dict_key_matches(self, text): + "Match string keys in a dictionary, after e.g. 'foo[' " + def get_keys(obj): + # Objects can define their own completions by defining an + # _ipy_key_completions_() method. + method = get_real_method(obj, '_ipython_key_completions_') + if method is not None: + return method() + + # Special case some common in-memory dict-like types + if isinstance(obj, dict) or\ + _safe_isinstance(obj, 'pandas', 'DataFrame'): + try: + return list(obj.keys()) + except Exception: + return [] + elif _safe_isinstance(obj, 'numpy', 'ndarray') or\ + _safe_isinstance(obj, 'numpy', 'void'): + return obj.dtype.names or [] + return [] + + try: + regexps = self.__dict_key_regexps + except AttributeError: + dict_key_re_fmt = r'''(?x) + ( # match dict-referring expression wrt greedy setting + %s + ) + \[ # open bracket + \s* # and optional whitespace + ([uUbB]? # string prefix (r not handled) + (?: # unclosed string + '(?:[^']|(? key_start: + leading = '' + else: + leading = text[text_start:completion_start] + + # the index of the `[` character + bracket_idx = match.end(1) + + # append closing quote and bracket as appropriate + # this is *not* appropriate if the opening quote or bracket is outside + # the text given to this method + suf = '' + continuation = self.line_buffer[len(self.text_until_cursor):] + if key_start > text_start and closing_quote: + # quotes were opened inside text, maybe close them + if continuation.startswith(closing_quote): + continuation = continuation[len(closing_quote):] + else: + suf += closing_quote + if bracket_idx > text_start: + # brackets were opened inside text, maybe close them + if not continuation.startswith(']'): + suf += ']' + + return [leading + k + suf for k in matches] + + def unicode_name_matches(self, text): + u"""Match Latex-like syntax for unicode characters base + on the name of the character. + + This does ``\\GREEK SMALL LETTER ETA`` -> ``η`` + + Works only on valid python 3 identifier, or on combining characters that + will combine to form a valid identifier. + + Used on Python 3 only. + """ + slashpos = text.rfind('\\') + if slashpos > -1: + s = text[slashpos+1:] + try : + unic = unicodedata.lookup(s) + # allow combining chars + if ('a'+unic).isidentifier(): + return '\\'+s,[unic] + except KeyError: + pass + return u'', [] + + + def latex_matches(self, text): + u"""Match Latex syntax for unicode characters. + + This does both ``\\alp`` -> ``\\alpha`` and ``\\alpha`` -> ``α`` + + Used on Python 3 only. + """ + slashpos = text.rfind('\\') + if slashpos > -1: + s = text[slashpos:] + if s in latex_symbols: + # Try to complete a full latex symbol to unicode + # \\alpha -> α + return s, [latex_symbols[s]] + else: + # If a user has partially typed a latex symbol, give them + # a full list of options \al -> [\aleph, \alpha] + matches = [k for k in latex_symbols if k.startswith(s)] + return s, matches + return u'', [] + + def dispatch_custom_completer(self, text): + if not self.custom_completers: + return + + line = self.line_buffer + if not line.strip(): + return None + + # Create a little structure to pass all the relevant information about + # the current completion to any custom completer. + event = SimpleNamespace() + event.line = line + event.symbol = text + cmd = line.split(None,1)[0] + event.command = cmd + event.text_until_cursor = self.text_until_cursor + + # for foo etc, try also to find completer for %foo + if not cmd.startswith(self.magic_escape): + try_magic = self.custom_completers.s_matches( + self.magic_escape + cmd) + else: + try_magic = [] + + for c in itertools.chain(self.custom_completers.s_matches(cmd), + try_magic, + self.custom_completers.flat_matches(self.text_until_cursor)): + try: + res = c(event) + if res: + # first, try case sensitive match + withcase = [r for r in res if r.startswith(text)] + if withcase: + return withcase + # if none, then case insensitive ones are ok too + text_low = text.lower() + return [r for r in res if r.lower().startswith(text_low)] + except TryNext: + pass + except KeyboardInterrupt: + """ + If custom completer take too long, + let keyboard interrupt abort and return nothing. + """ + break + + return None + + def completions(self, text: str, offset: int)->Iterator[Completion]: + """ + Returns an iterator over the possible completions + + .. warning:: Unstable + + This function is unstable, API may change without warning. + It will also raise unless use in proper context manager. + + Parameters + ---------- + + text:str + Full text of the current input, multi line string. + offset:int + Integer representing the position of the cursor in ``text``. Offset + is 0-based indexed. + + Yields + ------ + :any:`Completion` object + + + The cursor on a text can either be seen as being "in between" + characters or "On" a character depending on the interface visible to + the user. For consistency the cursor being on "in between" characters X + and Y is equivalent to the cursor being "on" character Y, that is to say + the character the cursor is on is considered as being after the cursor. + + Combining characters may span more that one position in the + text. + + + .. note:: + + If ``IPCompleter.debug`` is :any:`True` will yield a ``--jedi/ipython--`` + fake Completion token to distinguish completion returned by Jedi + and usual IPython completion. + + .. note:: + + Completions are not completely deduplicated yet. If identical + completions are coming from different sources this function does not + ensure that each completion object will only be present once. + """ + warnings.warn("_complete is a provisional API (as of IPython 6.0). " + "It may change without warnings. " + "Use in corresponding context manager.", + category=ProvisionalCompleterWarning, stacklevel=2) + + seen = set() + try: + for c in self._completions(text, offset, _timeout=self.jedi_compute_type_timeout/1000): + if c and (c in seen): + continue + yield c + seen.add(c) + except KeyboardInterrupt: + """if completions take too long and users send keyboard interrupt, + do not crash and return ASAP. """ + pass + + def _completions(self, full_text: str, offset: int, *, _timeout)->Iterator[Completion]: + """ + Core completion module.Same signature as :any:`completions`, with the + extra `timeout` parameter (in seconds). + + + Computing jedi's completion ``.type`` can be quite expensive (it is a + lazy property) and can require some warm-up, more warm up than just + computing the ``name`` of a completion. The warm-up can be : + + - Long warm-up the first time a module is encountered after + install/update: actually build parse/inference tree. + + - first time the module is encountered in a session: load tree from + disk. + + We don't want to block completions for tens of seconds so we give the + completer a "budget" of ``_timeout`` seconds per invocation to compute + completions types, the completions that have not yet been computed will + be marked as "unknown" an will have a chance to be computed next round + are things get cached. + + Keep in mind that Jedi is not the only thing treating the completion so + keep the timeout short-ish as if we take more than 0.3 second we still + have lots of processing to do. + + """ + deadline = time.monotonic() + _timeout + + + before = full_text[:offset] + cursor_line, cursor_column = position_to_cursor(full_text, offset) + + matched_text, matches, matches_origin, jedi_matches = self._complete( + full_text=full_text, cursor_line=cursor_line, cursor_pos=cursor_column) + + iter_jm = iter(jedi_matches) + if _timeout: + for jm in iter_jm: + try: + type_ = jm.type + except Exception: + if self.debug: + print("Error in Jedi getting type of ", jm) + type_ = None + delta = len(jm.name_with_symbols) - len(jm.complete) + if type_ == 'function': + signature = _make_signature(jm) + else: + signature = '' + yield Completion(start=offset - delta, + end=offset, + text=jm.name_with_symbols, + type=type_, + signature=signature, + _origin='jedi') + + if time.monotonic() > deadline: + break + + for jm in iter_jm: + delta = len(jm.name_with_symbols) - len(jm.complete) + yield Completion(start=offset - delta, + end=offset, + text=jm.name_with_symbols, + type='', # don't compute type for speed + _origin='jedi', + signature='') + + + start_offset = before.rfind(matched_text) + + # TODO: + # Suppress this, right now just for debug. + if jedi_matches and matches and self.debug: + yield Completion(start=start_offset, end=offset, text='--jedi/ipython--', + _origin='debug', type='none', signature='') + + # I'm unsure if this is always true, so let's assert and see if it + # crash + assert before.endswith(matched_text) + for m, t in zip(matches, matches_origin): + yield Completion(start=start_offset, end=offset, text=m, _origin=t, signature='', type='') + + + def complete(self, text=None, line_buffer=None, cursor_pos=None): + """Find completions for the given text and line context. + + Note that both the text and the line_buffer are optional, but at least + one of them must be given. + + Parameters + ---------- + text : string, optional + Text to perform the completion on. If not given, the line buffer + is split using the instance's CompletionSplitter object. + + line_buffer : string, optional + If not given, the completer attempts to obtain the current line + buffer via readline. This keyword allows clients which are + requesting for text completions in non-readline contexts to inform + the completer of the entire text. + + cursor_pos : int, optional + Index of the cursor in the full line buffer. Should be provided by + remote frontends where kernel has no access to frontend state. + + Returns + ------- + text : str + Text that was actually used in the completion. + + matches : list + A list of completion matches. + + + .. note:: + + This API is likely to be deprecated and replaced by + :any:`IPCompleter.completions` in the future. + + + """ + warnings.warn('`Completer.complete` is pending deprecation since ' + 'IPython 6.0 and will be replaced by `Completer.completions`.', + PendingDeprecationWarning) + # potential todo, FOLD the 3rd throw away argument of _complete + # into the first 2 one. + return self._complete(line_buffer=line_buffer, cursor_pos=cursor_pos, text=text, cursor_line=0)[:2] + + def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None, + full_text=None) -> Tuple[str, List[str], List[str], Iterable[_FakeJediCompletion]]: + """ + + Like complete but can also returns raw jedi completions as well as the + origin of the completion text. This could (and should) be made much + cleaner but that will be simpler once we drop the old (and stateful) + :any:`complete` API. + + + With current provisional API, cursor_pos act both (depending on the + caller) as the offset in the ``text`` or ``line_buffer``, or as the + ``column`` when passing multiline strings this could/should be renamed + but would add extra noise. + """ + + # if the cursor position isn't given, the only sane assumption we can + # make is that it's at the end of the line (the common case) + if cursor_pos is None: + cursor_pos = len(line_buffer) if text is None else len(text) + + if self.use_main_ns: + self.namespace = __main__.__dict__ + + # if text is either None or an empty string, rely on the line buffer + if (not line_buffer) and full_text: + line_buffer = full_text.split('\n')[cursor_line] + if not text: + text = self.splitter.split_line(line_buffer, cursor_pos) + + if self.backslash_combining_completions: + # allow deactivation of these on windows. + base_text = text if not line_buffer else line_buffer[:cursor_pos] + latex_text, latex_matches = self.latex_matches(base_text) + if latex_matches: + return latex_text, latex_matches, ['latex_matches']*len(latex_matches), () + name_text = '' + name_matches = [] + for meth in (self.unicode_name_matches, back_latex_name_matches, back_unicode_name_matches): + name_text, name_matches = meth(base_text) + if name_text: + return name_text, name_matches[:MATCHES_LIMIT], \ + [meth.__qualname__]*min(len(name_matches), MATCHES_LIMIT), () + + + # If no line buffer is given, assume the input text is all there was + if line_buffer is None: + line_buffer = text + + self.line_buffer = line_buffer + self.text_until_cursor = self.line_buffer[:cursor_pos] + + # Do magic arg matches + for matcher in self.magic_arg_matchers: + matches = list(matcher(line_buffer))[:MATCHES_LIMIT] + if matches: + origins = [matcher.__qualname__] * len(matches) + return text, matches, origins, () + + # Start with a clean slate of completions + matches = [] + custom_res = self.dispatch_custom_completer(text) + # FIXME: we should extend our api to return a dict with completions for + # different types of objects. The rlcomplete() method could then + # simply collapse the dict into a list for readline, but we'd have + # richer completion semantics in other environments. + completions = () + if self.use_jedi: + if not full_text: + full_text = line_buffer + completions = self._jedi_matches( + cursor_pos, cursor_line, full_text) + if custom_res is not None: + # did custom completers produce something? + matches = [(m, 'custom') for m in custom_res] + else: + # Extend the list of completions with the results of each + # matcher, so we return results to the user from all + # namespaces. + if self.merge_completions: + matches = [] + for matcher in self.matchers: + try: + matches.extend([(m, matcher.__qualname__) + for m in matcher(text)]) + except: + # Show the ugly traceback if the matcher causes an + # exception, but do NOT crash the kernel! + sys.excepthook(*sys.exc_info()) + else: + for matcher in self.matchers: + matches = [(m, matcher.__qualname__) + for m in matcher(text)] + if matches: + break + seen = set() + filtered_matches = set() + for m in matches: + t, c = m + if t not in seen: + filtered_matches.add(m) + seen.add(t) + + _filtered_matches = sorted( + set(filtered_matches), key=lambda x: completions_sorting_key(x[0]))\ + [:MATCHES_LIMIT] + + _matches = [m[0] for m in _filtered_matches] + origins = [m[1] for m in _filtered_matches] + + self.matches = _matches + + return text, _matches, origins, completions diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/completerlib.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/completerlib.py new file mode 100644 index 00000000..3c66d73b --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/completerlib.py @@ -0,0 +1,354 @@ +# encoding: utf-8 +"""Implementations for various useful completers. + +These are all loaded by default by IPython. +""" +#----------------------------------------------------------------------------- +# Copyright (C) 2010-2011 The IPython Development Team. +# +# Distributed under the terms of the BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +# Stdlib imports +import glob +import inspect +import os +import re +import sys +from importlib import import_module +from importlib.machinery import all_suffixes + + +# Third-party imports +from time import time +from zipimport import zipimporter + +# Our own imports +from IPython.core.completer import expand_user, compress_user +from IPython.core.error import TryNext +from IPython.utils._process_common import arg_split + +# FIXME: this should be pulled in with the right call via the component system +from IPython import get_ipython + +from typing import List + +#----------------------------------------------------------------------------- +# Globals and constants +#----------------------------------------------------------------------------- +_suffixes = all_suffixes() + +# Time in seconds after which the rootmodules will be stored permanently in the +# ipython ip.db database (kept in the user's .ipython dir). +TIMEOUT_STORAGE = 2 + +# Time in seconds after which we give up +TIMEOUT_GIVEUP = 20 + +# Regular expression for the python import statement +import_re = re.compile(r'(?P[a-zA-Z_][a-zA-Z0-9_]*?)' + r'(?P[/\\]__init__)?' + r'(?P%s)$' % + r'|'.join(re.escape(s) for s in _suffixes)) + +# RE for the ipython %run command (python + ipython scripts) +magic_run_re = re.compile(r'.*(\.ipy|\.ipynb|\.py[w]?)$') + +#----------------------------------------------------------------------------- +# Local utilities +#----------------------------------------------------------------------------- + +def module_list(path): + """ + Return the list containing the names of the modules available in the given + folder. + """ + # sys.path has the cwd as an empty string, but isdir/listdir need it as '.' + if path == '': + path = '.' + + # A few local constants to be used in loops below + pjoin = os.path.join + + if os.path.isdir(path): + # Build a list of all files in the directory and all files + # in its subdirectories. For performance reasons, do not + # recurse more than one level into subdirectories. + files = [] + for root, dirs, nondirs in os.walk(path, followlinks=True): + subdir = root[len(path)+1:] + if subdir: + files.extend(pjoin(subdir, f) for f in nondirs) + dirs[:] = [] # Do not recurse into additional subdirectories. + else: + files.extend(nondirs) + + else: + try: + files = list(zipimporter(path)._files.keys()) + except: + files = [] + + # Build a list of modules which match the import_re regex. + modules = [] + for f in files: + m = import_re.match(f) + if m: + modules.append(m.group('name')) + return list(set(modules)) + + +def get_root_modules(): + """ + Returns a list containing the names of all the modules available in the + folders of the pythonpath. + + ip.db['rootmodules_cache'] maps sys.path entries to list of modules. + """ + ip = get_ipython() + if ip is None: + # No global shell instance to store cached list of modules. + # Don't try to scan for modules every time. + return list(sys.builtin_module_names) + + rootmodules_cache = ip.db.get('rootmodules_cache', {}) + rootmodules = list(sys.builtin_module_names) + start_time = time() + store = False + for path in sys.path: + try: + modules = rootmodules_cache[path] + except KeyError: + modules = module_list(path) + try: + modules.remove('__init__') + except ValueError: + pass + if path not in ('', '.'): # cwd modules should not be cached + rootmodules_cache[path] = modules + if time() - start_time > TIMEOUT_STORAGE and not store: + store = True + print("\nCaching the list of root modules, please wait!") + print("(This will only be done once - type '%rehashx' to " + "reset cache!)\n") + sys.stdout.flush() + if time() - start_time > TIMEOUT_GIVEUP: + print("This is taking too long, we give up.\n") + return [] + rootmodules.extend(modules) + if store: + ip.db['rootmodules_cache'] = rootmodules_cache + rootmodules = list(set(rootmodules)) + return rootmodules + + +def is_importable(module, attr, only_modules): + if only_modules: + return inspect.ismodule(getattr(module, attr)) + else: + return not(attr[:2] == '__' and attr[-2:] == '__') + + +def try_import(mod: str, only_modules=False) -> List[str]: + """ + Try to import given module and return list of potential completions. + """ + mod = mod.rstrip('.') + try: + m = import_module(mod) + except: + return [] + + m_is_init = hasattr(m, '__file__') and '__init__' in m.__file__ + + completions = [] + if (not hasattr(m, '__file__')) or (not only_modules) or m_is_init: + completions.extend( [attr for attr in dir(m) if + is_importable(m, attr, only_modules)]) + + completions.extend(getattr(m, '__all__', [])) + if m_is_init: + completions.extend(module_list(os.path.dirname(m.__file__))) + completions_set = {c for c in completions if isinstance(c, str)} + completions_set.discard('__init__') + return list(completions_set) + + +#----------------------------------------------------------------------------- +# Completion-related functions. +#----------------------------------------------------------------------------- + +def quick_completer(cmd, completions): + """ Easily create a trivial completer for a command. + + Takes either a list of completions, or all completions in string (that will + be split on whitespace). + + Example:: + + [d:\ipython]|1> import ipy_completers + [d:\ipython]|2> ipy_completers.quick_completer('foo', ['bar','baz']) + [d:\ipython]|3> foo b + bar baz + [d:\ipython]|3> foo ba + """ + + if isinstance(completions, str): + completions = completions.split() + + def do_complete(self, event): + return completions + + get_ipython().set_hook('complete_command',do_complete, str_key = cmd) + +def module_completion(line): + """ + Returns a list containing the completion possibilities for an import line. + + The line looks like this : + 'import xml.d' + 'from xml.dom import' + """ + + words = line.split(' ') + nwords = len(words) + + # from whatever -> 'import ' + if nwords == 3 and words[0] == 'from': + return ['import '] + + # 'from xy' or 'import xy' + if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) : + if nwords == 1: + return get_root_modules() + mod = words[1].split('.') + if len(mod) < 2: + return get_root_modules() + completion_list = try_import('.'.join(mod[:-1]), True) + return ['.'.join(mod[:-1] + [el]) for el in completion_list] + + # 'from xyz import abc' + if nwords >= 3 and words[0] == 'from': + mod = words[1] + return try_import(mod) + +#----------------------------------------------------------------------------- +# Completers +#----------------------------------------------------------------------------- +# These all have the func(self, event) signature to be used as custom +# completers + +def module_completer(self,event): + """Give completions after user has typed 'import ...' or 'from ...'""" + + # This works in all versions of python. While 2.5 has + # pkgutil.walk_packages(), that particular routine is fairly dangerous, + # since it imports *EVERYTHING* on sys.path. That is: a) very slow b) full + # of possibly problematic side effects. + # This search the folders in the sys.path for available modules. + + return module_completion(event.line) + +# FIXME: there's a lot of logic common to the run, cd and builtin file +# completers, that is currently reimplemented in each. + +def magic_run_completer(self, event): + """Complete files that end in .py or .ipy or .ipynb for the %run command. + """ + comps = arg_split(event.line, strict=False) + # relpath should be the current token that we need to complete. + if (len(comps) > 1) and (not event.line.endswith(' ')): + relpath = comps[-1].strip("'\"") + else: + relpath = '' + + #print("\nev=", event) # dbg + #print("rp=", relpath) # dbg + #print('comps=', comps) # dbg + + lglob = glob.glob + isdir = os.path.isdir + relpath, tilde_expand, tilde_val = expand_user(relpath) + + # Find if the user has already typed the first filename, after which we + # should complete on all files, since after the first one other files may + # be arguments to the input script. + + if any(magic_run_re.match(c) for c in comps): + matches = [f.replace('\\','/') + ('/' if isdir(f) else '') + for f in lglob(relpath+'*')] + else: + dirs = [f.replace('\\','/') + "/" for f in lglob(relpath+'*') if isdir(f)] + pys = [f.replace('\\','/') + for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') + + lglob(relpath+'*.ipynb') + lglob(relpath + '*.pyw')] + + matches = dirs + pys + + #print('run comp:', dirs+pys) # dbg + return [compress_user(p, tilde_expand, tilde_val) for p in matches] + + +def cd_completer(self, event): + """Completer function for cd, which only returns directories.""" + ip = get_ipython() + relpath = event.symbol + + #print(event) # dbg + if event.line.endswith('-b') or ' -b ' in event.line: + # return only bookmark completions + bkms = self.db.get('bookmarks', None) + if bkms: + return bkms.keys() + else: + return [] + + if event.symbol == '-': + width_dh = str(len(str(len(ip.user_ns['_dh']) + 1))) + # jump in directory history by number + fmt = '-%0' + width_dh +'d [%s]' + ents = [ fmt % (i,s) for i,s in enumerate(ip.user_ns['_dh'])] + if len(ents) > 1: + return ents + return [] + + if event.symbol.startswith('--'): + return ["--" + os.path.basename(d) for d in ip.user_ns['_dh']] + + # Expand ~ in path and normalize directory separators. + relpath, tilde_expand, tilde_val = expand_user(relpath) + relpath = relpath.replace('\\','/') + + found = [] + for d in [f.replace('\\','/') + '/' for f in glob.glob(relpath+'*') + if os.path.isdir(f)]: + if ' ' in d: + # we don't want to deal with any of that, complex code + # for this is elsewhere + raise TryNext + + found.append(d) + + if not found: + if os.path.isdir(relpath): + return [compress_user(relpath, tilde_expand, tilde_val)] + + # if no completions so far, try bookmarks + bks = self.db.get('bookmarks',{}) + bkmatches = [s for s in bks if s.startswith(event.symbol)] + if bkmatches: + return bkmatches + + raise TryNext + + return [compress_user(p, tilde_expand, tilde_val) for p in found] + +def reset_completer(self, event): + "A completer for %reset magic" + return '-f -s in out array dhist'.split() diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/crashhandler.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/crashhandler.py new file mode 100644 index 00000000..f3abc1c6 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/crashhandler.py @@ -0,0 +1,225 @@ +# encoding: utf-8 +"""sys.excepthook for IPython itself, leaves a detailed report on disk. + +Authors: + +* Fernando Perez +* Brian E. Granger +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2001-2007 Fernando Perez. +# Copyright (C) 2008-2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os +import sys +import traceback +from pprint import pformat + +from IPython.core import ultratb +from IPython.core.release import author_email +from IPython.utils.sysinfo import sys_info +from IPython.utils.py3compat import input + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +# Template for the user message. +_default_message_template = """\ +Oops, {app_name} crashed. We do our best to make it stable, but... + +A crash report was automatically generated with the following information: + - A verbatim copy of the crash traceback. + - A copy of your input history during this session. + - Data on your current {app_name} configuration. + +It was left in the file named: +\t'{crash_report_fname}' +If you can email this file to the developers, the information in it will help +them in understanding and correcting the problem. + +You can mail it to: {contact_name} at {contact_email} +with the subject '{app_name} Crash Report'. + +If you want to do it now, the following command will work (under Unix): +mail -s '{app_name} Crash Report' {contact_email} < {crash_report_fname} + +In your email, please also include information about: +- The operating system under which the crash happened: Linux, macOS, Windows, + other, and which exact version (for example: Ubuntu 16.04.3, macOS 10.13.2, + Windows 10 Pro), and whether it is 32-bit or 64-bit; +- How {app_name} was installed: using pip or conda, from GitHub, as part of + a Docker container, or other, providing more detail if possible; +- How to reproduce the crash: what exact sequence of instructions can one + input to get the same crash? Ideally, find a minimal yet complete sequence + of instructions that yields the crash. + +To ensure accurate tracking of this issue, please file a report about it at: +{bug_tracker} +""" + +_lite_message_template = """ +If you suspect this is an IPython bug, please report it at: + https://github.com/ipython/ipython/issues +or send an email to the mailing list at {email} + +You can print a more detailed traceback right now with "%tb", or use "%debug" +to interactively debug it. + +Extra-detailed tracebacks for bug-reporting purposes can be enabled via: + {config}Application.verbose_crash=True +""" + + +class CrashHandler(object): + """Customizable crash handlers for IPython applications. + + Instances of this class provide a :meth:`__call__` method which can be + used as a ``sys.excepthook``. The :meth:`__call__` signature is:: + + def __call__(self, etype, evalue, etb) + """ + + message_template = _default_message_template + section_sep = '\n\n'+'*'*75+'\n\n' + + def __init__(self, app, contact_name=None, contact_email=None, + bug_tracker=None, show_crash_traceback=True, call_pdb=False): + """Create a new crash handler + + Parameters + ---------- + app : Application + A running :class:`Application` instance, which will be queried at + crash time for internal information. + + contact_name : str + A string with the name of the person to contact. + + contact_email : str + A string with the email address of the contact. + + bug_tracker : str + A string with the URL for your project's bug tracker. + + show_crash_traceback : bool + If false, don't print the crash traceback on stderr, only generate + the on-disk report + + Non-argument instance attributes: + + These instances contain some non-argument attributes which allow for + further customization of the crash handler's behavior. Please see the + source for further details. + """ + self.crash_report_fname = "Crash_report_%s.txt" % app.name + self.app = app + self.call_pdb = call_pdb + #self.call_pdb = True # dbg + self.show_crash_traceback = show_crash_traceback + self.info = dict(app_name = app.name, + contact_name = contact_name, + contact_email = contact_email, + bug_tracker = bug_tracker, + crash_report_fname = self.crash_report_fname) + + + def __call__(self, etype, evalue, etb): + """Handle an exception, call for compatible with sys.excepthook""" + + # do not allow the crash handler to be called twice without reinstalling it + # this prevents unlikely errors in the crash handling from entering an + # infinite loop. + sys.excepthook = sys.__excepthook__ + + # Report tracebacks shouldn't use color in general (safer for users) + color_scheme = 'NoColor' + + # Use this ONLY for developer debugging (keep commented out for release) + #color_scheme = 'Linux' # dbg + try: + rptdir = self.app.ipython_dir + except: + rptdir = os.getcwd() + if rptdir is None or not os.path.isdir(rptdir): + rptdir = os.getcwd() + report_name = os.path.join(rptdir,self.crash_report_fname) + # write the report filename into the instance dict so it can get + # properly expanded out in the user message template + self.crash_report_fname = report_name + self.info['crash_report_fname'] = report_name + TBhandler = ultratb.VerboseTB( + color_scheme=color_scheme, + long_header=1, + call_pdb=self.call_pdb, + ) + if self.call_pdb: + TBhandler(etype,evalue,etb) + return + else: + traceback = TBhandler.text(etype,evalue,etb,context=31) + + # print traceback to screen + if self.show_crash_traceback: + print(traceback, file=sys.stderr) + + # and generate a complete report on disk + try: + report = open(report_name,'w') + except: + print('Could not create crash report on disk.', file=sys.stderr) + return + + # Inform user on stderr of what happened + print('\n'+'*'*70+'\n', file=sys.stderr) + print(self.message_template.format(**self.info), file=sys.stderr) + + # Construct report on disk + report.write(self.make_report(traceback)) + report.close() + input("Hit to quit (your terminal may close):") + + def make_report(self,traceback): + """Return a string containing a crash report.""" + + sec_sep = self.section_sep + + report = ['*'*75+'\n\n'+'IPython post-mortem report\n\n'] + rpt_add = report.append + rpt_add(sys_info()) + + try: + config = pformat(self.app.config) + rpt_add(sec_sep) + rpt_add('Application name: %s\n\n' % self.app_name) + rpt_add('Current user configuration structure:\n\n') + rpt_add(config) + except: + pass + rpt_add(sec_sep+'Crash traceback:\n\n' + traceback) + + return ''.join(report) + + +def crash_handler_lite(etype, evalue, tb): + """a light excepthook, adding a small message to the usual traceback""" + traceback.print_exception(etype, evalue, tb) + + from IPython.core.interactiveshell import InteractiveShell + if InteractiveShell.initialized(): + # we are in a Shell environment, give %magic example + config = "%config " + else: + # we are not in a shell, show generic config + config = "c." + print(_lite_message_template.format(email=author_email, config=config), file=sys.stderr) + diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/debugger.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/debugger.py new file mode 100644 index 00000000..0e0d4011 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/debugger.py @@ -0,0 +1,645 @@ +# -*- coding: utf-8 -*- +""" +Pdb debugger class. + +Modified from the standard pdb.Pdb class to avoid including readline, so that +the command line completion of other programs which include this isn't +damaged. + +In the future, this class will be expanded with improvements over the standard +pdb. + +The code in this file is mainly lifted out of cmd.py in Python 2.2, with minor +changes. Licensing should therefore be under the standard Python terms. For +details on the PSF (Python Software Foundation) standard license, see: + +https://docs.python.org/2/license.html +""" + +#***************************************************************************** +# +# This file is licensed under the PSF license. +# +# Copyright (C) 2001 Python Software Foundation, www.python.org +# Copyright (C) 2005-2006 Fernando Perez. +# +# +#***************************************************************************** + +import bdb +import functools +import inspect +import linecache +import sys +import warnings +import re + +from IPython import get_ipython +from IPython.utils import PyColorize +from IPython.utils import coloransi, py3compat +from IPython.core.excolors import exception_colors +from IPython.testing.skipdoctest import skip_doctest + + +prompt = 'ipdb> ' + +#We have to check this directly from sys.argv, config struct not yet available +from pdb import Pdb as OldPdb + +# Allow the set_trace code to operate outside of an ipython instance, even if +# it does so with some limitations. The rest of this support is implemented in +# the Tracer constructor. + +def make_arrow(pad): + """generate the leading arrow in front of traceback or debugger""" + if pad >= 2: + return '-'*(pad-2) + '> ' + elif pad == 1: + return '>' + return '' + + +def BdbQuit_excepthook(et, ev, tb, excepthook=None): + """Exception hook which handles `BdbQuit` exceptions. + + All other exceptions are processed using the `excepthook` + parameter. + """ + warnings.warn("`BdbQuit_excepthook` is deprecated since version 5.1", + DeprecationWarning, stacklevel=2) + if et==bdb.BdbQuit: + print('Exiting Debugger.') + elif excepthook is not None: + excepthook(et, ev, tb) + else: + # Backwards compatibility. Raise deprecation warning? + BdbQuit_excepthook.excepthook_ori(et,ev,tb) + + +def BdbQuit_IPython_excepthook(self,et,ev,tb,tb_offset=None): + warnings.warn( + "`BdbQuit_IPython_excepthook` is deprecated since version 5.1", + DeprecationWarning, stacklevel=2) + print('Exiting Debugger.') + + +class Tracer(object): + """ + DEPRECATED + + Class for local debugging, similar to pdb.set_trace. + + Instances of this class, when called, behave like pdb.set_trace, but + providing IPython's enhanced capabilities. + + This is implemented as a class which must be initialized in your own code + and not as a standalone function because we need to detect at runtime + whether IPython is already active or not. That detection is done in the + constructor, ensuring that this code plays nicely with a running IPython, + while functioning acceptably (though with limitations) if outside of it. + """ + + @skip_doctest + def __init__(self, colors=None): + """ + DEPRECATED + + Create a local debugger instance. + + Parameters + ---------- + + colors : str, optional + The name of the color scheme to use, it must be one of IPython's + valid color schemes. If not given, the function will default to + the current IPython scheme when running inside IPython, and to + 'NoColor' otherwise. + + Examples + -------- + :: + + from IPython.core.debugger import Tracer; debug_here = Tracer() + + Later in your code:: + + debug_here() # -> will open up the debugger at that point. + + Once the debugger activates, you can use all of its regular commands to + step through code, set breakpoints, etc. See the pdb documentation + from the Python standard library for usage details. + """ + warnings.warn("`Tracer` is deprecated since version 5.1, directly use " + "`IPython.core.debugger.Pdb.set_trace()`", + DeprecationWarning, stacklevel=2) + + ip = get_ipython() + if ip is None: + # Outside of ipython, we set our own exception hook manually + sys.excepthook = functools.partial(BdbQuit_excepthook, + excepthook=sys.excepthook) + def_colors = 'NoColor' + else: + # In ipython, we use its custom exception handler mechanism + def_colors = ip.colors + ip.set_custom_exc((bdb.BdbQuit,), BdbQuit_IPython_excepthook) + + if colors is None: + colors = def_colors + + # The stdlib debugger internally uses a modified repr from the `repr` + # module, that limits the length of printed strings to a hardcoded + # limit of 30 characters. That much trimming is too aggressive, let's + # at least raise that limit to 80 chars, which should be enough for + # most interactive uses. + try: + try: + from reprlib import aRepr # Py 3 + except ImportError: + from repr import aRepr # Py 2 + aRepr.maxstring = 80 + except: + # This is only a user-facing convenience, so any error we encounter + # here can be warned about but can be otherwise ignored. These + # printouts will tell us about problems if this API changes + import traceback + traceback.print_exc() + + self.debugger = Pdb(colors) + + def __call__(self): + """Starts an interactive debugger at the point where called. + + This is similar to the pdb.set_trace() function from the std lib, but + using IPython's enhanced debugger.""" + + self.debugger.set_trace(sys._getframe().f_back) + + +RGX_EXTRA_INDENT = re.compile('(?<=\n)\s+') + + +def strip_indentation(multiline_string): + return RGX_EXTRA_INDENT.sub('', multiline_string) + + +def decorate_fn_with_doc(new_fn, old_fn, additional_text=""): + """Make new_fn have old_fn's doc string. This is particularly useful + for the ``do_...`` commands that hook into the help system. + Adapted from from a comp.lang.python posting + by Duncan Booth.""" + def wrapper(*args, **kw): + return new_fn(*args, **kw) + if old_fn.__doc__: + wrapper.__doc__ = strip_indentation(old_fn.__doc__) + additional_text + return wrapper + + +def _file_lines(fname): + """Return the contents of a named file as a list of lines. + + This function never raises an IOError exception: if the file can't be + read, it simply returns an empty list.""" + + try: + outfile = open(fname) + except IOError: + return [] + else: + out = outfile.readlines() + outfile.close() + return out + + +class Pdb(OldPdb): + """Modified Pdb class, does not load readline. + + for a standalone version that uses prompt_toolkit, see + `IPython.terminal.debugger.TerminalPdb` and + `IPython.terminal.debugger.set_trace()` + """ + + def __init__(self, color_scheme=None, completekey=None, + stdin=None, stdout=None, context=5): + + # Parent constructor: + try: + self.context = int(context) + if self.context <= 0: + raise ValueError("Context must be a positive integer") + except (TypeError, ValueError): + raise ValueError("Context must be a positive integer") + + OldPdb.__init__(self, completekey, stdin, stdout) + + # IPython changes... + self.shell = get_ipython() + + if self.shell is None: + save_main = sys.modules['__main__'] + # No IPython instance running, we must create one + from IPython.terminal.interactiveshell import \ + TerminalInteractiveShell + self.shell = TerminalInteractiveShell.instance() + # needed by any code which calls __import__("__main__") after + # the debugger was entered. See also #9941. + sys.modules['__main__'] = save_main + + if color_scheme is not None: + warnings.warn( + "The `color_scheme` argument is deprecated since version 5.1", + DeprecationWarning, stacklevel=2) + else: + color_scheme = self.shell.colors + + self.aliases = {} + + # Create color table: we copy the default one from the traceback + # module and add a few attributes needed for debugging + self.color_scheme_table = exception_colors() + + # shorthands + C = coloransi.TermColors + cst = self.color_scheme_table + + cst['NoColor'].colors.prompt = C.NoColor + cst['NoColor'].colors.breakpoint_enabled = C.NoColor + cst['NoColor'].colors.breakpoint_disabled = C.NoColor + + cst['Linux'].colors.prompt = C.Green + cst['Linux'].colors.breakpoint_enabled = C.LightRed + cst['Linux'].colors.breakpoint_disabled = C.Red + + cst['LightBG'].colors.prompt = C.Blue + cst['LightBG'].colors.breakpoint_enabled = C.LightRed + cst['LightBG'].colors.breakpoint_disabled = C.Red + + cst['Neutral'].colors.prompt = C.Blue + cst['Neutral'].colors.breakpoint_enabled = C.LightRed + cst['Neutral'].colors.breakpoint_disabled = C.Red + + + # Add a python parser so we can syntax highlight source while + # debugging. + self.parser = PyColorize.Parser(style=color_scheme) + self.set_colors(color_scheme) + + # Set the prompt - the default prompt is '(Pdb)' + self.prompt = prompt + + def set_colors(self, scheme): + """Shorthand access to the color table scheme selector method.""" + self.color_scheme_table.set_active_scheme(scheme) + self.parser.style = scheme + + def interaction(self, frame, traceback): + try: + OldPdb.interaction(self, frame, traceback) + except KeyboardInterrupt: + sys.stdout.write('\n' + self.shell.get_exception_only()) + + def new_do_up(self, arg): + OldPdb.do_up(self, arg) + do_u = do_up = decorate_fn_with_doc(new_do_up, OldPdb.do_up) + + def new_do_down(self, arg): + OldPdb.do_down(self, arg) + + do_d = do_down = decorate_fn_with_doc(new_do_down, OldPdb.do_down) + + def new_do_frame(self, arg): + OldPdb.do_frame(self, arg) + + def new_do_quit(self, arg): + + if hasattr(self, 'old_all_completions'): + self.shell.Completer.all_completions=self.old_all_completions + + return OldPdb.do_quit(self, arg) + + do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit) + + def new_do_restart(self, arg): + """Restart command. In the context of ipython this is exactly the same + thing as 'quit'.""" + self.msg("Restart doesn't make sense here. Using 'quit' instead.") + return self.do_quit(arg) + + def print_stack_trace(self, context=None): + if context is None: + context = self.context + try: + context=int(context) + if context <= 0: + raise ValueError("Context must be a positive integer") + except (TypeError, ValueError): + raise ValueError("Context must be a positive integer") + try: + for frame_lineno in self.stack: + self.print_stack_entry(frame_lineno, context=context) + except KeyboardInterrupt: + pass + + def print_stack_entry(self,frame_lineno, prompt_prefix='\n-> ', + context=None): + if context is None: + context = self.context + try: + context=int(context) + if context <= 0: + raise ValueError("Context must be a positive integer") + except (TypeError, ValueError): + raise ValueError("Context must be a positive integer") + print(self.format_stack_entry(frame_lineno, '', context)) + + # vds: >> + frame, lineno = frame_lineno + filename = frame.f_code.co_filename + self.shell.hooks.synchronize_with_editor(filename, lineno, 0) + # vds: << + + def format_stack_entry(self, frame_lineno, lprefix=': ', context=None): + if context is None: + context = self.context + try: + context=int(context) + if context <= 0: + print("Context must be a positive integer") + except (TypeError, ValueError): + print("Context must be a positive integer") + try: + import reprlib # Py 3 + except ImportError: + import repr as reprlib # Py 2 + + ret = [] + + Colors = self.color_scheme_table.active_colors + ColorsNormal = Colors.Normal + tpl_link = u'%s%%s%s' % (Colors.filenameEm, ColorsNormal) + tpl_call = u'%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal) + tpl_line = u'%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal) + tpl_line_em = u'%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, + ColorsNormal) + + frame, lineno = frame_lineno + + return_value = '' + if '__return__' in frame.f_locals: + rv = frame.f_locals['__return__'] + #return_value += '->' + return_value += reprlib.repr(rv) + '\n' + ret.append(return_value) + + #s = filename + '(' + `lineno` + ')' + filename = self.canonic(frame.f_code.co_filename) + link = tpl_link % py3compat.cast_unicode(filename) + + if frame.f_code.co_name: + func = frame.f_code.co_name + else: + func = "" + + call = '' + if func != '?': + if '__args__' in frame.f_locals: + args = reprlib.repr(frame.f_locals['__args__']) + else: + args = '()' + call = tpl_call % (func, args) + + # The level info should be generated in the same format pdb uses, to + # avoid breaking the pdbtrack functionality of python-mode in *emacs. + if frame is self.curframe: + ret.append('> ') + else: + ret.append(' ') + ret.append(u'%s(%s)%s\n' % (link,lineno,call)) + + start = lineno - 1 - context//2 + lines = linecache.getlines(filename) + start = min(start, len(lines) - context) + start = max(start, 0) + lines = lines[start : start + context] + + for i,line in enumerate(lines): + show_arrow = (start + 1 + i == lineno) + linetpl = (frame is self.curframe or show_arrow) \ + and tpl_line_em \ + or tpl_line + ret.append(self.__format_line(linetpl, filename, + start + 1 + i, line, + arrow = show_arrow) ) + return ''.join(ret) + + def __format_line(self, tpl_line, filename, lineno, line, arrow = False): + bp_mark = "" + bp_mark_color = "" + + new_line, err = self.parser.format2(line, 'str') + if not err: + line = new_line + + bp = None + if lineno in self.get_file_breaks(filename): + bps = self.get_breaks(filename, lineno) + bp = bps[-1] + + if bp: + Colors = self.color_scheme_table.active_colors + bp_mark = str(bp.number) + bp_mark_color = Colors.breakpoint_enabled + if not bp.enabled: + bp_mark_color = Colors.breakpoint_disabled + + numbers_width = 7 + if arrow: + # This is the line with the error + pad = numbers_width - len(str(lineno)) - len(bp_mark) + num = '%s%s' % (make_arrow(pad), str(lineno)) + else: + num = '%*s' % (numbers_width - len(bp_mark), str(lineno)) + + return tpl_line % (bp_mark_color + bp_mark, num, line) + + + def print_list_lines(self, filename, first, last): + """The printing (as opposed to the parsing part of a 'list' + command.""" + try: + Colors = self.color_scheme_table.active_colors + ColorsNormal = Colors.Normal + tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal) + tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal) + src = [] + if filename == "" and hasattr(self, "_exec_filename"): + filename = self._exec_filename + + for lineno in range(first, last+1): + line = linecache.getline(filename, lineno) + if not line: + break + + if lineno == self.curframe.f_lineno: + line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True) + else: + line = self.__format_line(tpl_line, filename, lineno, line, arrow = False) + + src.append(line) + self.lineno = lineno + + print(''.join(src)) + + except KeyboardInterrupt: + pass + + def do_list(self, arg): + """Print lines of code from the current stack frame + """ + self.lastcmd = 'list' + last = None + if arg: + try: + x = eval(arg, {}, {}) + if type(x) == type(()): + first, last = x + first = int(first) + last = int(last) + if last < first: + # Assume it's a count + last = first + last + else: + first = max(1, int(x) - 5) + except: + print('*** Error in argument:', repr(arg)) + return + elif self.lineno is None: + first = max(1, self.curframe.f_lineno - 5) + else: + first = self.lineno + 1 + if last is None: + last = first + 10 + self.print_list_lines(self.curframe.f_code.co_filename, first, last) + + # vds: >> + lineno = first + filename = self.curframe.f_code.co_filename + self.shell.hooks.synchronize_with_editor(filename, lineno, 0) + # vds: << + + do_l = do_list + + def getsourcelines(self, obj): + lines, lineno = inspect.findsource(obj) + if inspect.isframe(obj) and obj.f_globals is obj.f_locals: + # must be a module frame: do not try to cut a block out of it + return lines, 1 + elif inspect.ismodule(obj): + return lines, 1 + return inspect.getblock(lines[lineno:]), lineno+1 + + def do_longlist(self, arg): + """Print lines of code from the current stack frame. + + Shows more lines than 'list' does. + """ + self.lastcmd = 'longlist' + try: + lines, lineno = self.getsourcelines(self.curframe) + except OSError as err: + self.error(err) + return + last = lineno + len(lines) + self.print_list_lines(self.curframe.f_code.co_filename, lineno, last) + do_ll = do_longlist + + def do_debug(self, arg): + """debug code + Enter a recursive debugger that steps through the code + argument (which is an arbitrary expression or statement to be + executed in the current environment). + """ + sys.settrace(None) + globals = self.curframe.f_globals + locals = self.curframe_locals + p = self.__class__(completekey=self.completekey, + stdin=self.stdin, stdout=self.stdout) + p.use_rawinput = self.use_rawinput + p.prompt = "(%s) " % self.prompt.strip() + self.message("ENTERING RECURSIVE DEBUGGER") + sys.call_tracing(p.run, (arg, globals, locals)) + self.message("LEAVING RECURSIVE DEBUGGER") + sys.settrace(self.trace_dispatch) + self.lastcmd = p.lastcmd + + def do_pdef(self, arg): + """Print the call signature for any callable object. + + The debugger interface to %pdef""" + namespaces = [('Locals', self.curframe.f_locals), + ('Globals', self.curframe.f_globals)] + self.shell.find_line_magic('pdef')(arg, namespaces=namespaces) + + def do_pdoc(self, arg): + """Print the docstring for an object. + + The debugger interface to %pdoc.""" + namespaces = [('Locals', self.curframe.f_locals), + ('Globals', self.curframe.f_globals)] + self.shell.find_line_magic('pdoc')(arg, namespaces=namespaces) + + def do_pfile(self, arg): + """Print (or run through pager) the file where an object is defined. + + The debugger interface to %pfile. + """ + namespaces = [('Locals', self.curframe.f_locals), + ('Globals', self.curframe.f_globals)] + self.shell.find_line_magic('pfile')(arg, namespaces=namespaces) + + def do_pinfo(self, arg): + """Provide detailed information about an object. + + The debugger interface to %pinfo, i.e., obj?.""" + namespaces = [('Locals', self.curframe.f_locals), + ('Globals', self.curframe.f_globals)] + self.shell.find_line_magic('pinfo')(arg, namespaces=namespaces) + + def do_pinfo2(self, arg): + """Provide extra detailed information about an object. + + The debugger interface to %pinfo2, i.e., obj??.""" + namespaces = [('Locals', self.curframe.f_locals), + ('Globals', self.curframe.f_globals)] + self.shell.find_line_magic('pinfo2')(arg, namespaces=namespaces) + + def do_psource(self, arg): + """Print (or run through pager) the source code for an object.""" + namespaces = [('Locals', self.curframe.f_locals), + ('Globals', self.curframe.f_globals)] + self.shell.find_line_magic('psource')(arg, namespaces=namespaces) + + def do_where(self, arg): + """w(here) + Print a stack trace, with the most recent frame at the bottom. + An arrow indicates the "current frame", which determines the + context of most commands. 'bt' is an alias for this command. + + Take a number as argument as an (optional) number of context line to + print""" + if arg: + context = int(arg) + self.print_stack_trace(context) + else: + self.print_stack_trace() + + do_w = do_where + + +def set_trace(frame=None): + """ + Start debugging from `frame`. + + If frame is not specified, debugging starts from caller's frame. + """ + Pdb().set_trace(frame or sys._getframe().f_back) diff --git a/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/display.py b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/display.py new file mode 100644 index 00000000..fa64d9c1 --- /dev/null +++ b/prajesh_gohel/Python/myEnvironments/django2.0Py3Env/lib/python3.7/site-packages/IPython/core/display.py @@ -0,0 +1,1416 @@ +# -*- coding: utf-8 -*- +"""Top-level display functions for displaying object in different formats.""" + +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + + +from binascii import b2a_hex, b2a_base64, hexlify +import json +import mimetypes +import os +import struct +import sys +import warnings +from copy import deepcopy + +from IPython.utils.py3compat import cast_unicode +from IPython.testing.skipdoctest import skip_doctest + +__all__ = ['display', 'display_pretty', 'display_html', 'display_markdown', +'display_svg', 'display_png', 'display_jpeg', 'display_latex', 'display_json', +'display_javascript', 'display_pdf', 'DisplayObject', 'TextDisplayObject', +'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'ProgressBar', 'JSON', +'GeoJSON', 'Javascript', 'Image', 'clear_output', 'set_matplotlib_formats', +'set_matplotlib_close', 'publish_display_data', 'update_display', 'DisplayHandle', +'Video'] + +#----------------------------------------------------------------------------- +# utility functions +#----------------------------------------------------------------------------- + +def _safe_exists(path): + """Check path, but don't let exceptions raise""" + try: + return os.path.exists(path) + except Exception: + return False + +def _merge(d1, d2): + """Like update, but merges sub-dicts instead of clobbering at the top level. + + Updates d1 in-place + """ + + if not isinstance(d2, dict) or not isinstance(d1, dict): + return d2 + for key, value in d2.items(): + d1[key] = _merge(d1.get(key), value) + return d1 + +def _display_mimetype(mimetype, objs, raw=False, metadata=None): + """internal implementation of all display_foo methods + + Parameters + ---------- + mimetype : str + The mimetype to be published (e.g. 'image/png') + objs : tuple of objects + The Python objects to display, or if raw=True raw text data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + if metadata: + metadata = {mimetype: metadata} + if raw: + # turn list of pngdata into list of { 'image/png': pngdata } + objs = [ {mimetype: obj} for obj in objs ] + display(*objs, raw=raw, metadata=metadata, include=[mimetype]) + +#----------------------------------------------------------------------------- +# Main functions +#----------------------------------------------------------------------------- + +# use * to indicate transient is keyword-only +def publish_display_data(data, metadata=None, source=None, *, transient=None, **kwargs): + """Publish data and metadata to all frontends. + + See the ``display_data`` message in the messaging documentation for + more details about this message type. + + Keys of data and metadata can be any mime-type. + + Parameters + ---------- + data : dict + A dictionary having keys that are valid MIME types (like + 'text/plain' or 'image/svg+xml') and values that are the data for + that MIME type. The data itself must be a JSON'able data + structure. Minimally all data should have the 'text/plain' data, + which can be displayed by all frontends. If more than the plain + text is given, it is up to the frontend to decide which + representation to use. + metadata : dict + A dictionary for metadata related to the data. This can contain + arbitrary key, value pairs that frontends can use to interpret + the data. mime-type keys matching those in data can be used + to specify metadata about particular representations. + source : str, deprecated + Unused. + transient : dict, keyword-only + A dictionary of transient data, such as display_id. + """ + from IPython.core.interactiveshell import InteractiveShell + + display_pub = InteractiveShell.instance().display_pub + + # only pass transient if supplied, + # to avoid errors with older ipykernel. + # TODO: We could check for ipykernel version and provide a detailed upgrade message. + if transient: + kwargs['transient'] = transient + + display_pub.publish( + data=data, + metadata=metadata, + **kwargs + ) + + +def _new_id(): + """Generate a new random text id with urandom""" + return b2a_hex(os.urandom(16)).decode('ascii') + + +def display(*objs, include=None, exclude=None, metadata=None, transient=None, display_id=None, **kwargs): + """Display a Python object in all frontends. + + By default all representations will be computed and sent to the frontends. + Frontends can decide which representation is used and how. + + In terminal IPython this will be similar to using :func:`print`, for use in richer + frontends see Jupyter notebook examples with rich display logic. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display. + raw : bool, optional + Are the objects to be displayed already mimetype-keyed dicts of raw display data, + or Python objects that need to be formatted before display? [default: False] + include : list, tuple or set, optional + A list of format type strings (MIME types) to include in the + format data dict. If this is set *only* the format types included + in this list will be computed. + exclude : list, tuple or set, optional + A list of format type strings (MIME types) to exclude in the format + data dict. If this is set all format types will be computed, + except for those included in this argument. + metadata : dict, optional + A dictionary of metadata to associate with the output. + mime-type keys in this dictionary will be associated with the individual + representation formats, if they exist. + transient : dict, optional + A dictionary of transient data to associate with the output. + Data in this dict should not be persisted to files (e.g. notebooks). + display_id : str, bool optional + Set an id for the display. + This id can be used for updating this display area later via update_display. + If given as `True`, generate a new `display_id` + kwargs: additional keyword-args, optional + Additional keyword-arguments are passed through to the display publisher. + + Returns + ------- + + handle: DisplayHandle + Returns a handle on updatable displays for use with :func:`update_display`, + if `display_id` is given. Returns :any:`None` if no `display_id` is given + (default). + + Examples + -------- + + >>> class Json(object): + ... def __init__(self, json): + ... self.json = json + ... def _repr_pretty_(self, pp, cycle): + ... import json + ... pp.text(json.dumps(self.json, indent=2)) + ... def __repr__(self): + ... return str(self.json) + ... + + >>> d = Json({1:2, 3: {4:5}}) + + >>> print(d) + {1: 2, 3: {4: 5}} + + >>> display(d) + { + "1": 2, + "3": { + "4": 5 + } + } + + >>> def int_formatter(integer, pp, cycle): + ... pp.text('I'*integer) + + >>> plain = get_ipython().display_formatter.formatters['text/plain'] + >>> plain.for_type(int, int_formatter) + + >>> display(7-5) + II + + >>> del plain.type_printers[int] + >>> display(7-5) + 2 + + See Also + -------- + + :func:`update_display` + + Notes + ----- + + In Python, objects can declare their textual representation using the + `__repr__` method. IPython expands on this idea and allows objects to declare + other, rich representations including: + + - HTML + - JSON + - PNG + - JPEG + - SVG + - LaTeX + + A single object can declare some or all of these representations; all are + handled by IPython's display system. + + The main idea of the first approach is that you have to implement special + display methods when you define your class, one for each representation you + want to use. Here is a list of the names of the special methods and the + values they must return: + + - `_repr_html_`: return raw HTML as a string + - `_repr_json_`: return a JSONable dict + - `_repr_jpeg_`: return raw JPEG data + - `_repr_png_`: return raw PNG data + - `_repr_svg_`: return raw SVG data as a string + - `_repr_latex_`: return LaTeX commands in a string surrounded by "$". + - `_repr_mimebundle_`: return a full mimebundle containing the mapping + from all mimetypes to data. + Use this for any mime-type not listed above. + + When you are directly writing your own classes, you can adapt them for + display in IPython by following the above approach. But in practice, you + often need to work with existing classes that you can't easily modify. + + You can refer to the documentation on integrating with the display system in + order to register custom formatters for already existing types + (:ref:`integrating_rich_display`). + + .. versionadded:: 5.4 display available without import + .. versionadded:: 6.1 display available without import + + Since IPython 5.4 and 6.1 :func:`display` is automatically made available to + the user without import. If you are using display in a document that might + be used in a pure python context or with older version of IPython, use the + following import at the top of your file:: + + from IPython.display import display + + """ + from IPython.core.interactiveshell import InteractiveShell + + if not InteractiveShell.initialized(): + # Directly print objects. + print(*objs) + return + + raw = kwargs.pop('raw', False) + if transient is None: + transient = {} + if metadata is None: + metadata={} + if display_id: + if display_id is True: + display_id = _new_id() + transient['display_id'] = display_id + if kwargs.get('update') and 'display_id' not in transient: + raise TypeError('display_id required for update_display') + if transient: + kwargs['transient'] = transient + + if not raw: + format = InteractiveShell.instance().display_formatter.format + + for obj in objs: + if raw: + publish_display_data(data=obj, metadata=metadata, **kwargs) + else: + format_dict, md_dict = format(obj, include=include, exclude=exclude) + if not format_dict: + # nothing to display (e.g. _ipython_display_ took over) + continue + if metadata: + # kwarg-specified metadata gets precedence + _merge(md_dict, metadata) + publish_display_data(data=format_dict, metadata=md_dict, **kwargs) + if display_id: + return DisplayHandle(display_id) + + +# use * for keyword-only display_id arg +def update_display(obj, *, display_id, **kwargs): + """Update an existing display by id + + Parameters + ---------- + + obj: + The object with which to update the display + display_id: keyword-only + The id of the display to update + + See Also + -------- + + :func:`display` + """ + kwargs['update'] = True + display(obj, display_id=display_id, **kwargs) + + +class DisplayHandle(object): + """A handle on an updatable display + + Call `.update(obj)` to display a new object. + + Call `.display(obj`) to add a new instance of this display, + and update existing instances. + + See Also + -------- + + :func:`display`, :func:`update_display` + + """ + + def __init__(self, display_id=None): + if display_id is None: + display_id = _new_id() + self.display_id = display_id + + def __repr__(self): + return "<%s display_id=%s>" % (self.__class__.__name__, self.display_id) + + def display(self, obj, **kwargs): + """Make a new display with my id, updating existing instances. + + Parameters + ---------- + + obj: + object to display + **kwargs: + additional keyword arguments passed to display + """ + display(obj, display_id=self.display_id, **kwargs) + + def update(self, obj, **kwargs): + """Update existing displays with my id + + Parameters + ---------- + + obj: + object to display + **kwargs: + additional keyword arguments passed to update_display + """ + update_display(obj, display_id=self.display_id, **kwargs) + + +def display_pretty(*objs, **kwargs): + """Display the pretty (default) representation of an object. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw text data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('text/plain', objs, **kwargs) + + +def display_html(*objs, **kwargs): + """Display the HTML representation of an object. + + Note: If raw=False and the object does not have a HTML + representation, no HTML will be shown. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw HTML data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('text/html', objs, **kwargs) + + +def display_markdown(*objs, **kwargs): + """Displays the Markdown representation of an object. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw markdown data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + + _display_mimetype('text/markdown', objs, **kwargs) + + +def display_svg(*objs, **kwargs): + """Display the SVG representation of an object. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw svg data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('image/svg+xml', objs, **kwargs) + + +def display_png(*objs, **kwargs): + """Display the PNG representation of an object. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw png data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('image/png', objs, **kwargs) + + +def display_jpeg(*objs, **kwargs): + """Display the JPEG representation of an object. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw JPEG data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('image/jpeg', objs, **kwargs) + + +def display_latex(*objs, **kwargs): + """Display the LaTeX representation of an object. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw latex data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('text/latex', objs, **kwargs) + + +def display_json(*objs, **kwargs): + """Display the JSON representation of an object. + + Note that not many frontends support displaying JSON. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw json data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('application/json', objs, **kwargs) + + +def display_javascript(*objs, **kwargs): + """Display the Javascript representation of an object. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw javascript data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('application/javascript', objs, **kwargs) + + +def display_pdf(*objs, **kwargs): + """Display the PDF representation of an object. + + Parameters + ---------- + objs : tuple of objects + The Python objects to display, or if raw=True raw javascript data to + display. + raw : bool + Are the data objects raw data or Python objects that need to be + formatted before display? [default: False] + metadata : dict (optional) + Metadata to be associated with the specific mimetype output. + """ + _display_mimetype('application/pdf', objs, **kwargs) + + +#----------------------------------------------------------------------------- +# Smart classes +#----------------------------------------------------------------------------- + + +class DisplayObject(object): + """An object that wraps data to be displayed.""" + + _read_flags = 'r' + _show_mem_addr = False + metadata = None + + def __init__(self, data=None, url=None, filename=None, metadata=None): + """Create a display object given raw data. + + When this object is returned by an expression or passed to the + display function, it will result in the data being displayed + in the frontend. The MIME type of the data should match the + subclasses used, so the Png subclass should be used for 'image/png' + data. If the data is a URL, the data will first be downloaded + and then displayed. If + + Parameters + ---------- + data : unicode, str or bytes + The raw data or a URL or file to load the data from + url : unicode + A URL to download the data from. + filename : unicode + Path to a local file to load the data from. + metadata : dict + Dict of metadata associated to be the object when displayed + """ + if data is not None and isinstance(data, str): + if data.startswith('http') and url is None: + url = data + filename = None + data = None + elif _safe_exists(data) and filename is None: + url = None + filename = data + data = None + + self.data = data + self.url = url + self.filename = filename + + if metadata is not None: + self.metadata = metadata + elif self.metadata is None: + self.metadata = {} + + self.reload() + self._check_data() + + def __repr__(self): + if not self._show_mem_addr: + cls = self.__class__ + r = "<%s.%s object>" % (cls.__module__, cls.__name__) + else: + r = super(DisplayObject, self).__repr__() + return r + + def _check_data(self): + """Override in subclasses if there's something to check.""" + pass + + def _data_and_metadata(self): + """shortcut for returning metadata with shape information, if defined""" + if self.metadata: + return self.data, deepcopy(self.metadata) + else: + return self.data + + def reload(self): + """Reload the raw data from file or URL.""" + if self.filename is not None: + with open(self.filename, self._read_flags) as f: + self.data = f.read() + elif self.url is not None: + try: + # Deferred import + from urllib.request import urlopen + response = urlopen(self.url) + self.data = response.read() + # extract encoding from header, if there is one: + encoding = None + for sub in response.headers['content-type'].split(';'): + sub = sub.strip() + if sub.startswith('charset'): + encoding = sub.split('=')[-1].strip() + break + # decode data, if an encoding was specified + if encoding: + self.data = self.data.decode(encoding, 'replace') + except: + self.data = None + +class TextDisplayObject(DisplayObject): + """Validate that display data is text""" + def _check_data(self): + if self.data is not None and not isinstance(self.data, str): + raise TypeError("%s expects text, not %r" % (self.__class__.__name__, self.data)) + +class Pretty(TextDisplayObject): + + def _repr_pretty_(self, pp, cycle): + return pp.text(self.data) + + +class HTML(TextDisplayObject): + + def _repr_html_(self): + return self._data_and_metadata() + + def __html__(self): + """ + This method exists to inform other HTML-using modules (e.g. Markupsafe, + htmltag, etc) that this object is HTML and does not need things like + special characters (<>&) escaped. + """ + return self._repr_html_() + + +class Markdown(TextDisplayObject): + + def _repr_markdown_(self): + return self._data_and_metadata() + + +class Math(TextDisplayObject): + + def _repr_latex_(self): + s = "$$%s$$" % self.data.strip('$') + if self.metadata: + return s, deepcopy(self.metadata) + else: + return s + + +class Latex(TextDisplayObject): + + def _repr_latex_(self): + return self._data_and_metadata() + + +class SVG(DisplayObject): + + _read_flags = 'rb' + # wrap data in a property, which extracts the tag, discarding + # document headers + _data = None + + @property + def data(self): + return self._data + + @data.setter + def data(self, svg): + if svg is None: + self._data = None + return + # parse into dom object + from xml.dom import minidom + x = minidom.parseString(svg) + # get svg tag (should be 1) + found_svg = x.getElementsByTagName('svg') + if found_svg: + svg = found_svg[0].toxml() + else: + # fallback on the input, trust the user + # but this is probably an error. + pass + svg = cast_unicode(svg) + self._data = svg + + def _repr_svg_(self): + return self._data_and_metadata() + +class ProgressBar(DisplayObject): + """Progressbar supports displaying a progressbar like element + """ + def __init__(self, total): + """Creates a new progressbar + + Parameters + ---------- + total : int + maximum size of the progressbar + """ + self.total = total + self._progress = 0 + self.html_width = '60ex' + self.text_width = 60 + self._display_id = hexlify(os.urandom(8)).decode('ascii') + + def __repr__(self): + fraction = self.progress / self.total + filled = '=' * int(fraction * self.text_width) + rest = ' ' * (self.text_width - len(filled)) + return '[{}{}] {}/{}'.format( + filled, rest, + self.progress, self.total, + ) + + def _repr_html_(self): + return "".format( + self.html_width, self.total, self.progress) + + def display(self): + display(self, display_id=self._display_id) + + def update(self): + display(self, display_id=self._display_id, update=True) + + @property + def progress(self): + return self._progress + + @progress.setter + def progress(self, value): + self._progress = value + self.update() + + def __iter__(self): + self.display() + self._progress = -1 # First iteration is 0 + return self + + def __next__(self): + """Returns current value and increments display by one.""" + self.progress += 1 + if self.progress < self.total: + return self.progress + else: + raise StopIteration() + +class JSON(DisplayObject): + """JSON expects a JSON-able dict or list + + not an already-serialized JSON string. + + Scalar types (None, number, string) are not allowed, only dict or list containers. + """ + # wrap data in a property, which warns about passing already-serialized JSON + _data = None + def __init__(self, data=None, url=None, filename=None, expanded=False, metadata=None, **kwargs): + """Create a JSON display object given raw data. + + Parameters + ---------- + data : dict or list + JSON data to display. Not an already-serialized JSON string. + Scalar types (None, number, string) are not allowed, only dict + or list containers. + url : unicode + A URL to download the data from. + filename : unicode + Path to a local file to load the data from. + expanded : boolean + Metadata to control whether a JSON display component is expanded. + metadata: dict + Specify extra metadata to attach to the json display object. + """ + self.metadata = {'expanded': expanded} + if metadata: + self.metadata.update(metadata) + if kwargs: + self.metadata.update(kwargs) + super(JSON, self).__init__(data=data, url=url, filename=filename) + + def _check_data(self): + if self.data is not None and not isinstance(self.data, (dict, list)): + raise TypeError("%s expects JSONable dict or list, not %r" % (self.__class__.__name__, self.data)) + + @property + def data(self): + return self._data + + @data.setter + def data(self, data): + if isinstance(data, str): + if getattr(self, 'filename', None) is None: + warnings.warn("JSON expects JSONable dict or list, not JSON strings") + data = json.loads(data) + self._data = data + + def _data_and_metadata(self): + return self.data, self.metadata + + def _repr_json_(self): + return self._data_and_metadata() + +_css_t = """$("head").append($("").attr({ + rel: "stylesheet", + type: "text/css", + href: "%s" +})); +""" + +_lib_t1 = """$.getScript("%s", function () { +""" +_lib_t2 = """}); +""" + +class GeoJSON(JSON): + """GeoJSON expects JSON-able dict + + not an already-serialized JSON string. + + Scalar types (None, number, string) are not allowed, only dict containers. + """ + + def __init__(self, *args, **kwargs): + """Create a GeoJSON display object given raw data. + + Parameters + ---------- + data : dict or list + VegaLite data. Not an already-serialized JSON string. + Scalar types (None, number, string) are not allowed, only dict + or list containers. + url_template : string + Leaflet TileLayer URL template: http://leafletjs.com/reference.html#url-template + layer_options : dict + Leaflet TileLayer options: http://leafletjs.com/reference.html#tilelayer-options + url : unicode + A URL to download the data from. + filename : unicode + Path to a local file to load the data from. + metadata: dict + Specify extra metadata to attach to the json display object. + + Examples + -------- + + The following will display an interactive map of Mars with a point of + interest on frontend that do support GeoJSON display. + + >>> from IPython.display import GeoJSON + + >>> GeoJSON(data={ + ... "type": "Feature", + ... "geometry": { + ... "type": "Point", + ... "coordinates": [-81.327, 296.038] + ... } + ... }, + ... url_template="http://s3-eu-west-1.amazonaws.com/whereonmars.cartodb.net/{basemap_id}/{z}/{x}/{y}.png", + ... layer_options={ + ... "basemap_id": "celestia_mars-shaded-16k_global", + ... "attribution" : "Celestia/praesepe", + ... "minZoom" : 0, + ... "maxZoom" : 18, + ... }) + + + In the terminal IPython, you will only see the text representation of + the GeoJSON object. + + """ + + super(GeoJSON, self).__init__(*args, **kwargs) + + + def _ipython_display_(self): + bundle = { + 'application/geo+json': self.data, + 'text/plain': '' + } + metadata = { + 'application/geo+json': self.metadata + } + display(bundle, metadata=metadata, raw=True) + +class Javascript(TextDisplayObject): + + def __init__(self, data=None, url=None, filename=None, lib=None, css=None): + """Create a Javascript display object given raw data. + + When this object is returned by an expression or passed to the + display function, it will result in the data being displayed + in the frontend. If the data is a URL, the data will first be + downloaded and then displayed. + + In the Notebook, the containing element will be available as `element`, + and jQuery will be available. Content appended to `element` will be + visible in the output area. + + Parameters + ---------- + data : unicode, str or bytes + The Javascript source code or a URL to download it from. + url : unicode + A URL to download the data from. + filename : unicode + Path to a local file to load the data from. + lib : list or str + A sequence of Javascript library URLs to load asynchronously before + running the source code. The full URLs of the libraries should + be given. A single Javascript library URL can also be given as a + string. + css: : list or str + A sequence of css files to load before running the source code. + The full URLs of the css files should be given. A single css URL + can also be given as a string. + """ + if isinstance(lib, str): + lib = [lib] + elif lib is None: + lib = [] + if isinstance(css, str): + css = [css] + elif css is None: + css = [] + if not isinstance(lib, (list,tuple)): + raise TypeError('expected sequence, got: %r' % lib) + if not isinstance(css, (list,tuple)): + raise TypeError('expected sequence, got: %r' % css) + self.lib = lib + self.css = css + super(Javascript, self).__init__(data=data, url=url, filename=filename) + + def _repr_javascript_(self): + r = '' + for c in self.css: + r += _css_t % c + for l in self.lib: + r += _lib_t1 % l + r += self.data + r += _lib_t2*len(self.lib) + return r + +# constants for identifying png/jpeg data +_PNG = b'\x89PNG\r\n\x1a\n' +_JPEG = b'\xff\xd8' + +def _pngxy(data): + """read the (width, height) from a PNG header""" + ihdr = data.index(b'IHDR') + # next 8 bytes are width/height + return struct.unpack('>ii', data[ihdr+4:ihdr+12]) + +def _jpegxy(data): + """read the (width, height) from a JPEG header""" + # adapted from http://www.64lines.com/jpeg-width-height + + idx = 4 + while True: + block_size = struct.unpack('>H', data[idx:idx+2])[0] + idx = idx + block_size + if data[idx:idx+2] == b'\xFF\xC0': + # found Start of Frame + iSOF = idx + break + else: + # read another block + idx += 2 + + h, w = struct.unpack('>HH', data[iSOF+5:iSOF+9]) + return w, h + +def _gifxy(data): + """read the (width, height) from a GIF header""" + return struct.unpack(' tag. Set this to True if you want the image + to be viewable later with no internet connection in the notebook. + + Default is `True`, unless the keyword argument `url` is set, then + default value is `False`. + + Note that QtConsole is not able to display images if `embed` is set to `False` + width : int + Width in pixels to which to constrain the image in html + height : int + Height in pixels to which to constrain the image in html + retina : bool + Automatically set the width and height to half of the measured + width and height. + This only works for embedded images because it reads the width/height + from image data. + For non-embedded images, you can just set the desired display width + and height directly. + unconfined: bool + Set unconfined=True to disable max-width confinement of the image. + metadata: dict + Specify extra metadata to attach to the image. + + Examples + -------- + # embedded image data, works in qtconsole and notebook + # when passed positionally, the first arg can be any of raw image data, + # a URL, or a filename from which to load image data. + # The result is always embedding image data for inline images. + Image('http://www.google.fr/images/srpr/logo3w.png') + Image('/path/to/image.jpg') + Image(b'RAW_PNG_DATA...') + + # Specifying Image(url=...) does not embed the image data, + # it only generates `` tag with a link to the source. + # This will not work in the qtconsole or offline. + Image(url='http://www.google.fr/images/srpr/logo3w.png') + + """ + if filename is not None: + ext = self._find_ext(filename) + elif url is not None: + ext = self._find_ext(url) + elif data is None: + raise ValueError("No image data found. Expecting filename, url, or data.") + elif isinstance(data, str) and ( + data.startswith('http') or _safe_exists(data) + ): + ext = self._find_ext(data) + else: + ext = None + + if format is None: + if ext is not None: + if ext == u'jpg' or ext == u'jpeg': + format = self._FMT_JPEG + elif ext == u'png': + format = self._FMT_PNG + elif ext == u'gif': + format = self._FMT_GIF + else: + format = ext.lower() + elif isinstance(data, bytes): + # infer image type from image data header, + # only if format has not been specified. + if data[:2] == _JPEG: + format = self._FMT_JPEG + + # failed to detect format, default png + if format is None: + format = self._FMT_PNG + + if format.lower() == 'jpg': + # jpg->jpeg + format = self._FMT_JPEG + + self.format = format.lower() + self.embed = embed if embed is not None else (url is None) + + if self.embed and self.format not in self._ACCEPTABLE_EMBEDDINGS: + raise ValueError("Cannot embed the '%s' image format" % (self.format)) + if self.embed: + self._mimetype = self._MIMETYPES.get(self.format) + + self.width = width + self.height = height + self.retina = retina + self.unconfined = unconfined + super(Image, self).__init__(data=data, url=url, filename=filename, + metadata=metadata) + + if self.width is None and self.metadata.get('width', {}): + self.width = metadata['width'] + + if self.height is None and self.metadata.get('height', {}): + self.height = metadata['height'] + + if retina: + self._retina_shape() + + + def _retina_shape(self): + """load pixel-doubled width and height from image data""" + if not self.embed: + return + if self.format == self._FMT_PNG: + w, h = _pngxy(self.data) + elif self.format == self._FMT_JPEG: + w, h = _jpegxy(self.data) + elif self.format == self._FMT_GIF: + w, h = _gifxy(self.data) + else: + # retina only supports png + return + self.width = w // 2 + self.height = h // 2 + + def reload(self): + """Reload the raw data from file or URL.""" + if self.embed: + super(Image,self).reload() + if self.retina: + self._retina_shape() + + def _repr_html_(self): + if not self.embed: + width = height = klass = '' + if self.width: + width = ' width="%d"' % self.width + if self.height: + height = ' height="%d"' % self.height + if self.unconfined: + klass = ' class="unconfined"' + return u''.format( + url=self.url, + width=width, + height=height, + klass=klass, + ) + + def _repr_mimebundle_(self, include=None, exclude=None): + """Return the image as a mimebundle + + Any new mimetype support should be implemented here. + """ + if self.embed: + mimetype = self._mimetype + data, metadata = self._data_and_metadata(always_both=True) + if metadata: + metadata = {mimetype: metadata} + return {mimetype: data}, metadata + else: + return {'text/html': self._repr_html_()} + + def _data_and_metadata(self, always_both=False): + """shortcut for returning metadata with shape information, if defined""" + b64_data = b2a_base64(self.data).decode('ascii') + md = {} + if self.metadata: + md.update(self.metadata) + if self.width: + md['width'] = self.width + if self.height: + md['height'] = self.height + if self.unconfined: + md['unconfined'] = self.unconfined + if md or always_both: + return b64_data, md + else: + return b64_data + + def _repr_png_(self): + if self.embed and self.format == self._FMT_PNG: + return self._data_and_metadata() + + def _repr_jpeg_(self): + if self.embed and self.format == self._FMT_JPEG: + return self._data_and_metadata() + + def _find_ext(self, s): + return s.split('.')[-1].lower() + + +class Video(DisplayObject): + + def __init__(self, data=None, url=None, filename=None, embed=False, mimetype=None): + """Create a video object given raw data or an URL. + + When this object is returned by an input cell or passed to the + display function, it will result in the video being displayed + in the frontend. + + Parameters + ---------- + data : unicode, str or bytes + The raw video data or a URL or filename to load the data from. + Raw data will require passing `embed=True`. + url : unicode + A URL for the video. If you specify `url=`, + the image data will not be embedded. + filename : unicode + Path to a local file containing the video. + Will be interpreted as a local URL unless `embed=True`. + embed : bool + Should the video be embedded using a data URI (True) or be + loaded using a