Ejemplo n.º 1
0
def download_tests_infolder(folder_id='1962',
                            folder_name="Name",
                            folder_type="question_bank"):
    obj = {}
    params = (('folder_id', folder_id), )
    response_tests = requests.get(
        'http://careeranna.edoola.com/manage/content/list/',
        headers=headers,
        params=params,
        cookies=cookies)
    output_testlist = response_tests.content
    doc_test = document_fromstring(output_testlist)
    tests_table = (doc_test.xpath("//table[contains(@class,'table')]/tr"))

    list_tests = []
    row = 0
    for test in tests_table:
        try:
            td = test.xpath("./td")
            test_obj = {}
            vanilla_link = td[0].xpath("./a/@href")[0]
            test_name = td[0].text_content()
            type = td[1].text_content()
            date_modified = td[2].text_content()
            question_count = td[3].text_content()
            score_count = td[4].text_content()
            questions_link = ("http://careeranna.edoola.com" +
                              vanilla_link.replace("/detail/", '/questions/'))
            details_link = ("http://careeranna.edoola.com" + vanilla_link)
            test_details_link = questions_link
            test_obj = {
                "name": cleanstring(test_name),
                "details_link": details_link,
                "question_link": questions_link,
                "type": cleanstring(type),
                "date_modified": cleanstring(date_modified),
                "score_count": score_count,
                "question_count": question_count
            }
            # list_tests.append(test_obj)
            if type != "Grouped Tests":
                EdoolaTests.objects.create(folder_name=folder_name,
                                           folder_id=folder_id,
                                           test_name=cleanstring(test_name),
                                           details_link=details_link,
                                           question_link=questions_link,
                                           type=cleanstring(type),
                                           folder_type=folder_type)
        except:
            print "Error"
            None
Ejemplo n.º 2
0
def download_folders():
    obj = {}
    response_folders = requests.get(
        'http://careeranna.edoola.com/manage/content/',
        headers=headers,
        cookies=cookies)
    output_folderlist = response_folders.content
    doc_folders = document_fromstring(output_folderlist)
    folder_table = (
        doc_folders.xpath("//table[contains(@id, 'folder_table')]/tr/td"))
    list_folders = []

    for folder in folder_table:
        folderobj = {}
        folder_name = ""
        folder_id = ""
        folder_id = folder.xpath("./@id")[0]
        folder_name = cleanstring(folder.text_content()).replace("1. ", "")
        i = 0
        if folder_name != "Blank" and folder_name != "Default Folder" and folder_name != "External Content" and folder_name != "" and folder_name != "Licensed Content":

            if folder_name in test_bank_folders:
                folder_type = "test_bank"
            else:
                folder_type = "question_bank"

            EdoolaFolders.objects.create(folder_id=folder_id,
                                         folder_name=folder_name,
                                         folder_type=folder_type)
            i = i + 1
            print i
Ejemplo n.º 3
0
def loadTestTopics(fileName):
    with open(path + '/data/' + fileName, 'rU') as csvfile:
        topicData = csv.reader(csvfile, delimiter='\t', quotechar='|')
        for topic in topicData:
            category = cleanstring(topic[0]).lower()
            sub_category = cleanstring(topic[1]).lower()
            description = cleanstring(topic[2]).lower()
            findTopic = TestCategory.objects.filter(category=category,
                                                    sub_category=sub_category)
            if len(findTopic):
                findTopic = findTopic[0]
                findTopic.category = category
                findTopic.sub_category = sub_category
                findTopic.description = description
                findTopic.save()
            else:
                cc = TestCategory(category=category,
                                  sub_category=sub_category,
                                  description=description)
                cc.save()
Ejemplo n.º 4
0
    def update_all_equity():
        error = False
        success = False
        error_message_list = []
        output = {}
        message = "Request Recieved"
        stocks_csv_url = 'http://www1.NSEIndia.com/content/equities/EQUITY_L.csv'

        with requests.Session() as s:
            try:
                download = s.get(stocks_csv_url)
                decoded_content = download.content.decode('utf-8')
                cr = csv.reader(decoded_content.splitlines(), delimiter=',')
                my_list = list(cr)
            except:
                error_message_list.append('Download Failure CSV!')
                error = True
                message = "Error Found! Please refer list"
                success = False

            if not error:
                count = 0 
                if (my_list[0][6] == " ISIN NUMBER" and my_list[0][0] == "SYMBOL" and my_list[0][1] == "NAME OF COMPANY"):
                    for row in my_list:
                        if count > 0:
                            company = Company.objects.filter(isin_no=row[6])
                            if company.count() > 0 :
                                company = company[0]
                                company.name = row[1],
                                company.nse_ticker = row[0]
                                company.is_listed_nse = True
                            else:
                                company = Company.objects.create(
                                    name = cleanstring(row[1].lower())
                                    ,isin_no = row[6]
                                    ,nse_ticker = row[0]
                                    ,is_listed_nse=True
                                )
                        count = count + 1
                    output = Company.objects.all()
                    success = True
                    error = False
                    message = "Companies Updated"
                else:
                    success = False
                    error = True
                    message = "Error Found! Please refer list"
                    error_message_list = "check incoming data format!"

        return {'output':output,'message':message,'error':error,'error_message_list':error_message_list,'success':success}
Ejemplo n.º 5
0
def login_view_staff(request):
    obj = {}
    obj['status'] = False
    email = get_param(request, 'email', None)
    password = get_param(request, 'pass', None)
    secret_string = get_param(request, 'sec_string', None)
    auth_token = get_param(request, 'auth_token', None)
    status = False
    print auth_token
    if email:
        email = email.lower()
        email = cleanstring(email)
    obj['result'] = {}
    obj['result']['user'] = {}
    # obj['user'] = {}
    message = ""
    if auth_token:
        try:
            user = CAUsers.objects.get(auth_token=auth_token, active=True)
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            message = "User Found"
            login(request, user)
            obj['result']['user']['auth_token'] = auth_token
            obj['result']['user']['id'] = user.id
            obj['result']['user']['first_name'] = user.first_name
            obj['result']['user']['last_name'] = user.last_name
            obj['result']['user']['email'] = user.email
            obj['result']['user']['user_role'] = user.user_role
            obj['result']['user']['is_staff'] = user.is_staff
            obj['result']['auth'] = True
            message = "Login Success!"
            status = True
            print 1
        except:
            obj['result']['auth'] = False
            message = "Auth Token Expired"
            obj['result']['user'] = None
            status = False
            print 2
    else:
        try:
            user = CAUsers.objects.get(email=email, active=True)
            if user:
                print 3
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                message = "User Found"
                if user.check_password(password):
                    print 4
                    login(request, user)
                    new_string = user.id + random_str_generator()
                    user.auth_token = new_string
                    obj['result']['user']['auth_token'] = new_string
                    obj['result']['user']['id'] = user.id
                    obj['result']['user']['first_name'] = user.first_name
                    obj['result']['user']['last_name'] = user.last_name
                    obj['result']['user']['email'] = user.email
                    obj['result']['user']['user_role'] = user.user_role
                    obj['result']['user']['is_staff'] = user.is_staff
                    obj['result']['auth'] = True
                    message = "Login Success!"
                    status = True
                    user.save()
                elif user.secret_string == secret_string:
                    print 5
                    login(request, user)
                    new_string = user.id + random_str_generator()
                    user.auth_token = new_string
                    obj['result']['user']['auth_token'] = new_string
                    obj['result']['user']['id'] = user.id
                    obj['result']['user']['first_name'] = user.first_name
                    obj['result']['user']['last_name'] = user.last_name
                    obj['result']['user']['email'] = user.email
                    obj['result']['user']['user_role'] = user.user_role
                    obj['result']['user']['is_staff'] = user.is_staff
                    obj['result']['auth'] = True
                    status = True
                    message = "Login Success!"
                    user.save()
                else:
                    print 6
                    message = "Incorrect Password"
                    obj['result']['auth'] = False
                    status = False

            else:
                print 7
                message = "User Doesn't exist"
                obj['result']['auth'] = False
                obj['result']['user'] = None
                status = False
        except:
            print 8
            if email:
                print 9
                message = "User Doesn't exist"
            obj['result']['auth'] = False
            obj['result']['user'] = None
            status = False
    obj['status'] = status
    obj['message'] = message
    response = HttpResponse(json.dumps(obj), content_type='application/json')
    return response
Ejemplo n.º 6
0
def create_update_user(request):
    error = False
    success = False
    error_message_list = []
    output = CAUsers.objects.none()
    message = "Request Recieved"
    operation = get_param(request, 'operation', None)
    fname = get_param(request, 'fname', None)
    lname = get_param(request, 'lname', None)
    email = get_param(request, 'email', None)
    is_staff = get_param(request, 'is_staff', None)
    user_role = get_param(request, 'user_role', None)
    data_id = get_param(request, 'data_id', None)
    # user fields check and correction
    if fname:
        fname = cleanstring(fname.lower())
    else:
        error = True
        error_message_list.append("Missing fname")

    if lname:
        lname = cleanstring(lname.lower())
    else:
        error = True
        error_message_list.append("Missing lname")

    if operation == "create":
        if email:
            email = cleanstring(email.lower())
            if validate_email(email):
                pass
            else:
                error = True
                error_message_list.append("Invalid email")
        else:
            error = True
            error_message_list.append("Missing email")

    check_user_role = listvar_check(variable_name="user_role",
                                    value=user_role,
                                    allowedlist=allowed_roles)
    if not check_user_role['error']:
        user_role = str(user_role)
    else:
        error = True
        error_message_list.append(check_user_role['errormessage'])

    check_is_staff = booleanvar_check(variable_name="is_staff", value=is_staff)
    if not check_is_staff['error']:
        is_staff = check_is_staff['output']
        if is_staff:
            check_user_role = listvar_check(variable_name="user_role",
                                            value=user_role,
                                            allowedlist=staff_roles)
            if not check_user_role['error']:
                user_role = str(user_role)
            else:
                error = True
                error_message_list.append(check_user_role['errormessage'])
        else:
            user_role = "user"

    else:
        error = True
        error_message_list.append(check_is_staff['errormessage'])

    if operation == "update":
        if data_id:
            try:
                user = CAUsers.objects.get(id=data_id)
            except:
                error = True
                error_message_list = ['invalid data_id']
        else:
            error = True
            error_message_list = ['missing data_id']

    if not error:
        if operation == "create":
            users = CAUsers.objects.filter(email=email)
            if users.count() > 0:
                message = "User Already Exists!"
                output = users
                success = False
            else:
                user_new = CAUsers.objects.create(first_name=fname,
                                                  last_name=lname,
                                                  email=email,
                                                  is_staff=is_staff,
                                                  user_role=user_role)
                user_new.set_password(defaultpassword)
                user_new.secret_string = (user_new.id + random_str_generator())
                user_new.auth_token = (user_new.id + random_str_generator())
                user_new.save()
                output = [user_new]
                success = True
                message = "User Created!"
        else:
            user.first_name = fname
            user.last_name = lname
            user.is_staff = is_staff
            if not is_staff:
                user.user_role = "user"
            else:
                if user_role in staff_roles:
                    user.user_role = user_role
                else:
                    error = True
                    user.user_role = "staff"
            user.save()
            output = [user]
            success = True
            message = "User Updated!"
    else:
        message = "Errors | Refer Error List!"

    return {
        'output': output,
        'message': message,
        'error': error,
        'error_message_list': error_message_list,
        'success': success
    }
Ejemplo n.º 7
0
def create_update_course(request):
    error = False
    success = False
    error_message_list = []
    output = Courses.objects.none()
    message = "Request Recieved"
    operation          = get_param(request, 'operation', None)
    course_name        = get_param(request, 'course_name', None)    
    display_name       =   get_param(request, 'display_name', None)    
    data_id            = get_param(request, 'data_id', None)      
    # user fields check and correction

    if course_name:
        course_name = cleanstring(course_name)
    else:
        error = True
        error_message_list.append("Missing course_name")                               

    if display_name:
        try:
            display_name = json.loads(display_name)
            new_display_name = {}
            print display_name
            for lang in languages:
                try:
                    print display_name[lang]
                    name_clean = display_name[lang]
                except:
                    name_clean = ''
                new_display_name[lang] = name_clean
            display_name = new_display_name
        except:
            error = True
            error_message_list.append("Invalid display_name dict")                               


    if operation == "update":
        if data_id:
            try:
                course = Courses.objects.get(id=data_id)
            except:
                error = True
                error_message_list = ['invalid data_id']
        else:
            error = True
            error_message_list = ['missing data_id']
        

    if not error: 
        if operation == "create":
            course = Courses.objects.filter(course_name_english=course_name)
            if course.count() > 0 :
                message = "Course Already Exists!"        
                output = course
                success = False
            else:
                course_new = Courses.objects.create(
                    course_name_english                   = course_name                 
                    ,display_name_dictionary              = display_name                          
                )
                output = [course_new]
                success = True
                message = "Course Created!"
        else:
            if Courses.objects.filter(course_name_english = course_name).count() > 1:
                success = False
                message = "Course name already exist"
                output = []
            elif Courses.objects.filter(course_name_english = course_name).count() == 1 :
                if course.id == Courses.objects.filter(course_name_english = course_name)[0].id:
                    course.course_name_english           = course_name                 
                    course.display_name_dictionary       = display_name   
                    course.save()
                    output = [course]
                    success = True
                    message = "Course Updated!"                   
                else:  
                    success = False
                    message = "Course name already exist"
                    output = []
            else:
                course.course_name_english           = course_name                 
                course.display_name_dictionary       = display_name   
                course.save()
                output = [course]
                success = True
                message = "Course Updated!"

    else:
        message = "Errors | Refer Error List!"

    return {'output':output,'message':message,'error':error,'error_message_list':error_message_list,'success':success}