How to use common_code method in autotest

Best Python code snippet using autotest_python

views.py

Source:views.py Github

copy

Full Screen

...4from .models import *5from django.http import JsonResponse6import json7# Create your views here.8def common_code(request):9 if request.user.is_authenticated:10 student = request.user11 print("student",student)12 profile_imgs = Profile_pic.objects.filter(stu=student)13 if profile_imgs == {}:14 profile_imgs = ' '15 con = {16 'student': student,17 'profile_imgs': profile_imgs[0],18 }19 return con20def home_page(request):21 context1 = common_code(request)22 context = {23 'context1': context1,24 }25 return render(request, 'home.html',context)26def login_page(request):27 if request.method == 'POST':28 roll_number = request.POST.get('roll_number')29 password = request.POST.get('Password')30 print(roll_number, password)31 student = authenticate(request, roll_number=roll_number, password=password)32 print(student.is_authenticated)33 if student is not None:34 login(request, student)35 return redirect('home')36 context = {}37 return render(request, 'login_page.html',context)38def create_new_customer(request):39 form = CreateStudent()40 if request.method == 'POST':41 form = CreateStudent(request.POST)42 print(form.is_valid())43 # print(form.cleaned_data.get('email'))44 if form.is_valid():45 form.save()46 print(form.cleaned_data.get('email'))47 return redirect('login')48 context = {'form': form}49 return render(request, 'cna.html', context)50def attendance(request):51 context1 = common_code(request)52 sub = Subject.objects.all()53 print(sub)54 atten = Student_Attendance.objects.all()55 # print(atten[0].present)56 total_conducted = 057 for i in range(0,1):58 total_conducted += sub[i].conducted59 print(total_conducted)60 total_present = 061 for i in range(0,1):62 total_present += atten[i].present63 # print("total at "+ str(i) + " ", str(total_present))64 # print(total_present)65 total_absent_hours = 066 for i in range(0,1):67 total_absent_hours += atten[i].total_hours_absent68 # print(total_absent_hours)69 total_percentage = 070 for i in range(0,1):71 total_percentage += atten[i].percentage72 print(int(total_percentage/2))73 context = {74 'total_present': total_present,75 'total_conducted': total_conducted,76 'total_absent_hours': total_absent_hours,77 'total_percentage': int(total_percentage/2),78 'sub': sub,79 'atten': atten,80 'context1': context1,81 }82 return render(request, 'navigation/attendance.html', context)83def absence_details(request):84 context1 = common_code(request)85 student = request.user86 subs = Subject.objects.all()87 absen_details = Student_Absence_Details.objects.filter(stu=student)88 print(absen_details)89 n_o_p_a = Number_of_periods_absent.objects.filter(stu=student)90 print(n_o_p_a)91 total_periods = 092 for i in range(0,len(n_o_p_a)):93 total_periods += n_o_p_a[i].number_of_periods_absent94 print(int(total_periods))95 context = {96 'subs': subs,97 'absen_details': absen_details,98 'n_o_p_a': n_o_p_a,99 'total_periods': total_periods,100 'context1': context1,101 }102 return render(request, 'navigation/absence_details.html', context)103def previous_attendance(request):104 context1 = common_code(request)105 context = {106 'context1': context1,107 }108 return render(request, 'navigation/previous_attendance.html', context)109def time_table(request):110 context1 = common_code(request)111 context = {112 'context1': context1,113 }114 return render(request, 'navigation/time_table.html', context)115def navbar(request):116 context1 = common_code(request)117 # student = request.user118 # stu = Student.objects.filter(roll_number=student)119 # print('stu',stu)120 context = {121 # 'stu': stu,122 'context1': context1,123 }124 return render(request, 'navbar.html', context)125def result(request):126 context1 = common_code(request)127 context = {128 'context1': context1,129 }130 return render(request, 'navigation/result.html', context)131def previous_result(request):132 context1 = common_code(request)133 context = {134 'context1': context1,135 }136 return render(request, 'navigation/previous_result.html', context)137def view_course_plan(request):138 context1 = common_code(request)139 subs = Subject.objects.all()140 context = {141 'subs': subs,142 'context1': context1,143 }144 return render(request, 'navigation/view_course_plan.html', context)145# def download_course_plan(request, id):146# sub = Subject.objects.filter(sub_id = id)147# print(sub)148# context1 = common_code(request)149# context = {150# 'context1': context1,151# }152# return render(request, 'navigation/download_course_plan.html', context)153def fee_payment(request):154 context1 = common_code(request)155 student = request.user156 stu = Student.objects.filter(roll_number=student)157 print("stu",stu)158 fees = Fee_details.objects.filter(stu=student)159 print(fees)160 context = {161 'stu': stu,162 'fees': fees,163 'context1': context1,164 }165 return render(request, 'navigation/fee_payment.html', context)166def fee_payment_history(request):167 context1 = common_code(request)168 student = request.user169 stu = Student.objects.filter(roll_number=student)170 print("stu",stu)171 fees = Fee_Payment_History.objects.filter(stu=student)172 print(fees)173 total = 0174 for i in range(0,len(fees)):175 total += fees[i].amount176 print(int(total))177 context = {178 'stu': stu,179 'fees': fees,180 'total': total,181 'context1': context1,182 }183 return render(request, 'navigation/fee_payment_history.html', context)184def hostel_leave_entry_form(request):185 context1 = common_code(request)186 form = hostel_leave_form()187 if request.method == 'POST':188 form = hostel_leave_form(request.POST)189 print(form.is_valid())190 if form.is_valid():191 instance = form.save(commit=False)192 instance.roll_number = request.user193 # print(form.cleaned_data.get('email'))194 instance.save()195 # print(form.cleaned_data.get('email'))196 197 return redirect('hostel leave entry')198 context = {199 'form': form,200 'context1': context1,201 }202 return render(request, 'navigation/hostel_leave_entry_form.html', context)203def hostel_leave_entry(request):204 context1 = common_code(request)205 student = request.user206 form = Hostel_Leave_Entry.objects.filter(roll_number=student)207 print(form)208 context = {209 'form': form,210 'context1': context1,211 }212 return render(request, 'navigation/hostel_leave_entry.html', context)213def support(request):214 context1 = common_code(request)215 student = request.user216 print("roll_num",student)217 s_r = Support_Request_form.objects.filter(roll_number=student)218 print(s_r)219 context = {220 's_r': s_r,221 'context1': context1,222 }223 return render(request, 'navigation/support.html', context)224def support_request_form(request):225 context1 = common_code(request)226 form = request_form()227 if request.method == 'POST':228 form = request_form(request.POST)229 print(form.is_valid())230 if form.is_valid():231 instance = form.save(commit=False)232 instance.roll_number = request.user233 # print(form.cleaned_data.get('email'))234 instance.save()235 236 return redirect('support')237 context = {238 'form': form,239 'context1': context1,...

Full Screen

Full Screen

cilin_similarity.py

Source:cilin_similarity.py Github

copy

Full Screen

...95 @param code1 The code 196 @param code2 The code 297 @return The common level.98 """99 common_code = self.get_common_code(code1, code2)100 if len(common_code) == 1:101 return 2102 elif len(common_code) == 2:103 return 3104 elif len(common_code) == 4:105 return 4106 elif len(common_code) == 5:107 return 5108 else:109 return 0110 def get_n(self, code1, code2):111 """112 @brief 获取分支层的所有节点数113 @param self The object114 @param common_level The common layer115 @param n 116 @param k 117 @return {}118 """119 common_code = self.get_common_code(code1,code2)120 common_level = self.get_common_level(code1, code2)121 if len(common_code) == 0:122 return 0123 res = set()124 for key in self.code_words.keys():125 if key.startswith(common_code):126 code = self.split_code(key)127 res.add(code[common_level - 1])128 return len(res)129 def get_k(self,code1,code2):130 """131 @brief 获取分支之间的距离132 @param self The object133 @param code1 The code 1134 @param code2 The code 2135 @return The k.136 """137 code1 = self.split_code(code1)138 code2 = self.split_code(code2)139 if code1[0] != code2[0]:140 return abs(ord(code1[0]) - ord(code2[0]))141 elif code1[1] != code2[1]:142 return abs(ord(code1[1]) - ord(code2[1]))143 elif code1[2] != code2[2]:144 return abs(int(code1[2]) - int(code2[2]))145 elif code1[3] != code2[3]:146 return abs(ord(code1[3]) - ord(code2[3]))147 else:148 return abs(int(code1[4]) - int(code2[4]))149 def cal_sim(self, coeff, n, k):150 """151 @brief 计算相似度152 @param self The object153 @param common_level The common layer154 @param n 155 @param k 156 @return 相似度值157 """158 return coeff * math.cos(n * math.pi / 180) * ((n - k + 1) / n)159 def get_common_code(self, code1, code2):160 """161 @brief 获取公共子串162 @param self The object163 @param code1 The code 1164 @param code2 The code 2165 @return { description_of_the_return_value }166 """167 code1 = self.split_code(code1)168 code2 = self.split_code(code2)169 res = "" 170 for i, j in zip(code1, code2):171 if i == j:172 res += i173 else:...

Full Screen

Full Screen

test_settings.py

Source:test_settings.py Github

copy

Full Screen

1from __future__ import unicode_literals2from django.test import TestCase3from django.utils import six4from django_countries import countries, data, base5class TestSettings(TestCase):6 def setUp(self):7 del countries.countries8 def tearDown(self):9 del countries.countries10 def test_override_additional(self):11 with self.settings(COUNTRIES_OVERRIDE={"XX": "New"}):12 self.assertEqual(countries.name("XX"), "New")13 def test_override_replace(self):14 with self.settings(COUNTRIES_OVERRIDE={"NZ": "Middle Earth"}):15 self.assertEqual(countries.name("NZ"), "Middle Earth")16 def test_override_remove(self):17 with self.settings(COUNTRIES_OVERRIDE={"AU": None}):18 self.assertNotIn("AU", countries)19 self.assertEqual(countries.name("AU"), "")20 def test_override_only(self):21 with self.settings(COUNTRIES_ONLY={"AU": "Desert"}):22 self.assertTrue(len(countries.countries) == 1)23 self.assertIn("AU", countries)24 self.assertEqual(countries.name("AU"), "Desert")25 def test_common_names(self):26 common_code, common_name = list(base.CountriesBase.COMMON_NAMES.items())[0]27 common_name = six.text_type(common_name)28 name = six.text_type(countries.countries[common_code])29 self.assertEqual(name, common_name)30 del countries.countries31 official_name = six.text_type(data.COUNTRIES[common_code])32 with self.settings(COUNTRIES_COMMON_NAMES=False):33 name = six.text_type(countries.countries[common_code])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful