Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary files #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions calculate/admin.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
from django.contrib import admin
from calculate.models import UserProfile,Myindex,Expectedindex,IndexNumber,CourseCode,Email, Applicant
from calculate.models import Email, Applicant
# Register your models here.





class MyIndexAdmin(admin.ModelAdmin):
list_display = ('index','views')


class IndexAdmin(admin.ModelAdmin):
list_display = ('index','course','post')

class CourseAdmin(admin.ModelAdmin):
list_display = ('code','views')

class EmailAdmin(admin.ModelAdmin):
list_display = ('name','email','message')

admin.site.register(UserProfile)
admin.site.register(Applicant)
admin.site.register(Myindex,MyIndexAdmin)
admin.site.register(Expectedindex)
admin.site.register(IndexNumber,IndexAdmin)
admin.site.register(CourseCode,CourseAdmin)
admin.site.register(Email,EmailAdmin)
45 changes: 1 addition & 44 deletions calculate/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django import forms
from calculate.models import UserProfile,Myindex,Expectedindex,CourseCode,IndexNumber,Email, Applicant
from django.contrib.auth.models import User
from calculate.models import Email, Applicant


class SwapForm(forms.ModelForm):
Expand All @@ -14,48 +13,6 @@ class Meta:
model = Applicant
fields = ('name','email','code','current','expected')

class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
class Meta:
model = User
fields = ('username', 'email', 'password')

class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ('picture',)


class MyIndexForm(forms.ModelForm):
index = forms.CharField(max_length=100, help_text="Please enter your index.")
views = forms.IntegerField(widget=forms.HiddenInput(), initial=0)
class Meta:
model = Myindex
fields = ('index','views')


class ExpectedIndexForm(forms.ModelForm):
expectedindex = forms.CharField(max_length=100, help_text="Please enter the index you want.")
views = forms.IntegerField(widget=forms.HiddenInput(),initial=0)
class Meta:
model = Expectedindex
fields = ('expectedindex','views')

class CourseForm(forms.ModelForm):
code = forms.CharField(max_length=50,help_text="Please enter a Course code.")
views = forms.IntegerField(widget=forms.HiddenInput(),initial=0)
class Meta:
model = CourseCode
fields = ('code','views')

class IndexForm(forms.ModelForm):
index = forms.IntegerField(initial=0,help_text="Please enter a index.")
post = forms.IntegerField(widget=forms.HiddenInput(),initial=0)
class Meta:
model = IndexNumber
fields = ('index','post')


class ContactForm(forms.Form):
name = forms.CharField()
email = forms.EmailField()
Expand Down
40 changes: 0 additions & 40 deletions calculate/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
# Create your models here.

Expand All @@ -12,45 +11,6 @@ class Applicant(models.Model):
expected = models.CharField(max_length=5)
date = models.DateTimeField(default=timezone.now)

class UserProfile(models.Model):
# This line is required. Links UserProfile to a User model instance.
user = models.OneToOneField(User,on_delete=models.CASCADE)
# The additional attributes we wish to include.
picture = models.ImageField(upload_to='profile_images', blank=True)
# Override the __unicode__() method to return out something meaningful!
def __unicode__(self):
return self.user.username


class Myindex(models.Model):
index = models.CharField(max_length=100)
views = models.IntegerField(default=0)
def __unicode__(self):
return self.index


class Expectedindex(models.Model):
myindex = models.ManyToManyField(Myindex)
expectedindex = models.CharField(max_length=100)
views = models.IntegerField(default=0)
def __unicode__(self):
return self.expectedindex


class CourseCode(models.Model):
code = models.CharField(max_length=50,unique=True)
views = models.IntegerField(default=0)
def __unicode__(self):
return self.code

class IndexNumber(models.Model):
course = models.ForeignKey(CourseCode,null=True,on_delete=models.SET_NULL)
index = models.IntegerField(default=0)
post = models.IntegerField(default=0)
def __unicode__(self):
return self.index


class Email(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField(max_length=50)
Expand Down
34 changes: 11 additions & 23 deletions calculate/urls.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@

from django.conf.urls import url
from django.conf.urls import url
from django.urls import path
from . import views

urlpatterns = [
url(r'^home/$',views.mainpage,name='home'),
url(r'^contact/$',views.contact,name='contact'),
url(r'^contact/success/$',views.successView,name='success'),
url(r'^timetable/$',views.timetable,name='timetable'),
url(r'^timetable/search/$', views.search,name='search'),
url(r'^forum/$',views.temp,name='temp'),
url(r'^forum/match$',views.matchsuccess,name='match'),
url(r'^forum/nomatch$',views.nomatch,name='nomatch'),

url(r'^login/$',views.user_login,name='login'),
url(r'^logout/$', views.user_logout, name='logout'),
url(r'^register/$', views.register, name='register'),
url(r'^forum/(?P<coursecode1_name_url>\w+)/$', views.coursecode, name='coursecode'),
url(r'^add_myindex/$', views.add_myindex, name='add_myindex'),
#url(r'^forum/$',views.forum,name='forum'),
#url(r'^forum/(?P<myindex_name_url>\w+)/$', views.myindex, name='myindex'),


#url(r'^forum/(?P<myindex_name_url>\w+)/add_expectedindex/$', views.add_expectedindex, name='add_expectedindex'),
#url(r'^/forum/(?P<myindex_name_url>\w+)/(?P<expectedindex_name_url>\w+)/$', views.expectedindex, name='expectedindex'),
]
path('home/',views.mainpage,name='home'),
path('contact/',views.contact,name='contact'),
path('contact/success/',views.successView,name='success'),
path('timetable/',views.timetable,name='timetable'),
path('timetable/search/', views.search,name='search'),
path('forum/',views.temp,name='temp'),
path('forum/match',views.matchsuccess,name='match'),
path('forum/nomatch',views.nomatch,name='nomatch'),

]
155 changes: 3 additions & 152 deletions calculate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
from django.views.decorators import csrf
import os, sys
from coursearrangement import solve
from django.contrib.auth import authenticate,login,logout
from django.contrib.auth.decorators import login_required
from calculate.models import Myindex,Expectedindex,CourseCode,IndexNumber,Applicant
from calculate.forms import MyIndexForm,ExpectedIndexForm,ContactForm, SwapForm
from calculate.models import Applicant
from calculate.forms import ContactForm,SwapForm
from coursearrangement.display import writecontent
from django.core.mail import send_mail, BadHeaderError
import random
Expand Down Expand Up @@ -85,10 +83,6 @@ def search(request):
name = chr(ord(name)+1)
i = i+1





list.reverse()
answer = solve.allCombination(list,names)
if answer:
Expand Down Expand Up @@ -190,7 +184,7 @@ def matchsuccess(request):
send_mail("Course Swapping MATCH!",message(name,code,current,expected,result["name"],result["email"]),"[email protected]",[email,])
send_mail("Course Swapping MATCH!",message(result["name"],code,expected,current,name,email),"[email protected]",[result["email"],])

#delte ppl from both of the database
#delete ppl from both of the database
p1 = Applicant.objects.get(name=name,code=code,current=current,expected=expected,email=email)
p1.delete()
p2 = Applicant.objects.get(id=result["id"])
Expand Down Expand Up @@ -252,82 +246,6 @@ def encode_url(str):
def decode_url(str):
return str.replace('_', ' ')





def user_login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
# Is the account active? It could have been disabled.
if user.is_active:
login(request, user)
return HttpResponseRedirect('/home/')
else:
return HttpResponse("Your Rango account is disabled.")
else:
print("Invalid login details: {0}, {1}".format(username, password))
return HttpResponse("Invalid login details supplied.")
else:
return render(request,'login.html', {},)




@login_required
def user_logout(request):
# Since we know the user is logged in, we can now just log them out.
logout(request)
# Take the user back to the homepage.
return HttpResponseRedirect('/home/')

from calculate.forms import UserForm, UserProfileForm
def register(request):
# Like before, get the request's context.
# A boolean value for telling the template whether the registration was successful.
# Set to False initially. Code changes value to True when registration succeeds.
registered = False
# If it's a HTTP POST, we're interested in processing form data.
if request.method == 'POST':
# Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm.
user_form = UserForm(data=request.POST)
profile_form = UserProfileForm(data=request.POST)
# If the two forms are valid...
if user_form.is_valid() and profile_form.is_valid():
# Save the user's form data to the database.
user = user_form.save()
# Now we hash the password with the set_password method.
# Once hashed, we can update the user object.
user.set_password(user.password)
user.save()
# Now sort out the UserProfile instance.
# Since we need to set the user attribute ourselves, we set commit=False.
# This delays saving the model until we're ready to avoid integrity problem
profile = profile_form.save(commit=False)
profile.user = user
# Did the user provide a profile picture?
# If so, we need to get it from the input form and put it in the UserProfile model.
if 'picture' in request.FILES:
profile.picture = request.FILES['picture']

profile.save()
registered = True
# Invalid form or forms - mistakes or something else? # Print problems to the terminal.
# They'll also be shown to the user.
else:
print(user_form.errors, profile_form.errors)

# Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input.
else:
user_form = UserForm()
profile_form = UserProfileForm()
# Render the template depending on the context.
return render(request,'register.html',{'user_form': user_form, 'profile_form': profile_form, 'registered': registered})


def get_coursecode_list(max_results=0, starts_with=''):
coursecode_list = []
if starts_with:
Expand Down Expand Up @@ -390,70 +308,3 @@ def coursecode(request,coursecode1_name_url):
pass

return render(request,'coursecode.html', context_dict)


def myindex(request, myindex_name_url):
myindex_name = decode_url(myindex_name_url)
context_dict = {'myindex_name': myindex_name, 'myindex_name_url': myindex_name_url}


try:
myindex = Myindex.objects.get(index=myindex_name)
context_dict['myindex'] = myindex
Expectedindexes = Expectedindex.objects.filter(myindex=myindex).order_by('-views')
context_dict['expectedindexes'] = Expectedindexes
except Myindex.DoesNotExist:
pass

# Go render the response and return it to the client.
return render(request,'myindex.html', context_dict)


def add_myindex(request):
context_dict = {}

# A HTTP POST?
if request.method == 'POST':
form = MyIndexForm(request.POST)

# Have we been provided with a valid form?
if form.is_valid():
# Save the new myindex to the database.
form.save(commit=True)
return HttpResponseRedirect('/forum/')
else:
# The supplied form contained errors - just print them to the terminal.
print(form.errors)
else:
# If the request was not a POST, display the form to enter details.
form = MyIndexForm()

# Bad form (or form details), no form supplied...
# Render the form with error messages (if any).
context_dict['myindex_form'] = form
return render(request,'add_myindex.html', context_dict)


def add_expectedindex(request, myindex_name_url):

context_dict = {}

myindex_name = decode_url(myindex_name_url)
context_dict['myindex_name'] = myindex_name
context_dict['myindex_name_url'] = myindex_name_url
x = Myindex.objects.get(index=myindex_name)
if request.method == 'POST':
form = ExpectedIndexForm(request.POST)
if form.is_valid():
ex = form.save()
ex.views = 0
ex.myindex.add(x)
ex.save()
path = '/forum/'+myindex_name_url
return HttpResponseRedirect(path)
else:
print(form.errors)
else:
form = ExpectedIndexForm()
context_dict['form']=form
return render(request,'add_expectedindex.html',context_dict)
2 changes: 1 addition & 1 deletion simplesite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

ROOT_URLCONF = 'simplesite.urls'

TEMPLATES_PATH = os.path.join(BASE_DIR, 'templetes')
TEMPLATES_PATH = os.path.join(BASE_DIR, 'templates')

TEMPLATES = [
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions templetes/add_expectedindex.html

This file was deleted.

Loading