Commit 1e3ef547 authored by apocalypse007's avatar apocalypse007

final commit

parents
cse-git link:
https://tarunsaurabh@git.cse.iitb.ac.in/tarunsaurabh/reinforcement-learning-peers-space.git
---------------------------------------------------------------------------------------------------------------
Abhijeet Pratap Singh 203059001 {Documentation and Data acquisition,templates}
Ayush Gupta 203050034 {Layout/ ML and RL related tasks/ Workingwith models}
Ankit Gaur 203050081 {Documentation and Data acquisition,templates}
Tarun Saurabh 203050009 {Python/ ML related tasks/models}
-----------------------------------------------------------------------------------------------------------------
Motivation:
Peer’s Space is started to provide a platform to exchangeknowledge between the experts of one field with the experts of other field. The vast majority of human knowledge is still not onthe internet. Most of it is trapped in the form of experience inpeople’s heads, or buried in books and papers that only expertscan access. As a consequence most people don’t have theknowledge they should, and don’t have the time, connections, orskills to get the knowledge faster.
In this project user can read and post article display of article on the feed is based on Thompson sampling from using beta distribution
------------------------------------------------------------------------------------------------------------------
How to use:
Using the peer's space is very simple. You need to have installed the dependencies.
To install python3 on ubuntu, run the following command in your terminal.
sudo apt-get install python3.6
pip3 install numpy
To install Django on ubuntu, run the following command in your terminal.
sudo apt-get install python3-django
One needs to git clone the project. After that open terminal in peers_space directory where manage.py is present and run following commands.
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py runserver
To access the application open the web browser and go to "localhost:8000"
"""
ASGI config for ablog project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ablog.settings')
application = get_asgi_application()
"""
Django settings for ablog project.
Generated by 'django-admin startproject' using Django 3.1.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'bdx=b5ko@sdfr!347*hhrn9v@l-7(n+a@k=yj$()zhd(5@&7kw'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'theblog',
'users',
]
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 = 'ablog.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 = 'ablog.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.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/3.1/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/3.1/howto/static-files/
STATIC_URL = 'theblog/static/'
LOGIN_REDIRECT_URL = "home"
LOGOUT_REDIRECT_URL = "home"
"""ablog URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('theblog.urls')),
path('dashboard/',include('users.urls')),
]
"""
WSGI config for ablog 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/3.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ablog.settings')
application = get_wsgi_application()
File added
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ablog.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)
if __name__ == '__main__':
main()
from django.contrib import admin
# Register your models here.
from .models import Post , Tags , alpha , total
admin.site.register(Post)
admin.site.register(Tags)
admin.site.register(alpha)
admin.site.register(total)
\ No newline at end of file
from django.apps import AppConfig
class TheblogConfig(AppConfig):
name = 'theblog'
# Generated by Django 3.1.2 on 2020-11-01 20:19
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('body', models.TextField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
# Generated by Django 3.1.2 on 2020-11-01 20:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('theblog', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='post',
name='tags',
field=models.CharField(max_length=255, null=True),
),
]
# Generated by Django 3.1.2 on 2020-11-15 10:56
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('theblog', '0002_post_tags'),
]
operations = [
migrations.CreateModel(
name='thompson',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ML', models.FloatField(default=0.0)),
('DIP', models.FloatField(default=0.0)),
('RL', models.FloatField(default=0.0)),
('SYSTEM', models.FloatField(default=0.0)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
# Generated by Django 3.1.2 on 2020-11-15 12:14
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('theblog', '0003_thompson'),
]
operations = [
migrations.CreateModel(
name='thompsonalpha',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ML', models.IntegerField(default=0)),
('DIP', models.IntegerField(default=0)),
('RL', models.IntegerField(default=0)),
('SYSTEM', models.IntegerField(default=0)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='thompsontotal',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ML', models.IntegerField(default=0)),
('DIP', models.IntegerField(default=0)),
('RL', models.IntegerField(default=0)),
('SYSTEM', models.IntegerField(default=0)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.DeleteModel(
name='thompson',
),
]
# Generated by Django 3.1.2 on 2020-11-15 15:14
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('theblog', '0004_auto_20201115_1214'),
]
operations = [
migrations.CreateModel(
name='Tags',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tag_name', models.CharField(max_length=255)),
],
),
migrations.AlterField(
model_name='post',
name='tags',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='theblog.tags'),
),
]
# Generated by Django 3.1.2 on 2020-11-15 15:25
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('theblog', '0005_auto_20201115_1514'),
]
operations = [
migrations.RenameField(
model_name='tags',
old_name='tag_name',
new_name='tagname',
),
]
# Generated by Django 3.1.2 on 2020-11-15 15:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('theblog', '0006_auto_20201115_1525'),
]
operations = [
migrations.RemoveField(
model_name='thompsontotal',
name='author',
),
migrations.AlterField(
model_name='post',
name='tags',
field=models.CharField(max_length=255),
),
migrations.DeleteModel(
name='thompsonalpha',
),
migrations.DeleteModel(
name='thompsontotal',
),
]
# Generated by Django 3.1.2 on 2020-11-15 16:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('theblog', '0007_auto_20201115_1553'),
]
operations = [
migrations.AddField(
model_name='post',
name='tagname',
field=models.CharField(default=0, max_length=255),
),
]
# Generated by Django 3.1.2 on 2020-11-15 16:30
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('theblog', '0008_post_tagname'),
]
operations = [
migrations.CreateModel(
name='total',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ML', models.IntegerField(default=0)),
('RL', models.IntegerField(default=0)),
('DIP', models.IntegerField(default=0)),
('MATHS', models.IntegerField(default=0)),
('userid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='alpha',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ML', models.IntegerField(default=0)),
('RL', models.IntegerField(default=0)),
('DIP', models.IntegerField(default=0)),
('MATHS', models.IntegerField(default=0)),
('userid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
# Generated by Django 3.1.2 on 2020-11-16 09:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('theblog', '0009_alpha_total'),
]
operations = [
migrations.AlterField(
model_name='post',
name='tags',
field=models.IntegerField(),
),
]
# Generated by Django 3.1.2 on 2020-11-16 19:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('theblog', '0010_auto_20201116_0959'),
]
operations = [
migrations.AddField(
model_name='alpha',
name='architecture',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='alpha',
name='arts',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='alpha',
name='chemistry',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='alpha',
name='computer_science',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='alpha',
name='engineering',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='alpha',
name='geography',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='alpha',
name='literature',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='alpha',
name='physics',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='alpha',
name='python',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='architecture',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='arts',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='chemistry',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='computer_science',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='engineering',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='geography',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='literature',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='physics',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='total',
name='python',
field=models.IntegerField(default=0),
),
]
from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
import datetime
# Create your models here.
class Tags(models.Model):
tagname = models.CharField(max_length=255)
def __str__(self):
return str(self.pk)+" "+str(self.tagname)
class Post(models.Model):
tags = models.IntegerField()
title = models.CharField(max_length=255)
author = models.ForeignKey(User , on_delete=models.CASCADE)
body = models.TextField()
tagname = models.CharField(max_length=255 , default=0)
def __str__(self):
return "Primarykey="+str(self.pk)+" Tags="+str(self.tags)+" "+str(self.title) + ' | ' + str(self.author)
class alpha(models.Model):
userid = models.ForeignKey(User,on_delete=models.CASCADE)
ML = models.IntegerField(default=0)
RL = models.IntegerField(default=0)
DIP = models.IntegerField(default=0)
MATHS = models.IntegerField(default=0)
python = models.IntegerField(default=0)
physics = models.IntegerField(default=0)
chemistry = models.IntegerField(default=0)
computer_science = models.IntegerField(default=0)
arts = models.IntegerField(default=0)
geography = models.IntegerField(default=0)
architecture = models.IntegerField(default=0)
engineering = models.IntegerField(default=0)
literature = models.IntegerField(default=0)
def __str__(self):
return str(self.userid)
class total(models.Model):
userid = models.ForeignKey(User,on_delete=models.CASCADE)
ML = models.IntegerField(default=0)
RL = models.IntegerField(default=0)
DIP = models.IntegerField(default=0)
MATHS = models.IntegerField(default=0)
python = models.IntegerField(default=0)
physics = models.IntegerField(default=0)
chemistry = models.IntegerField(default=0)
computer_science = models.IntegerField(default=0)
arts = models.IntegerField(default=0)
geography = models.IntegerField(default=0)
architecture = models.IntegerField(default=0)
engineering = models.IntegerField(default=0)
literature = models.IntegerField(default=0)
def __str__(self):
return str(self.userid)
\ No newline at end of file
body{
margin:50px 0 0 0;
font-family: Tahoma, Verdana, Segoe, sans-serif;
padding:0;
background-image:linear-gradient(#ffffff , #dfe1ee );
}
.left{
float:left;
width:50%;
color:#12141d;
height:300px;
margin:60px auto;
padding-top:50px;
}
.right{
float:left;
width:50%;
height:300px;
padding-top:50px;
margin:60px auto;
color:#12141d;
}
.signup input{
display:block;
width:60%;
border:none;
height:30px;
padding:2px;
margin:5px auto;
}
.signup .button{
height:35px;
margin:5px auto;
width:61%;
background-image:linear-gradient(#334a7d,#2b3c63);
color:white;
border:none;
font-weight:bold;
}
.account_head{
text-align:center;
font-weight:bold;
}
body{
margin:50px 0 0 0;
font-family: Tahoma, Verdana, Segoe, sans-serif;
padding:0;
background-color: rgba(255,255,255,0.5);
}
.nav{
padding:0;
width:100%;
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
height:30px;
background-color:#4267B2;
color:white;
z-index:1;
box-shadow:0 0 5px 0 #F5F5F5;
}
.nav a{
color:white;
font-weight: bold;
text-decoration:none;
}
.nav a:hover{
color: white;
font-weight: bold;
text-decoration: none;
}
.logo{
float:left;
width:20%;
margin:auto;
text-align:center;
line-height:30px;
font-size:100%;
}
.list{
float:left;
margin:auto;
width:60%;
padding:0 auto;
line-height:30px;
}
.list a{
display:inline-block;
margin:0 3%;
padding:0;
letter-spacing:1px;
text-align:center;
}
.account
{
float:right;
width:20%;
margin:auto;
text-align:center;
line-height:30px;
font-size:80%;
}
.input_block
{
background-color:white;
width:95%;
max-width:1000px;
border: 1px solid white;
margin:20px auto;
padding:2% 2% 2% 2%;
}
.user_input input {
width:100%;
}
.dummy{
margin: 10px;
}
.each_block
{
background-color:white;
width:90%;
font-family: 'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;
max-width:1000px;
margin-top:10px;
margin-bottom:0;
margin-left:auto;
margin-right: auto;
padding: 0;
padding-left:1%;
padding-right: 1%;
}
.each_block:hover{
box-shadow: 0 1px 1px rgba(0,0,0,0.11),
0 2px 2px rgba(0,0,0,0.11),
0 4px 4px rgba(0,0,0,0.11),
0 6px 8px rgba(0,0,0,0.11),
0 8px 16px rgba(0,0,0,0.11);}
.tag{
width:100%;
background-color:white;
color:black;
font-weight:bold;
text-align:left;
margin:0;
padding: 0;
}
.heading{
padding:0;
margin:0;
font-size:14px;
font-weight:bold;
}
.name{
font-style:oblique;
color:#A8A8A8;
font-size:11px;
padding:0;
margin:0;
}
.each_block .head{
text-align: center;
font-size:14px;
font-weight: bold;
cursor: pointer;
}
.btn{
color: white;
background-color: #4267B2;
}
.modal-header{
color: white;
background-color: #4267B2;
}
.modal-body input{
width: 100%;
margin: 5px auto;
border-bottom: 1px;
padding: 2px;
border: none;
background-color: #D3D3D3;
height: 40px;
}
.modal-body select{
width: 100%;
margin: 5px auto;
border-bottom: 1px;
padding: 2px;
border: none;
background-color: #D3D3D3;
height: 40px;
}
.modal-body:nth-child(3){
width: 100%;
margin: 5px auto;
border-bottom: 1px;
padding: 2px;
border: none;
background-color: #D3D3D3;
height: 400px;
}
.modal-body .labelinput{
text-align: left;
font-size:10px;
font-weight: bold;
cursor: pointer;
}
.middle{
width:50%;
padding:25px;
margin:80px auto;
color:#12141d;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.signup input{
display:block;
width:60%;
border:none;
background-color: #dfe1ee;
color:black;
height:40px;
padding:4px;
margin:15px auto;
}
.signup .button{
height:35px;
margin:10px auto;
width:61%;
background-image:linear-gradient(#334a7d,#2b3c63);
color:white;
border:none;
font-weight:bold;
}
.signup .button:hover{
height:35px;
margin:10px auto;
width:61%;
background-image:linear-gradient(#2b3c63,#334a7d);
color:white;
border:none;
font-weight:bold;
}
.account_head{
text-align:center;
font-weight:bold;
margin-bottom: 10px;
}
.account_base{
text-align:center;
font-weight:bold;
margin-bottom: 10px;
color: black;
}
.middle .labelinput{
text-align: center;
font-size:10px;
font-weight: bold;
cursor: pointer;
}
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static '/home.css' %}">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus')
})
</head>
<body>
<div class='nav'>
<div class='logo'>
<a href="{% url 'home' %}">Peer'sSpace</a></div>
<div class='list'>
{% if user.is_authenticated %}
<a href="{% url 'personalspace' %}">PersonalSpace</a>
{% endif %}
<a>LocalSpace</a>
<a href="{% url 'home' %}">GlobalSpace</a>
</div>
<div class='account'>
{% if user.is_authenticated %}
<a href="{% url 'logout' %}">Logout</a>
{% else %}
<a href="{% url 'login' %}">Login</a>
{% endif %}
</div>
</div>
{% block content %}
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<div class="dummy"></div>
{% for p in post1 %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body|truncatewords:30}}&nbsp;<a href ="{% url 'detail' p.pk %}">Continue reading</a>
</div>
<hr>
</div>
{% endfor %}
{% for p in post2 %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body|truncatewords:30}}&nbsp;<a href ="{% url 'detail' p.pk %}">Continue reading</a>
</div>
<hr>
</div>
{% endfor %}
{% for p in post3 %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body|truncatewords:30}}&nbsp;<a href ="{% url 'detail' p.pk %}">Continue reading</a>
</div>
<hr>
</div>
{% endfor %}
{% for p in post11 %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body|truncatewords:30}}&nbsp;<a href ="{% url 'detail' p.pk %}">Continue reading</a>
</div>
<hr>
</div>
{% endfor %}
{% for p in post12 %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body|truncatewords:30}}&nbsp;<a href ="{% url 'detail' p.pk %}">Continue reading</a>
</div>
<hr>
</div>
{% endfor %}
{% for p in post13 %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body|truncatewords:30}}&nbsp;<a href ="{% url 'detail' p.pk %}">Continue reading</a>
</div>
<hr>
</div>
{% endfor %}
{% for p in post %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body|truncatewords:30}}&nbsp;<a href ="{% url 'detail' p.pk %}">Continue reading</a>
</div>
<hr>
</div>
{% endfor %}
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<div class="dummy"></div>
<!-- Modal -->
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Share your knowledge</h5>
<button type="button" class="close btn" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form action="{% url 'inputpost' %}" method="POST">
{% csrf_token %}
<div class="labelinput">Add tag</div>
<select name="tags">
{% for t in tags %}
<option value="{{t.pk}}">{{t.tagname}}</option>
{% endfor %}
</select>
<div class="labelinput">Add title</div>
<input type="text" name="title" placeholder=" Title">
<div class="labelinput">Add content</div>
<input type="text" name="body" placeholder=" Share content">
<input type="submit" name="submitpost" class='button' value="submit">
</div>
</form>
</div>
</div>
</div>
<!-- ******************************************** -->
{% if user.is_authenticated %}
<div class="each_block">
<div class="head" data-toggle="modal" data-target="#exampleModalLong">Click to share something with us . .
</div>
</div>
{% endif %}
{% for p in post %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body}}
</div>
<hr>
</div>
{% endfor %}
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<div class='each_block'>
<div class='tag'>{{postdetail.tagname}}</div>
<div class='heading'>{{postdetail.title}}</div>
<span class='name'>This article is shared by&nbsp;{{postdetail.author}}</span>
<div class='body'>{{postdetail.body}}
</div>
<hr>
</div>
{% for p in post %}
<div class='each_block'>
<div class='tag'>{{p.tagname}}</div>
<div class='heading'><a href ="{% url 'detail' p.pk %}">{{p.title}}</a></div>
<span class='name'>This article is shared by&nbsp;{{p.author}}</span>
<div class='body'>{{p.body|truncatewords:30}}&nbsp;<a href ="{% url 'detail' p.pk %}">Continue reading</a>
</div>
<hr>
</div>
{% endfor %}
{% endblock %}
from django.test import TestCase
# Create your tests here.
"""ablog URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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.urls import path
from . import views
urlpatterns = [
path('',views.home , name='home') ,
path('article/<int:pk>' , views.detail , name='detail') ,
path('article/personalspace' , views.personalspace , name='personalspace') ,
path('article/personalspace/input' , views.inputdata , name='inputpost'),
]
from django.shortcuts import render
from django.shortcuts import redirect
from django.contrib.auth.models import User
import numpy as np
from .models import Post , Tags , alpha , total
from django.db.models import Q
def sampling(sl,tl):
e = np.zeros(len(sl))
length =len(sl)
count = 0
while count<length:
e[count] = np.random.beta(sl[count]+1,tl[count]-sl[count]+1)
count += 1
top1 = np.argmax(e)
e[top1] = 0
top2 = np.argmax(e)
e[top2] = 0
top3 = np.argmax(e)
return top1 , top2 , top3
def home(request):
if request.user.is_authenticated:
success = alpha.objects.get(userid = request.user)
timeperiod = total.objects.get(userid = request.user)
sl = [ success.ML , success.RL , success.DIP , success.MATHS ,
success.python , success.physics ,success.chemistry, success.computer_science , success.arts ,
success.geography , success.architecture , success.engineering , success.literature ]
tl = [ timeperiod.ML , timeperiod.RL , timeperiod.DIP , timeperiod.MATHS ,
timeperiod.python , timeperiod.physics , timeperiod.chemistry , timeperiod.computer_science , timeperiod.arts ,
timeperiod.geography , timeperiod.architecture , timeperiod.engineering , timeperiod.literature]
action1 ,action2 , action3 = sampling(sl,tl)
post1 = Post.objects.filter(tags=action1+6).order_by('-pk')[:3]
post2 = Post.objects.filter(tags=action2+6).order_by('-pk')[:2]
post3 = Post.objects.filter(tags=action3+6).order_by('-pk')[:1]
post11 = Post.objects.filter(tags=action1+6).order_by('-pk')[3:]
post12 = Post.objects.filter(tags=action2+6).order_by('-pk')[2:]
post13 = Post.objects.filter(tags=action3+6).order_by('-pk')[1:]
post = Post.objects.filter(~Q(tags = action1+6) & ~Q(tags=action2+6) &
~Q(tags=action3+6)).order_by('-pk')
#...............UPDATING TOTAL VALUE OF ALL THE POSTS.......
#>>> product = Product.objects.get(name='Venezuelan Beaver Cheese')
#>>> product.number_sold += 1
#>>> product.save()
timeperiod.ML +=1
timeperiod.RL +=1
timeperiod.DIP +=1
timeperiod.MATHS +=1
timeperiod.python +=1
timeperiod.physics +=1
timeperiod.chemistry +=1
timeperiod.computer_science +=1
timeperiod.arts +=1
timeperiod.geography +=1
timeperiod.architecture +=1
timeperiod.engineering +=1
timeperiod.literature +=1
timeperiod.save()
return render(request , 'home.html' , {'post1' : post1 , 'post2' : post2 , 'post3' : post3 ,
'post11' : post11 , 'post12' : post12 , 'post13' : post13, 'post':post})
else:
post = Post.objects.all().order_by('-pk')
return render(request , 'home.html' , {'post' : post})
def detail(request , pk):
if request.user.is_authenticated:
postdetail = Post.objects.get(pk=pk)
success = alpha.objects.get(userid = request.user)
timeperiod = total.objects.get(userid = request.user)
tag = postdetail.tags
# print(type(7))
if tag == 6:
success.ML +=1
timeperiod.ML +=1
elif tag == 7:
success.RL +=1
timeperiod.RL +=1
elif tag == 8:
success.DIP +=1
timeperiod.DIP += 1
elif tag == 9:
success.MATHS +=1
timeperiod.MATHS += 1
elif tag == 10:
success.python +=1
timeperiod.python += 1
elif tag == 11:
success.physics +=1
timeperiod.physics += 1
elif tag == 12:
success.chemistry +=1
timeperiod.chemistry += 1
elif tag == 13:
success.computer_science +=1
timeperiod.computer_science += 1
elif tag == 14:
success.arts +=1
timeperiod.arts += 1
elif tag == 15:
success.geography +=1
timeperiod.geography += 1
elif tag == 16:
success.architecture +=1
timeperiod.architecture += 1
elif tag == 17:
success.engineering +=1
timeperiod.engineering += 1
elif tag == 18:
success.literature +=1
timeperiod.literature += 1
success.save()
timeperiod.save()
post = Post.objects.filter(tagname=postdetail.tagname).order_by('-pk')
return render(request , 'post_detail.html' , {'postdetail' : postdetail, 'post':post})
else:
postdetail = Post.objects.get(pk=pk)
post = Post.objects.filter(Q(tagname=postdetail.tagname) & ~Q(pk=postdetail.pk)).order_by('-pk')
return render(request , 'post_detail.html' , {'postdetail' : postdetail, 'post':post})
def personalspace(request):
tags = Tags.objects.all()
post = Post.objects.all().filter(author=request.user).order_by('-pk')
return render(request , 'personalspace.html' , {'post' : post , 'tags': tags})
def inputdata(request):
if request.method == 'POST':
tags = request.POST['tags'].strip()
title = request.POST['title'].strip()
body = request.POST['body'].strip()
thetag = Tags.objects.get(pk=tags)
if len(tags) == 0 or len(title) == 0 or len(body)==0:
return redirect('personalspace')
else:
post = Post(tags = tags , title = title , body= body , author = request.user , tagname = thetag.tagname)
post.save()
return redirect('personalspace')
else:
return redirect('personalspace')
\ No newline at end of file
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'
from django.db import models
# Create your models here.
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static '/home.css' %}">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus')
})
</head>
<body>
<div class='nav'>
<div class='logo'>
<a href="{% url 'home' %}">PEER'SSPACE</a></div>
<div class='list'>
<a href="{% url 'personalspace' %}">PersonalSpace</a>
<a>LocalSpace</a>
<a>GlobalSpace</a>
</div>
<div class='account'>
<a href="{% url 'login' %}">LOGIN</a></div>
</div>
{% block content %}
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<div class='middle'>
<span style="text-align:center;color:red;font-weight: bold;font-family:monospace;">{{message}}</span>
<div class='account_head'>Already have an account? Sign in</div>
<form class='signup' method="post" action="{% url 'login' %}">
{% csrf_token %}
<input type="text" name="username" placeholder=" Enter your username">
<input type="password" name="password" placeholder="Enter your password">
<input type="submit" class='button' value="Sign in">
</form>
<div class='account_base'><a href="{% url 'register' %}">Don't have an account? Click to register</a></div>
</div>
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<div class='middle'>
<span style="text-align:center;color:red;font-weight: bold;font-family:monospace;">{{message}}</span>
<form action="{% url 'register' %}" method="POST" class="signup">
{% csrf_token %}
<div class="labelinput">Enter username</div>
<input type="text" name="username" placeholder=" Enter username">
<div class="labelinput">Enter email</div>
<input type="email" name="email" placeholder="Your email">
<div class="labelinput">Enter password</div>
<input type="password" name="password1" placeholder=" Password">
<div class="labelinput">Enter password again</div>
<input type="password" name="password2" placeholder=" Confirm password">
<input type="submit" class='button' value="Register">
</form>
</div>
{% endblock %}
from django.test import TestCase
# Create your tests here.
"""ablog URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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.urls import path , include
from . import views
urlpatterns = [
path('accounts/register' , views.register , name='register'),
path('accounts/login' , views.loginmanual , name='login'),
path('accounts/logout' , views.logoutmanual , name='logout'),
]
from django.shortcuts import render
from django.shortcuts import redirect
from django.contrib.auth import authenticate , login , logout
from django.contrib.auth.models import User
from theblog.models import alpha , total
# Create your views here.
def register(request):
if request.method == 'POST':
username = request.POST['username'].strip()
email = request.POST['email'].strip()
password1 = request.POST['password1'].strip()
password2 = request.POST['password2'].strip()
if len(username) == 0 or len(email) == 0:
return render(request, 'users/register.html' , {'message':"Username or Email Can't be empty."})
elif User.objects.filter(username=username).exists():
return render(request, 'users/register.html' , {'message':'Username is already taken.'})
elif User.objects.filter(email=email).exists():
return render(request, 'users/register.html' , {'message':'Already have an account with this E-mail id.'})
elif password1 != password2:
return render(request, 'users/register.html' , {'message':"Passwords don't match."})
else:
user = User.objects.create_user(username=username,password=password1,email=email)
user.save()
login(request,user)
x = alpha(userid = request.user)
x.save()
y = total(userid = request.user)
y.save()
return redirect('/')
else:
return render(request , 'users/register.html', {'message':''})
def loginmanual(request):
if request.method == 'POST':
username = request.POST['username'].strip()
password = request.POST['password'].strip()
user = authenticate(request , username=username, password=password)
if user is not None:
login(request,user)
return redirect ('/')
else:
return render(request , 'users/login.html' , {'message':'Invalid credentials. Either username or password is incorrect'})
else:
return render(request , 'users/login.html' , {'message':''})
def logoutmanual(request):
logout(request)
return redirect('/')
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