from django.contrib.flatpages.models import FlatPage from django.core.urlresolvers import reverse import dumper def flatpage_dependent_paths(self): yield reverse("exhibition-current") yield reverse("contact") FlatPage.dependent_paths = flatpage_dependent_paths dumper.register(FlatPage)
raise ValidationError("At least one of the following must be filled in: " + str(SLUG_FIELD_NAMES)) @property def slug_title(self): return "-".join(map(repr, self._slug_field_values)) @property def date_year(self): return self.date.year @property def _slug_field_values(self): values = [getattr(self, field_name) for field_name in SLUG_FIELD_NAMES] return [_f for _f in values if _f] def get_absolute_url(self): return reverse("press-detail", kwargs={"slug": self.slug}) def dependent_paths(self): yield self.get_absolute_url() if self.artist: yield self.artist.get_absolute_url() yield reverse("artist-press-list", kwargs={"slug": self.artist.slug}) if self.exhibition: yield self.exhibition.get_absolute_url() yield reverse("exhibition-press-list", kwargs={"slug": self.exhibition.slug}) url_tracker.track_url_changes_for_model(Press) dumper.register(Press)
def dependent_paths(self): yield reverse('artist-list') yield self.get_absolute_url() yield reverse('artist-resume', kwargs={'slug': self.slug}) yield reverse('artist-press-list', kwargs={'slug': self.slug}) yield reverse('artist-exhibition-list', kwargs={'slug': self.slug}) for exhibition in self.exhibitions.all(): yield exhibition.get_absolute_url() @property def link_if_visible(self): if self.visible: return format_html( '<a href="{}">{}</a>', self.get_absolute_url(), self, ) return str(self) class ArtistPhoto(ArtworkPhoto): content_object = models.ForeignKey(Artist, related_name='photos') url_tracker.track_url_changes_for_model(Artist) dumper.register(Artist) dumper.register(ArtistPhoto) simpleimages.trackers.track_model(ArtistPhoto) register(Artist, search_fields=['first_name', 'last_name'])
content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') def dependent_paths(self): yield self.content_object.get_absolute_url() class RelatedToGenericModel(models.Model): slug = models.CharField(max_length=200, default='slug') generic_related = GenericRelation(GenericRelationModel) def get_absolute_url(self): return reverse('related-to-generic-detail', kwargs={'slug': self.slug}) class GenericRelationNotRegisteredModel(models.Model): slug = models.CharField(max_length=200, default='slug') content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') def dependent_paths(self): pass dumper.register(SimpleModel) dumper.register(RelatedModel) dumper.register(GenericRelationModel)
from django.db import models import dumper from libs.ckeditor.fields import CKEditorField class CustomPage(models.Model): path = models.CharField(max_length=100, db_index=True) content = CKEditorField(blank=True) class Meta: verbose_name = 'custom page' verbose_name_plural = 'custom pages' ordering = ('path',) def __str__(self): return self.path def dependent_paths(self): yield self.path dumper.register(CustomPage)
def dependent_paths(self): yield self.get_absolute_url() yield reverse("exhibition-list") yield reverse("exhibition-current") yield reverse("exhibition-press-list", kwargs={"slug": self.slug}) for artist in self.artists.all(): yield artist.get_absolute_url() yield reverse("artist-exhibition-list", kwargs={"slug": artist.slug}) for press in self.press.all(): yield press.get_absolute_url() yield reverse("exhibition-pressrelease", kwargs={"slug": self.slug}) class ExhibitionPhoto(ArtworkPhoto): content_object = models.ForeignKey(Exhibition, related_name="photos") artist_text = models.CharField( blank=True, max_length=100, help_text="Only use if not solo artist in show", verbose_name="Artist" ) def dependent_paths(self): yield self.content_object.get_absolute_url() if self.content_object.current: yield reverse("exhibition-current") url_tracker.track_url_changes_for_model(Exhibition) dumper.register(Exhibition) dumper.register(ExhibitionPhoto) simpleimages.trackers.track_model(ExhibitionPhoto) register(Exhibition, search_fields=["name"])
upload_to=icon_image_path_function, height_field='icon_image_height', width_field='icon_image_width', max_length=1000 ) icon_image_height = models.PositiveIntegerField( null=True, blank=True, editable=False, ) icon_image_width = models.PositiveIntegerField( null=True, blank=True, editable=False, ) transformed_fields = copy.deepcopy(BasePhoto.transformed_fields) transformed_fields['image']['icon_image'] = simpleimages.transforms.Scale( width=150, height=200, ) @property def safe_icon_image(self): return self._get_safe_image('icon_image', 'image') dumper.register(Book) dumper.register(BookPhoto) simpleimages.trackers.track_model(BookPhoto)
from libs.ckeditor.fields import CKEditorField class Update(url_tracker.URLTrackingMixin, models.Model): description = CKEditorField(blank=True) post_date = models.DateField(verbose_name='Date') class Meta: ordering = ["-post_date"] def clean(self): self.description = self.description.strip() def __str__(self): return str(self.post_date.isoformat()) def get_absolute_url(self): return reverse('update-detail', kwargs={'pk': self.pk}) def dependent_paths(self): yield reverse('update-list') class UpdatePhoto(BasePhoto): content_object = models.ForeignKey(Update, related_name='photos') url_tracker.track_url_changes_for_model(Update) dumper.register(Update) dumper.register(UpdatePhoto) simpleimages.trackers.track_model(UpdatePhoto)