Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from django.contrib.sites.models import Site
  2. from django.db import models
  3. from django.urls import NoReverseMatch, get_script_prefix, reverse
  4. from django.utils.encoding import iri_to_uri
  5. from django.utils.translation import gettext_lazy as _
  6. class FlatPage(models.Model):
  7. url = models.CharField(_("URL"), max_length=100, db_index=True)
  8. title = models.CharField(_("title"), max_length=200)
  9. content = models.TextField(_("content"), blank=True)
  10. enable_comments = models.BooleanField(_("enable comments"), default=False)
  11. template_name = models.CharField(
  12. _("template name"),
  13. max_length=70,
  14. blank=True,
  15. help_text=_(
  16. "Example: “flatpages/contact_page.html”. If this isn’t provided, "
  17. "the system will use “flatpages/default.html”."
  18. ),
  19. )
  20. registration_required = models.BooleanField(
  21. _("registration required"),
  22. help_text=_(
  23. "If this is checked, only logged-in users will be able to view the page."
  24. ),
  25. default=False,
  26. )
  27. sites = models.ManyToManyField(Site, verbose_name=_("sites"))
  28. class Meta:
  29. db_table = "django_flatpage"
  30. verbose_name = _("flat page")
  31. verbose_name_plural = _("flat pages")
  32. ordering = ["url"]
  33. def __str__(self):
  34. return "%s -- %s" % (self.url, self.title)
  35. def get_absolute_url(self):
  36. from .views import flatpage
  37. for url in (self.url.lstrip("/"), self.url):
  38. try:
  39. return reverse(flatpage, kwargs={"url": url})
  40. except NoReverseMatch:
  41. pass
  42. # Handle script prefix manually because we bypass reverse()
  43. return iri_to_uri(get_script_prefix().rstrip("/") + self.url)