Commit c7c1580b authored by JAYABRATA DAS's avatar JAYABRATA DAS

Minor changes in README file. A Django project file has been added

parent b4f30ac0
"""
ASGI config for djangocc 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.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangocc.settings')
application = get_asgi_application()
"""
Django settings for djangocc project.
Generated by 'django-admin startproject' using Django 3.0.8.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&8au3j52pd#kly4(yk7jy$de5_fd$uv(f7&wth_35b@i0p3v(-'
# 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',
'flashcards'
]
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 = 'djangocc.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = 'djangocc.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
"""djangocc URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from . import views
from django.conf.urls import url, include
urlpatterns = [
#path('home/', views.home, name='Home'),
#path('admin/', admin.site.urls),
url(r'^$', views.main, name= 'Main'),
url(r'^$', views.home, name='Home'),
url(r'^admin/', admin.site.urls),
url(r'^flashcards/', include(('flashcards.urls', 'flashcards'), namespace='flashcards'))
]
from django.http import HttpResponse
from django.shortcuts import render
def home(request):
# return HttpResponse("Welcom to my Website. :)\nThanks for visiting")
days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thurstda', 'Friday', 'Saturday']
#days_of_week = []
greeting = "my first website"
context = {'our_greeting':greeting, 'weekday_list': days_of_week}
return render(request, 'home.html', context)
def main(request):
context = {}
return render(request, 'main.html', context)
\ No newline at end of file
"""
WSGI config for djangocc 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.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangocc.settings')
application = get_wsgi_application()
from django.contrib import admin
from .models import Deck, Card
def stateTrue(modeladmin, request,queryset):
rows_updated = queryset.update(state=True)
if rows_updated ==1:
msg = "1 deck has been"
else:
msg = "%s decks have been" %rows_updated
modeladmin.message_user(request,"%s successfully marked as active." %msg)
stateTrue.short_description="Change State to Active"
def stateFalse(modeladmin, request,queryset):
queryset.update(state=False)
stateFalse.short_description="Change State to Inactive"
class DeckAdmin(admin.ModelAdmin):
list_display=('title','state', 'getCardCount', 'description')
list_filter=('state',)
search_fields=['title','description']
actions = [stateTrue, stateFalse]
class CardAdmin(admin.ModelAdmin):
pass
# Register your models here.
admin.site.register(Deck, DeckAdmin)
admin.site.register(Card, CardAdmin)
\ No newline at end of file
from django.apps import AppConfig
class FlashcardsConfig(AppConfig):
name = 'flashcards'
from django.forms import ModelForm
from .models import Deck, Card
class DeckForm(ModelForm):
class Meta:
model = Deck
fields = ['title', 'description', 'state']
class CardForm(ModelForm):
class Meta:
model = Card
fields = [ 'parentDeck', 'front', 'back' ]
\ No newline at end of file
# Generated by Django 3.0.8 on 2020-07-07 10:15
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Deck',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=64)),
('description', models.CharField(blank=True, max_length=255)),
],
),
]
# Generated by Django 3.0.8 on 2020-07-07 17:33
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('flashcards', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Card',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('front', models.TextField()),
('back', models.TextField()),
('parentDeck', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='flashcards.Deck')),
],
),
]
# Generated by Django 3.0.8 on 2020-07-07 18:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('flashcards', '0002_card'),
]
operations = [
migrations.AddField(
model_name='deck',
name='state',
field=models.BooleanField(default=False),
),
]
from django.db import models
# Create your models here.
class Deck(models.Model):
title = models.CharField(max_length=64, null=False, blank=False)
description = models.CharField(max_length=255, null=False, blank=True)
state = models.BooleanField(default=False)
def __str__(self):
return self.title
def getCardCount(self):
return self.card_set.count()
#num = self.card_set.count()
#return '%s' %(num)
getCardCount.sort_description = 'Card Count'
class Card(models.Model):
parentDeck = models.ForeignKey(Deck, on_delete=models.CASCADE)
front = models.TextField()
back = models.TextField()
def __str__(self):
return self.front
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<form method="POST" >
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Save Card">
</form>
{% if edit_mode2 %}
<p>Do you want delete thid deck?</p>
<button><a href="{% url 'flashcards:deleteCard' card_obj.id %}">Delete Deck</a></button>
{% endif %}
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<form method="POST" >
{% csrf_token %}
<!-- <label for="form_title">Title: </label><br>
<input type="text" id="form_title" name="title"><br>
<label for="form_description">Description: </label><br>
<input type="text" id="form_description" name="description"><br><br>
<label>State:</label><br>
<input type="radio" name="state" value=True>
<label>Active</label><br>
<input type="radio" name="state" value=False>
<label>Inactive</label><br><br> -->
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Save Deck">
</form>
{% if edit_mode %}
<p>Do you want delete thid deck?</p>
<button><a href="{% url 'flashcards:deleteDeck' deck_obj.id %}">Delete Deck</a></button>
{% endif %}
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<div id="container">
<div class="mainpage-banner">
<h1>Poke Dex</h1>
<hr>
<a class="my-button2" href="{% url 'flashcards:createDeck' %}">Create New Deck</a>
<h4>Please select a deck below!</h4>
</div>
{% if decks %}
{% for deck in decks %}
<a class="my-button" href="{% url 'flashcards:viewDeck' deck.id %}">{{deck.title}}</a>
<!-- <h4>{{deck.description}} </h4> -->
{% endfor %}
{% else %}
<h1>No decks found. Contact admin</h1>
{% endif %}
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<div class="deck-hader">
<div class="deck-header-title">
<h2>Pokemon: {{deck_obj}}</h2>
<h2>Description: {{deck_obj.description}}</h2>
</div>
<div class="deck-header-action">
<a class="my-button3" href="{% url 'flashcards:editDeck' deck_obj.id %}">Edit Deck</a><br>
{% if card_obj %}
<a class="my-button3" href="{% url 'flashcards:editCard' card_obj.id %}">Edit Card</a>
{% else %}
<a class="my-button3" href="{% url 'flashcards:createCard' deck_obj.id %}">Add Card</a><br>
{% endif %}
<!-- {% if edit_mode %} -->
<!-- <a class="my-button3" href="{% url 'flashcards:editCard' deck_obj.id card_obj.id %}">Edit Card</a><br> -->
<!-- {% endif %} -->
</div>
</div>
<hr>
{% if card_obj %}
<h5>First Attack: {{card_obj.front}}</h5>
<h5>Second Attack: {{card_obj.back}}</h5>
{% else %}
<p>No card found!</p>
{% endif %}
{% endblock %}
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
from django.conf.urls import url
urlpatterns = [
#path('home/', views.home, name='Home'),
#path('admin/', admin.site.urls),
url(r'^$', views.home, name='Home'),
url(r'decks/create/',views.createDeck, name='createDeck'),
url(r'decks/view/(?P<deck_id>[\d]+)',views.viewDeck, name='viewDeck'),
url(r'decks/edit/(?P<deck_id>[\d]+)',views.editDeck, name='editDeck'),
url(r'decks/delete/(?P<deck_id>[\d]+)',views.deleteDeck, name='deleteDeck'),
#url(r'^main/', views.main, name= 'Main')
url(r'cards/create/(?P<deck_id>[\d]+)',views.createCard, name='createCard'),
url(r'cards/edit/(?P<card_id>[\d]+)',views.editCard, name='editCard'),
url(r'cards/delete/(?P<card_id>[\d]+)',views.deleteCard, name='deleteCard')
]
from django.shortcuts import (
get_object_or_404,
HttpResponseRedirect,
render
)
from django.urls import reverse
from .models import Deck, Card
from .forms import DeckForm, CardForm
# Create your views here.
def home(request):
qs = Deck.objects.order_by('title').filter(state=True)
context = {'decks': qs}
return render(request, 'flashcards/home.html', context)
def createCard(request, deck_id):
deck_obj = get_object_or_404(Deck, id=deck_id)
if request.method == 'POST':
form = CardForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('flashcards:viewDeck',args=[deck_obj.id]))
else:
form = CardForm(initial={'parentDeck': deck_obj})
context={'form': form}
return render(request, 'flashcards/createAndEditCard.html',context)
def editCard(request, card_id):
card_obj = get_object_or_404(Card, id=card_id)
if request.method == 'POST':
form = CardForm(request.POST, instance=card_obj)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('flashcards:viewDeck',args=[card_obj.parentDeck.id]))
else:
form = CardForm(instance=card_obj)
print("CARD OBJRCT",card_obj.id,card_id,":",card_obj)
context={'form': form, 'edit_mode2': True, 'card_obj': card_obj}
return render(request, 'flashcards/createAndEditCard.html',context)
def deleteCard(request, card_id):
card_obj = get_object_or_404(Card, id=card_id)
card_obj.delete();
return HttpResponseRedirect(reverse('flashcards:viewDeck',args=[card_obj.parentDeck.id]))
def createDeck(request):
# if request.method == 'POST':
# title_input = request.POST.get('title',None)
# description_input = request.POST.get('description',None)
# '''
# if 'state'==True in request.POST:
# state_input = True
# else:
# state_input = False
# '''
# state_input = request.POST.get('state',None)
# new_deck = Deck(title = title_input,
# description = description_input,
# state = state_input)
# new_deck.save()
# print("************ NEW DECK SAVED *************")
# print(request.POST)
# print('state' in request.POST)
# print("************ NEW DECK SAVED *************")
if request.method == 'POST':
form = DeckForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('flashcards:Home'))
else:
form = DeckForm()
context={'form': form}
return render(request, 'flashcards/createDeck.html',context)
def viewDeck(request, deck_id):
deck_obj = get_object_or_404(Deck, id=deck_id)
card_list = deck_obj.card_set.all()
card_obj = card_list.first()
print("DECK OBJRCT ID: ",deck_obj.id)
print(deck_obj)
if card_obj:
print("CARD OBJRCT ID: ",card_obj.id)
print(card_list)
context = { 'deck_obj': deck_obj, 'card_obj': card_obj}
return render(request, 'flashcards/viewDeck.html',context)
def editDeck(request, deck_id):
deck_obj = get_object_or_404(Deck, id=deck_id)
if request.method == 'POST':
form = DeckForm(request.POST, instance=deck_obj)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('flashcards:viewDeck',args=[deck_id]))
else:
form = DeckForm(instance=deck_obj)
context={'form': form, 'edit_mode':True, 'deck_obj': deck_obj}
return render(request, 'flashcards/createDeck.html',context)
def deleteDeck(request, deck_id):
deck_obj = get_object_or_404(Deck, id=deck_id)
deck_obj.delete();
return HttpResponseRedirect(reverse('flashcards:Home'))
\ No newline at end of file
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangocc.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()
body{
margin: 0;
}
nav{
background: #d0f1b0;
padding: 5px;
border-radius: 5px;
}
nav a{
color: black;
text-decoration: none;
font-size: 1.25em;
padding: 5px;
}
.container{
width: 80%;
min-width: 400px;
margin: 0 auto;
}
.mainpage-banner{
text-align: center;
color: #648e2c;
font-size: 2em;
max-width: 100%;
}
.mainpage-banner hr{
width: 20%;
}
.my-button{
display: block;
width: 200px;
margin: 10px auto;
background-color: #4CAF50;
border: none;
border-radius: 10px;
padding: 10px;
color: #ffffff;
text-decoration: none;
text-align: center;
}
.my-button2{
display: block;
width: 400px;
margin: 10px auto;
background-color: #648e2c;
border: none;
border-radius: 10px;
padding: 10px;
color: #ffffff;
text-decoration: none;
text-align: center;
}
.my-button3{
display: block;
width: 100px;
margin: 0px auto;
background-color: #648e2c;
border: none;
border-radius: 10px;
padding: 5px;
color: #ffffff;
text-decoration: none;
text-align: center;
}
.deck-hader{
/*background-color: grey;*/
display: block;
margin-top: 20px;
overflow: auto;
/*height: 2000px;*/
}
.deck-header-title{
float: left;
width: 70%;
color: #4CAF50;
}
.deck-header-action{
float: right;
width: 30%;
color: red;
text-align: right;
}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>MyAPP</title>
<link rel="stylesheet" href="{% static 'css/style.css' %}" />
</head>
<body>
<div id="container">
<nav>
<a href="{% url 'Home' %}">Home</a> |
<a href="{% url 'Main' %}">Main</a> |
<a href="{% url 'flashcards:Home' %}">Decks</a> |
<a href="">About</a> |
<a href="">Contacts</a>
{% if request.user.is_superuser %}
| <a href="{% url 'admin:index' %">Admin</a>
{% endif %}
</nav>
</div>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>MyAPP</title>
<link rel="stylesheet" href="{% static 'css/style.css' %}" />
</head>
<body>
<div id="container">
<h1>Welcome to {{ our_greeting | title }}!</h1>
{% if weekday_list %}
<ul>
{% for day in weekday_list %}
<li>{{day|slice:":3"}}</li>
{% endfor %}
</ul>
{% else %}
<p>Days of Week is not Defined</p>
{% endif %}
<hr>
<a href="main">main</a>
</div>
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<div class="mainpage-banner">
<h1>My Website!!</h1>
<hr>
<h3>Some Catchy line</h3>
<a class="my-button" href="{% url 'flashcards:Home' %}">Get started</a>
</div>
{% endblock %}
\ No newline at end of file
...@@ -2,4 +2,5 @@ Name: Jayabrata Das ...@@ -2,4 +2,5 @@ Name: Jayabrata Das
Stream: CSE Stream: CSE
College: IIT Bombay College: IIT Bombay
Course: MTech Course: MTech
Year: 2
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