diff options
-rw-r--r-- | tbc_error_page/broken.json | 130 | ||||
-rw-r--r-- | tbc_error_page/error.json | 194 | ||||
-rw-r--r-- | tbc_error_page/models.py | 107 | ||||
-rw-r--r-- | tbc_error_page/views.py | 56 |
4 files changed, 487 insertions, 0 deletions
diff --git a/tbc_error_page/broken.json b/tbc_error_page/broken.json new file mode 100644 index 0000000..4cfeb7b --- /dev/null +++ b/tbc_error_page/broken.json @@ -0,0 +1,130 @@ +(lp1 +(dp2 +Vbroken_status +p3 +I500 +sVbroken_url +p4 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Fluid_Mechanics_by_John_F_Douglass/Chapter_3.ipynb +p5 +sa(dp6 +Vbroken_status +p7 +I500 +sVbroken_url +p8 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Elements_of_Electric_drives/Chapter1_2.ipynb +p9 +sa(dp10 +Vbroken_status +p11 +I500 +sVbroken_url +p12 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_20_Radiochemistry.ipynb +p13 +sa(dp14 +Vbroken_status +p15 +I500 +sVbroken_url +p16 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Elements_of_Electric_drives/Chapter3_2.ipynb +p17 +sa(dp18 +Vbroken_status +p19 +I500 +sVbroken_url +p20 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Theory_Of_Machines/ch15.ipynb +p21 +sa(dp22 +Vbroken_status +p23 +I500 +sVbroken_url +p24 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Principles_Of_Electronic_Communication_Systems_by_L_E_Frenzechapter13_1.ipynb +p25 +sa(dp26 +Vbroken_status +p27 +I500 +sVbroken_url +p28 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_12_Thermodynamics_Thermodynamic_chemistry.ipynb +p29 +sa(dp30 +Vbroken_status +p31 +I500 +sVbroken_url +p32 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_7_Conductivity.ipynb +p33 +sa(dp34 +Vbroken_status +p35 +I500 +sVbroken_url +p36 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Principles_Of_Electronic_Communication_Systems_by_L_E_Frenze/chapter22_1.ipynb +p37 +sa(dp38 +Vbroken_status +p39 +I500 +sVbroken_url +p40 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_13_Thermodynamics_Entropy_and_Free_Energy.ipynb +p41 +sa(dp42 +Vbroken_status +p43 +I500 +sVbroken_url +p44 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/_Diffusion:_Mass_Transfer_In_Fluid_Systems_by__E._L._Cussler/Chapter_10_Absorption.ipynb +p45 +sa(dp46 +Vbroken_status +p47 +I500 +sVbroken_url +p48 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Aircraft_Structures_for_Engineering_Students/Chapter24_1.ipynb +p49 +sa(dp50 +Vbroken_status +p51 +I500 +sVbroken_url +p52 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Aircraft_Structures_for_Engineering_Students/Chapter20_1.ipynb +p53 +sa(dp54 +Vbroken_status +p55 +I500 +sVbroken_url +p56 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_9_Ionic_Equilibria_and_Buffer_Action.ipynb +p57 +sa(dp58 +Vbroken_status +p59 +I500 +sVbroken_url +p60 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/_Optical_Fiber_Communication_by_V._S._Bagad/Chapter02-Optical_Fiber_for_Telecommunication.ipynb +p61 +sa(dp62 +Vbroken_status +p63 +I500 +sVbroken_url +p64 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Aircraft_Structures_for_Engineering_Students/Chapter01_1.ipynb +p65 +sa.
\ No newline at end of file diff --git a/tbc_error_page/error.json b/tbc_error_page/error.json new file mode 100644 index 0000000..56c952a --- /dev/null +++ b/tbc_error_page/error.json @@ -0,0 +1,194 @@ +(lp1 +(dp2 +Vchapter_urls +p3 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Beginning_C_By_Ivon_Horton/chapter13.ipynb +p4 +sVnumber_of_errors +p5 +I1 +sVchapter_name +p6 +VChapter 13: The Preprocessor and Debugging +p7 +sa(dp8 +Vchapter_urls +p9 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Schaum's_Outlines:_Programming_with_C++/ch6.ipynb +p10 +sVnumber_of_errors +p11 +I2 +sVchapter_name +p12 +VChapter 6: Arrays +p13 +sa(dp14 +Vchapter_urls +p15 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Schaum's_Outlines:_Programming_with_C++/ch4.ipynb +p16 +sVnumber_of_errors +p17 +I1 +sVchapter_name +p18 +VChapter 4: Iteration +p19 +sa(dp20 +Vchapter_urls +p21 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/The_C_Book/Chapter2.ipynb +p22 +sVnumber_of_errors +p23 +I1 +sVchapter_name +p24 +VChapter 2: Variables and Arithmetic +p25 +sa(dp26 +Vchapter_urls +p27 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Mastering_C/chapter8.ipynb +p28 +sVnumber_of_errors +p29 +I1 +sVchapter_name +p30 +VChapter 8: Pointers +p31 +sa(dp32 +Vchapter_urls +p33 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Practical_C_Programming/Chapter_13_1.ipynb +p34 +sVnumber_of_errors +p35 +I1 +sVchapter_name +p36 +VChapter 13: Simple pointers +p37 +sa(dp38 +Vchapter_urls +p39 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Programming_in_C/Chapter_17.ipynb +p40 +sVnumber_of_errors +p41 +I1 +sVchapter_name +p42 +VChapter 17: Miscellaneous and Advanced Features +p43 +sa(dp44 +Vchapter_urls +p45 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Programming_in_C/Chapter_16.ipynb +p46 +sVnumber_of_errors +p47 +I2 +sVchapter_name +p48 +VChapter 16: Input and Output Operations in Python +p49 +sa(dp50 +Vchapter_urls +p51 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/C++_Demystified:_A_Self-Teaching_Guide/chapter11.ipynb +p52 +sVnumber_of_errors +p53 +I1 +sVchapter_name +p54 +VChapter 11 - What\u2019s the Address? Pointers +p55 +sa(dp56 +Vchapter_urls +p57 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/ANSI_C_Programming/chapter12.ipynb +p58 +sVnumber_of_errors +p59 +I3 +sVchapter_name +p60 +VCHAPTER 12:FILE INPUT/OUTPUT +p61 +sa(dp62 +Vchapter_urls +p63 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter9_1.ipynb +p64 +sVnumber_of_errors +p65 +I1 +sVchapter_name +p66 +VChapter 9: Functions +p67 +sa(dp68 +Vchapter_urls +p69 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter19-ExceptionHandling_1.ipynb +p70 +sVnumber_of_errors +p71 +I1 +sVchapter_name +p72 +VChapter 19-Exception Handling +p73 +sa(dp74 +Vchapter_urls +p75 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Programming_With_Java_A_Primer/chapter17.ipynb +p76 +sVnumber_of_errors +p77 +I1 +sVchapter_name +p78 +VChapter 17: Assertion & Design by Contract +p79 +sa(dp80 +Vchapter_urls +p81 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/How_to_think_like_a_computer_scientist_by_Allen_B_Downey/ch15.ipynb +p82 +sVnumber_of_errors +p83 +I2 +sVchapter_name +p84 +VChapter 15 : File Input/Output and apmatrixes +p85 +sa(dp86 +Vchapter_urls +p87 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Structured_Programing_with_C++/Chapter5.ipynb +p88 +sVnumber_of_errors +p89 +I1 +sVchapter_name +p90 +VChapter 5 : Strings +p91 +sa(dp92 +Vchapter_urls +p93 +Vhttp://tbc-python.fossee.aero.iitb.ac.in/convert-notebook/Programming_With_Java_A_Primer/chapter13.ipynb +p94 +sVnumber_of_errors +p95 +I1 +sVchapter_name +p96 +VChapter 13: Managing Errors & Exceptions +p97 +sa.
\ No newline at end of file diff --git a/tbc_error_page/models.py b/tbc_error_page/models.py new file mode 100644 index 0000000..ceab789 --- /dev/null +++ b/tbc_error_page/models.py @@ -0,0 +1,107 @@ +from django.db import models +import os +import cPickle + +def get_json_from_file(filename): + path = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename) + if os.path.isfile(path): + with open(path) as json_dump: + json_data =cPickle.load(json_dump) + return json_data + else: + return False + + + +class Error(models.Model): + + chapter_url = models.URLField(max_length = 255) + number_of_errors = models.IntegerField() + chapter_name = models.CharField(max_length = 200,) + is_deliberate = models.IntegerField(default = False) + + def create_new_error_data(self, error_json_data): + # Populates an empty table + for error_details in error_json_data: + Error.objects.create(chapter_url = error_details["chapter_urls"], + chapter_name = error_details["chapter_name"], + number_of_errors = int(error_details["number_of_errors"]), + is_deliberate = 0 + ) + + def delete_redundant_error_data(self, error_json_data): + # delete errors which have been solved + for error_details in error_json_data: + db_url_list = Error.objects.values_list("chapter_url", flat=True) + json_url_list = [url_list["chapter_urls"] for url_list in error_json_data] + c = set(db_url_list)-set(json_url_list) #change variable name. + for somelist in c: + Error.objects.filter(chapter_url = somelist).delete() + + def update_error_data(self, error_json_data): + + # Agreeably hacky at the moment. Will refine it. + + for error_details in error_json_data: + # if number of errors have increased + if Error.objects.filter(chapter_url = error_details["chapter_urls"], + number_of_errors__lt = error_details["number_of_errors"]): + + Error.objects.filter(chapter_url = error_details["chapter_urls"])\ + .update(number_of_errors = error_details["number_of_errors"], + is_deliberate = 0 + ) + # if number of errors have decreased + elif Error.objects.filter(chapter_url = error_details["chapter_urls"], + number_of_errors__gt = error_details["number_of_errors"]): + + Error.objects.filter(chapter_url = error_details["chapter_urls"])\ + .update(number_of_errors = error_details["number_of_errors"], is_deliberate = 0) + else: + # if new errors have been added. + Error.objects.get_or_create(chapter_url = error_details["chapter_urls"], + number_of_errors = error_details["number_of_errors"] + ) + + Error.objects.filter(chapter_url = error_details["chapter_urls"])\ + .update(chapter_url = error_details["chapter_urls"], + number_of_errors = error_details["number_of_errors"], + chapter_name = error_details["chapter_name"] + ) + + + + def update_deliberate_error(self, deliberate_error_list): + + for deliberate_urls in deliberate_error_list: + a = Error.objects.filter(chapter_url = deliberate_urls).update(is_deliberate = 1) + + + + +class Broken(models.Model): + + broken_url = models.URLField(max_length = 255) + error_status = models.IntegerField() + + def create_new_broken_data(self, broken_data): + for broken_details in broken_data: + + Broken.objects.create(broken_url = broken_details["broken_url"], + error_status = broken_details["broken_status"]) + + def delete_redundant_broken_data(self, broken_data): + for broken_details in broken_data: + db_url_list = Broken.objects.values_list("broken_url", flat=True) + json_url_list = [url_list["broken_url"] for url_list in broken_data] + redundant_url = set(db_url_list)-set(json_url_list) #change variable name. + for delete_url in redundant_url: + Broken.objects.filter(broken_url = delete_url).delete() + + + def update_broken_data(self, broken_data): + for broken_details in broken_data: + + Broken.objects.get_or_create(broken_url = broken_details["broken_url"], + error_status = broken_details["broken_status"] + ) diff --git a/tbc_error_page/views.py b/tbc_error_page/views.py new file mode 100644 index 0000000..1b271ef --- /dev/null +++ b/tbc_error_page/views.py @@ -0,0 +1,56 @@ +from django.shortcuts import render_to_response +from .models import Error, Broken, get_json_from_file +from django.contrib.auth.decorators import user_passes_test +from django.template import RequestContext +import json +import os + + +#@login_required(login_url="/admin/login/") +@user_passes_test(lambda u:u.is_superuser, login_url="/admin/login") + + + +def error(req): + ci = RequestContext(req) + db_instance = Error() + error_json_data = get_json_from_file("error.json") + + if not Error.objects.exists(): + db_instance.create_new_error_data(error_json_data) + else: + db_instance.delete_redundant_error_data(error_json_data) + db_instance.update_error_data(error_json_data) + + error_details = Error.objects.filter(is_deliberate = 0) + + if req.method == "POST": + deliberate_urls_list = req.POST.getlist("deliberate") + db_instance.update_deliberate_error(deliberate_urls_list) + + context = {"user":req.user, "deliberate" :deliberate_urls_list} + + return render_to_response ("deliberate.html", context, ci) + + + context = {"context": error_details, "user": req.user} + return render_to_response ("error.html", context, ci) + +def broken(req): + + ci = RequestContext(req) + db_instance = Broken() + broken_json_data = get_json_from_file("broken.json") + + if not Broken.objects.exists(): + db_instance.create_new_broken_data(broken_json_data) + + else: + db_instance.delete_redundant_broken_data(broken_json_data) + db_instance.update_broken_data(broken_json_data) + + broken = Broken.objects.all() + context = {"broken": broken, "user": req.user} + return render_to_response("broken.html", context, ci) + + |