def save(self, *args, **kwargs): # when saving for the first time only, put this page last in order if not self.id and not self.parent: # get max value of order for current pages. try: self.order = ( DocPage.objects.aggregate(Max("order"))["order__max"] + 1 ) except (ObjectDoesNotExist, TypeError): # Use the default pass elif not self.id and self.parent: try: self.order = ( DocPage.objects.filter(slug=self.parent.slug) .get() .children.last() .order + 1 ) except AttributeError: self.order = ( DocPage.objects.filter(slug=self.parent.slug).get().order + 1 ) self.content = clean(self.content) super().save(*args, **kwargs)
def __init__(self, *args, archive=None, user=None, archive_item=None, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() if archive_item: values = archive_item.values.all() else: values = ComponentInterfaceValue.objects.none() for inp in ComponentInterface.objects.all(): initial = values.filter(interface=inp).first() if initial: initial = initial.value self.fields[inp.slug] = InterfaceFormField( kind=inp.kind, schema=inp.schema, initial=initial or inp.default_value, required=False, user=user, help_text=clean(inp.description) if inp.description else "", ).field
def detail_context(self): context = {} cleaned_html = clean(self.html) if "project_statistics" in cleaned_html: cleaned_html = self._substitute_geochart(html=cleaned_html) context["includes_geochart"] = True context["cleaned_html"] = cleaned_html return context
def __init__(self, *args, algorithm=None, user=None, **kwargs): super().__init__(*args, **kwargs) if algorithm is None: return self.helper = FormHelper() for inp in algorithm.inputs.all(): self.fields[inp.slug] = InterfaceFormField( kind=inp.kind, initial=inp.default_value, user=user, help_text=clean(inp.description) if inp.description else "", ).field
def cleaned_html(self): out = clean(self.html) if "project_statistics" in out: out = self._substitute_geochart(html=out) if "google_group" in out: s = Substitution( tag_name="google_group", replacement=render_to_string( "grandchallenge/partials/google_group.html"), use_arg=True, ) out = s.sub(out) return out
def ama_html(self): if not self.citeproc_json: return "" bibliography = CitationStylesBibliography( CitationStylesStyle( str( Path(__file__).parent / "styles" / "american-medical-association-no-url.csl")), self.bib_source, formatter.html, ) bibliography.register(Citation([CitationItem(self.doi)])) # The bibliography only contains 1 element citation = str(bibliography.bibliography()[0]) citation = re.sub(r"^1\. ", "", citation) return clean(citation)
def save(self, *args, **kwargs): # when saving for the first time only, put this page last in order if not self.id: # get max value of order for current pages. try: max_order = Page.objects.filter( challenge=self.challenge).aggregate(Max("order")) except ObjectDoesNotExist: max_order = None try: self.order = max_order["order__max"] + 1 except TypeError: self.order = 1 self.html = clean(self.html) super().save(*args, **kwargs) self.assign_permissions()
def __str__(self): return clean(f"{self.identifier} {self.citation}")