Commit 27140b03 authored by SABBITHI NAREN RAHUL's avatar SABBITHI NAREN RAHUL

Revert "Merge branch 'django' into 'linux'"

This reverts merge request !1
parent 65ab129c
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5.2 (/usr/bin/python3.5)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mydrive.iml" filepath="$PROJECT_DIR$/.idea/mydrive.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.5.2 (/usr/bin/python3.5)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
File deleted
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mydrive.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)
from django.contrib import admin
# Register your models here.
from .models import File,User
admin.site.register(File)
admin.site.register(User)
\ No newline at end of file
from django.apps import AppConfig
class MyappConfig(AppConfig):
name = 'myapp'
from django.contrib.auth.models import User
from django import forms
class UserForm(forms.ModelForm):
password=forms.CharField(widget=forms.PasswordInput)
class Meta:
model=User
fields=['username','email','password']
# Generated by Django 2.1.2 on 2018-10-23 17:52
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='File',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=250)),
('password', models.CharField(max_length=250)),
('file_name', models.FileField(max_length=500, upload_to='')),
('sync', models.BooleanField(default=False)),
],
),
]
# Generated by Django 2.0.5 on 2018-10-24 05:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('myapp', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='file',
name='password',
),
]
# Generated by Django 2.1.2 on 2018-10-24 10:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('myapp', '0002_remove_file_password'),
]
operations = [
migrations.AddField(
model_name='file',
name='file_content',
field=models.BinaryField(blank=True),
),
]
# Generated by Django 2.1.2 on 2018-10-24 14:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('myapp', '0003_file_file_content'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=250)),
('sync', models.BooleanField(default=False)),
],
),
migrations.RemoveField(
model_name='file',
name='sync',
),
]
from django.db import models
from django.urls import reverse
class File(models.Model):
username=models.CharField(max_length=250)
file_name=models.FileField(max_length=500)
file_content=models.BinaryField(blank = True)
def __str__(self):
return self.file_name
class User(models.Model):
username=models.CharField(max_length=250)
sync = models.BooleanField(default=False)
def __str__(self):
return self.username+'(sync='+str(self.sync)+')'
{% if user.is_authenticated %}
<h2>Hi!{{ user.username }}</h2>
{% if all_files %}
<h3>Hi!Here are your files</h3>
<ul>
{% for file in all_files %}
<li>{{ file.file_name }}</li>
{% endfor %}
</ul>
{% else %}
<h3>Oops!You do not have any files</h3>
{% endif %}
<p><a href="{% url 'logout' %}" >Logout</a> </p>
{% else %}
<p><a href="{% url 'login' %}">Login Here</a> </p>
{% endif %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
{% if form.errors %}
<p>There"s something wrong with what you have entered</p>
{% endif %}
{% if next %}
<p>Hey,you cant access that page.</p>
{% endif %}
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<p>Username: {{ form.username }}</p>
<p>Password: {{ form.password }}</p>
<p> <input type="submit" value="login"></p>
<input type="hidden" name="next" value="{{ next }}">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Register</title>
</head>
<body>
<h1>Registration Page</h1>
<form method="post" action="{% url 'register' %}">
{% csrf_token %}
{% if form.errors %}
<p></p>
{% endif %}
{{ form }}
<input type="submit" value="Register">
</form>
<p>Already a User?<a href="/accounts/login">Sign in</a> </p>
</body>
</html>
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url
from django.urls import path,re_path
from . import views
urlpatterns = [
path('home',views.index,name='home'),
path('',views.register,name='register'),
path('linux/login',views.linuxlogin,name='linuxlogin'),
path('upload',views.upload,name='upload')
]
# Create your views here.
from django.shortcuts import render,redirect
from django.contrib.auth import authenticate,login
from django.views import generic
from .forms import UserForm
from .models import File
from django.views import generic
from django.views.generic.edit import CreateView,UpdateView,DeleteView
from django.views.generic import View
from django.contrib.auth.forms import UserCreationForm,AuthenticationForm
from .models import File,User
from django.http import JsonResponse
import json
from django.views.decorators.csrf import csrf_exempt
def index(request):
usernam = None
if request.user.is_authenticated:
usernam = request.user.username
all_files = File.objects.filter(username=usernam)
context={'all_files': all_files}
return render(request,'myapp/index.html',context)
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
usernam = form.cleaned_data['username']
password = form.cleaned_data['password1']
p=User(username=usernam,sync=0)
p.save()
user = authenticate(username=usernam,password=password)
login(request,user)
return redirect('home')
else:
form = UserCreationForm()
context = {'form' : form}
return render(request,'registration/register.html',context)
@csrf_exempt
def linuxlogin(request):
if request.method == 'POST':
details=json.loads(request.body.decode('utf-8'))
usr_name=details['username']
passw=details['password']
if authenticate(username=usr_name,password=passw):
return JsonResponse({'yes':'yes'})
else:
return JsonResponse({'yes':'no'})
@csrf_exempt
def upload(request):
if request.method == 'POST':
file1=request.FILES['file']
cont=file1.read()
file2=request.FILES['det']
details=json.load(file2)
usr_name = details['username']
passw = details['password']
if authenticate(username=usr_name, password=passw):
data = cont
name=file1.name
p=File(username=usr_name,file_name=name,file_content=data)
p.save()
return JsonResponse({'yes':'yes'})
else:
return JsonResponse({'yes':'no'})
class IndexView(generic.ListView):
template_name='myapp/index.html'
def get_queryset(self):
if user.is_authenticated:
nam=user.username
return File.objects.filter(username=nam)
class FileCreate(CreateView):
model=File
fields=['user_name','password','file_name','sync']
"""
Django settings for mydrive project.
Generated by 'django-admin startproject' using Django 2.1.2.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/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.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'yk7wcq-i)y4yht2m96qop_t123k(25i1sa-k_w9mk4*6*eaj)*'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# Application definition
INSTALLED_APPS = [
'myapp.apps.MyappConfig',
'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 = 'mydrive.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 = 'mydrive.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/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.1/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.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
ALLOWED_HOSTS = ['*']
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
LOGIN_REDIRECT_URL='home'
LOGOUT_REDIRECT_URL='/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
MEDIA_URL='/media/'
"""mydrive URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/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.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('myapp.urls')),
path('accounts/',include('django.contrib.auth.urls')),
]
if settings.DEBUG:
urlpatterns+=static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_URL)
"""
WSGI config for mydrive 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.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mydrive.settings')
application = get_wsgi_application()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment