def database(request): """ The idea here is to list the categories along with the checkboxes. The user can select the desired category and click the download button. Returns: First three letter of the structural class Descriptions of the three letter structural class Three download forms See more details from the database.forms.py """ categories = PesticidalProteinDatabase.objects.order_by( "name").values_list("name").distinct() category_prefixes = [] for category in categories: prefix = category[0][:3] if prefix not in category_prefixes: category_prefixes.append(prefix) form1 = DownloadForm() form2 = ThreedomainDownloadForm() form3 = HolotypeForm() context = { "category_prefixes": category_prefixes, "descriptions": Description.objects.all(), "form1": form1, "form2": form2, "form3": form3, } return render(request, "newwebpage/database.html", context)
def category_form(request): form = DownloadForm() context = { 'form': form } return render(request, 'database/download_form.html', context)
def category_form(request): form1 = DownloadForm() form2 = ThreedomainDownloadForm() form3 = HolotypeForm() context = { "form1": form1, "form2": form2, "form3": form3, } return render(request, "newwebpage/download_form.html", context)
def download_category(request, category=None): """Download the fasta sequences for the category.""" if request.method == 'POST': form = DownloadForm(request.POST) if form.is_valid(): category = category.title() context = { 'proteins': PesticidalProteinDatabase.objects.all(), 'descriptions': Description.objects.order_by('name') } file = StringIO() data = list(context.get('proteins')) for item in data: if category in item.name: fasta = textwrap.fill(item.sequence, 80) str_to_write = f">{item.name}\n{fasta}\n" file.write(str_to_write) else: pass if 'All' in category: for item in data: fasta = textwrap.fill(item.sequence, 80) str_to_write = f">{item.name}\n{fasta}\n" file.write(str_to_write) response = HttpResponse(file.getvalue(), content_type="text/plain") download_file = f"{category}_fasta_sequences.txt" response['Content-Disposition'] = 'attachment;filename=' + \ download_file response['Content-Length'] = file.tell() return response form = DownloadForm() return render(request, 'database/download_form.html', form)
def download_category(request, category=None): """Download the fasta sequences for the category.""" if request.method == "POST": form = DownloadForm(request.POST) if form.is_valid(): category = category.title() context = { "proteins": PesticidalProteinDatabase.objects.all(), "descriptions": Description.objects.order_by("name"), } file = StringIO() data = list(context.get("proteins")) for item in data: if category in item.name: fasta = textwrap.fill(item.sequence, 80) str_to_write = f">{item.name}\n{fasta}\n" file.write(str_to_write) else: pass if "All" in category: for item in data: fasta = textwrap.fill(item.sequence, 80) str_to_write = f">{item.name}\n{fasta}\n" file.write(str_to_write) response = HttpResponse(file.getvalue(), content_type="text/plain") download_file = f"{category}_fasta_sequences.txt" response["Content-Disposition"] = "attachment;filename=" + \ download_file response["Content-Length"] = file.tell() return response form = DownloadForm() return render(request, "newwebpage/download_form.html", form)
def download_category_form(request): form = DownloadForm() return render(request, 'database/download_form.html', form)
def download_category_form(request): form = DownloadForm() return render(request, "newwebpage/download_form.html", form)