summaryrefslogtreecommitdiff
path: root/tbc/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'tbc/views.py')
-rwxr-xr-xtbc/views.py75
1 files changed, 61 insertions, 14 deletions
diff --git a/tbc/views.py b/tbc/views.py
index 8af5c2e..1fa3384 100755
--- a/tbc/views.py
+++ b/tbc/views.py
@@ -164,6 +164,7 @@ def UserLogin(request):
def UserRegister(request):
+ context = {}
if request.method == 'POST':
form = UserRegisterForm(request.POST)
if form.is_valid():
@@ -177,13 +178,13 @@ def UserRegister(request):
return render_to_response('tbc/register.html', context)
else:
form = UserRegisterForm()
- context = {}
context.update(csrf(request))
context['form'] = form
return render_to_response('tbc/register.html', context)
def UserProfile(request):
+ context = {}
user = request.user
if user.is_authenticated():
if request.method == 'POST':
@@ -199,13 +200,11 @@ def UserProfile(request):
add_log(user, user, CHANGE,'Profile entry')
return HttpResponseRedirect('/')
else:
- context = {}
context.update(csrf(request))
context['form'] = form
return render_to_response('tbc/profile.html', context)
else:
form = UserProfileForm()
- context = {}
context.update(csrf(request))
context['form'] = form
context['user'] = user
@@ -262,8 +261,8 @@ def ForgotPassword(request):
def UpdatePassword(request):
- user = request.user
context = {}
+ user = request.user
context.update(csrf(request))
if user.is_authenticated():
if request.method == 'POST':
@@ -300,8 +299,8 @@ def UpdatePassword(request):
def SubmitBook(request):
- curr_user = request.user
context = {}
+ curr_user = request.user
if request.method == 'POST':
form = BookForm(request.POST)
if form.is_valid():
@@ -621,6 +620,7 @@ def SubmitSample(request, proposal_id=None, old_notebook_id=None):
def UpdateBook(request):
+ context = {}
current_user = request.user
user_profile = Profile.objects.get(user=current_user)
try:
@@ -630,7 +630,6 @@ def UpdateBook(request):
title = book_to_update.title
chapters = Chapters.objects.filter(book=book_to_update)
screenshots = ScreenShots.objects.filter(book=book_to_update)
- context = {}
if request.method == 'POST':
book_form = BookForm(request.POST, instance=book_to_update)
if book_form.is_valid():
@@ -714,11 +713,11 @@ def SubmitCode(request):
def UpdateContent(request, book_id=None):
+ context = {}
user = request.user
current_book = Book.objects.get(id=book_id)
chapters_to_update = Chapters.objects.filter(book=current_book)
screenshots_to_update = ScreenShots.objects.filter(book=current_book)
- context = {}
if request.method == 'POST':
for i in range(1, current_book.no_chapters+1):
chapter = Chapters.objects.get(id=chapters_to_update[i-1].id)
@@ -797,7 +796,7 @@ def BookDetails(request, book_id=None):
else:
context['user'] = request.user
book = Book.objects.get(id=book_id)
- chapters = Chapters.objects.filter(book=book)
+ chapters = Chapters.objects.filter(book=book).order_by('name')
images = ScreenShots.objects.filter(book=book)
context['chapters'] = chapters
context['images'] = images
@@ -810,7 +809,7 @@ def BookReview(request, book_id=None):
if is_reviewer(request.user):
if book_id:
book = Book.objects.get(id=book_id)
- chapters = Chapters.objects.filter(book=book)
+ chapters = Chapters.objects.filter(book=book).order_by('name')
images = ScreenShots.objects.filter(book=book)
proposal = Proposal.objects.get(accepted=book)
logs = ActivityLog.objects.filter(proposal_id=proposal.id)
@@ -838,8 +837,8 @@ def BookReview(request, book_id=None):
def ApproveBook(request, book_id=None):
- user = request.user
context = {}
+ user = request.user
if is_reviewer(request.user):
if request.method == 'POST' and request.POST['approve_notify'] == "approve":
book = Book.objects.get(id=book_id)
@@ -849,13 +848,14 @@ def ApproveBook(request, book_id=None):
proposal.status = "book completed"
proposal.save()
file_path = os.path.abspath(os.path.dirname(__file__))
- zip_path = "/".join(file_path.split("/")[1:-2])
- zip_path = "/"+zip_path+"/Python-Textbook-Companions/"
+ copy_path = "/".join(file_path.split("/")[1:-2])
+ copy_path = "/"+copy_path+"/Python-Textbook-Companions/"
file_path = file_path+"/static/uploads/"
directory = file_path+book.contributor.user.first_name
os.chmod(directory, 0777)
os.chdir(directory)
- fp = open(book.title+"/README.txt", 'w')
+ book_title = book.title.replace(" ", "_")
+ fp = open(book_title+"/README.txt", 'w')
fp.write("Contributed By: "+book.contributor.user.first_name+" "+book.contributor.user.last_name+"\n")
fp.write("Course: "+book.contributor.course+"\n")
fp.write("College/Institute/Organization: "+book.contributor.insti_org+"\n")
@@ -867,7 +867,7 @@ def ApproveBook(request, book_id=None):
fp.write("Isbn: "+book.isbn+"\n")
fp.write("Edition: "+book.edition)
fp.close()
- x = shutil.copytree(book.title, zip_path+book.title)
+ os.popen("cp -r '"+book_title+"' '"+copy_path+"'")
subject = "Python-TBC: Book Completion"
message = "Hi "+book.contributor.user.first_name+",\n"+\
"Congratulations !\n"+\
@@ -955,6 +955,7 @@ def BrowseBooks(request):
def ConvertNotebook(request, notebook_path=None):
+ context = {}
path = os.path.abspath(os.path.dirname(__file__))
path = path+"/static/uploads/"
path = path+notebook_path
@@ -974,6 +975,52 @@ def ConvertNotebook(request, notebook_path=None):
return render_to_response(template, {})
+def CompletedBooks(request):
+ context = {}
+ context.update(csrf(request))
+ category = "All"
+ if request.user.is_anonymous():
+ context['anonymous'] = True
+ else:
+ if is_reviewer(request.user):
+ context['reviewer'] = request.user
+ else:
+ context['user'] = request.user
+ if request.method == "POST":
+ category = request.POST['category']
+ if category == "all":
+ completed_books = Book.objects.filter(approved=True)
+ else:
+ completed_books = Book.objects.filter(category=category, approved=True)
+ else:
+ completed_books = Book.objects.filter(approved=True)
+ context['category'] = category
+ context['completed_books'] = completed_books
+ return render_to_response('tbc/completed_books.html', context)
+
+
+def BooksUnderProgress(request):
+ context = {}
+ images = []
+ if request.user.is_anonymous():
+ context['anonymous'] = True
+ else:
+ if is_reviewer(request.user):
+ context['reviewer'] = request.user
+ else:
+ context['user'] = request.user
+ return render_to_response('tbc/books_under_progress.html', context)
+
+
+def RedirectToIpynb(request, notebook_path=None):
+ context = {}
+ notebook = notebook_path.split("/")
+ notebook[0] = "notebooks"
+ notebook = "/".join(notebook)
+ redirect_url = "https://ipynb.fossee.in/"+notebook
+ return redirect(redirect_url)
+
+
# ajax views
@csrf_exempt
def ajax_matching_books(request):