def table(request, slugs=None): show_categs = bool(int(request.GET.get('show_categs', 1))) only_common = bool(int(request.GET.get('only_common', 1))) drugs = Drug.objects if slugs: drugs = drugs.filter(slug__in=slugs) elif only_common: drugs = drugs.filter(common=True) drugs = (drugs .prefetch_related('category') .order_by(F('category__name').asc(nulls_last=True), 'name') ) interactions = Interaction.objects.between(drugs, prefetch=True) dummy_risks = Interaction.get_dummy_risks() dummy_synergies = Interaction.get_dummy_synergies() chart_data = {drug: {} for drug in drugs} for inter in interactions: chart_data[inter.from_drug][inter.to_drug] = inter chart_data[inter.to_drug][inter.from_drug] = inter return render(request, 'drugcombinator/table.html', locals())
def get_context(self, *args, **kwargs): ctx = super().get_context(*args, **kwargs) ctx.interactions = ctx.interactions.filter(is_draft=False) ctx.dummy_risks = Interaction.get_dummy_risks() ctx.dummy_synergies = Interaction.get_dummy_synergies() for inter in ctx.interactions: inter.drug = inter.other_interactant(ctx.drug) return ctx
def portal(request): portal = get_object_or_404(Portal, drug=request.drug) interactions = (portal.drug.interactions.filter( is_draft=False).prefetch_related('from_drug', 'to_drug')) for inter in interactions: inter.drug = inter.other_interactant(portal.drug) interactions = sorted(interactions, key=attrgetter('drug.name')) dummy_risks = Interaction.get_dummy_risks() return render(request, 'drugportals/portal.html', locals())
def portal(request, drug): try: portal = Portal.objects.get(drug__slug=drug) except Portal.DoesNotExist: raise Http404("Ce portail n'existe pas.") interactions = (portal.drug.interactions.filter( is_draft=False).prefetch_related('from_drug', 'to_drug').order_by_name()) for inter in interactions: inter.drug = inter.other_interactant(portal.drug) dummy_risks = Interaction.get_dummy_risks() return render(request, 'drugportals/portal.html', locals())