I am currently working on my first website, which is a dna to protein translator. What it does is you input a number of letters divisible by three and it gets translated into a protein if the chain exists.
Anyways, this part of the code is working perfectly and I'd even say it looks super pythonic. Right now, I am now working on raising some error messages with the django messages. Here's the link to the document: https://docs.djangoproject.com/en/3.1/ref/contrib/messages/
What I want to do is, when you input a number of letters which isn't divisible by three, i call the message.error to tell that the chain isn't valid.
Here's the code and the method call in case you need it:
class TranslatorView(View):
def build_protein(self, request, phrase):
protein = []
i = 0
while i < len(phrase):
codon = phrase[i: i + 3]
amino = self.translate_amino(codon)
if amino:
protein.append(amino)
else:
print(f"The codon {codon} is not in self.mapper_1")
i += 3
if len(phrase) % 3:
messages.error(request, "INVALID DNA CHAIN")
return protein
def get(self, request, *args, **kwargs):
return render(request, 'main/translator.html')
def post(self, request, *args, **kwargs):
phrase = request.POST.get('text', 'translation')
protein = request.POST.get('text','protein')
return render(request, self.template_name, {'translation': self.translate(phrase), 'protein': ", ".join(self.build_protein(protein))})
However, this pylint error appears:
No value for argument 'phrase' in method call (pylint-no-value-for-parameter).
I've been reading about it, and they say you can solve it by disabling the pylint. However, I was hoping for another solution which didn't have to mean disabling pylint.
Perhaps changing something about the method call, I really don't know.
The error is due to this expression in the last line of your code:
self.build_protein(protein)
It is, indeed, missing a value for the "phrase" argument. You probably want this to be:
self.build_protein(protein, phrase)