class LevenshteinView(TemplateView): template_name = 'levenshtein/index.html' def dispatch(self, request, *args, **kwargs): self.levenshtein = Levenshtein.objects.all() self.form = LevenshteinForm() return super(LevenshteinView, self).dispatch( request, *args, **kwargs) def post(self, request, *args, **kwargs): self.form = LevenshteinForm(request.POST) if self.form.is_valid(): levenshtein = self.form.save() levenshtein.distance = levenshte_in_distance( levenshtein.text_1, levenshtein.text_2) levenshtein.ratio = levenshte_ratio( levenshtein.text_1, levenshtein.text_2) levenshtein.save() return super(LevenshteinView, self).get( request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(LevenshteinView, self).get_context_data(**kwargs) context['form'] = self.form context['levenshtein_objects'] = self.levenshtein return context
class LevenshteinView(TemplateView): template_name = 'levenshtein/index.html' def dispatch(self, request, *args, **kwargs): self.levenshtein = Levenshtein.objects.all() self.form = LevenshteinForm() return super(LevenshteinView, self).dispatch(request, *args, **kwargs) def post(self, request, *args, **kwargs): self.form = LevenshteinForm(request.POST) if self.form.is_valid(): levenshtein = self.form.save() levenshtein.distance = levenshte_in_distance( levenshtein.text_1, levenshtein.text_2) levenshtein.ratio = levenshte_ratio(levenshtein.text_1, levenshtein.text_2) levenshtein.save() return super(LevenshteinView, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(LevenshteinView, self).get_context_data(**kwargs) context['form'] = self.form context['levenshtein_objects'] = self.levenshtein return context
def post(self, request, *args, **kwargs): self.form = LevenshteinForm(request.POST) if self.form.is_valid(): levenshtein = self.form.save() levenshtein.distance = levenshte_in_distance( levenshtein.text_1, levenshtein.text_2) levenshtein.ratio = levenshte_ratio(levenshtein.text_1, levenshtein.text_2) levenshtein.save() return super(LevenshteinView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): self.form = LevenshteinForm(request.POST) if self.form.is_valid(): levenshtein = self.form.save() levenshtein.distance = levenshte_in_distance( levenshtein.text_1, levenshtein.text_2) levenshtein.ratio = levenshte_ratio( levenshtein.text_1, levenshtein.text_2) levenshtein.save() return super(LevenshteinView, self).get( request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): self.levenshtein = Levenshtein.objects.all() self.form = LevenshteinForm() return super(LevenshteinView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): self.levenshtein = Levenshtein.objects.all() self.form = LevenshteinForm() return super(LevenshteinView, self).dispatch( request, *args, **kwargs)
def test_forms(self): """Test the form to get text_1 and text_2""" form_data = {'text_1': 'something', 'text_2': 'what thing'} form = LevenshteinForm(data=form_data) self.assertTrue(form.is_valid())