class Journal(index.Indexed, ClusterableModel): name = models.CharField(max_length=255) url = models.URLField() issn = models.CharField(max_length=16, blank=True, help_text=_("Linking ISSN-L for this Journal")) description = MarkdownField() tags = TaggableManager(through=JournalTag, blank=True) panels = [ FieldPanel('name'), FieldPanel('url'), FieldPanel('issn'), FieldPanel('description', widget=forms.Textarea), FieldPanel('tags'), ] search_fields = [ index.SearchField('name', partial_match=True), index.SearchField('description', partial_match=True), index.SearchField('issn'), index.RelatedFields('tags', [ index.SearchField('name', partial_match=True), ]), ] def __lt__(self, other): if isinstance(other, Journal): return self.name < other.name raise TypeError("Unorderable types: {0} < {1}".format( Journal, type(other))) def __str__(self): return "{0} {1} {2}".format(self.name, self.url, self.issn)
class PeoplePage(Page, NavigationMixin): template = 'home/about/people.jinja' heading = models.CharField(max_length=64) description = MarkdownField( help_text=_("Text blurb on the people leading comses.net")) def sort_board(self): PeopleEntryPlacement.objects.board().update_sort_order_alpha() def add_users(self, category, usernames, offset): for idx, username in enumerate(usernames): # manually iterate and get MemberProfile to enforce original ordering profile = MemberProfile.objects.get(user__username=username) self.people_entry_placements.add( PeopleEntryPlacement(sort_order=offset + idx, member_profile=profile, category=category)) def get_context(self, request, *args, **kwargs): context = super().get_context(request, *args, **kwargs) context['people_categories'] = PeopleEntryPlacement.CATEGORIES return context content_panels = Page.content_panels + [ FieldPanel('heading'), FieldPanel('description'), InlinePanel('people_entry_placements', label='People Entries') ]
class MarkdownPage(NavigationMixin, Page): heading = models.CharField( max_length=128, blank=True, help_text= _('Large heading text placed on the blue background introduction header' )) template = models.CharField( max_length=128, help_text= _('Relative filesystem path to the template file to be used for this page ' '(advanced usage only - the template must exist on the filesystem). If you change ' 'this, help text suggestions on placement of elements may no longer apply.' ), default='home/markdown_page.jinja') post_date = models.DateField("Post date", default=timezone.now) description = MarkdownField( max_length=1024, blank=True, help_text=_( 'Markdown-enabled summary text placed below the heading and title.' )) body = MarkdownField( blank=True, help_text=_('Markdown-enabled main content pane for this page.')) jumbotron = models.BooleanField( default=True, help_text= _("Mark as true if this page should display its title and description in a jumbotron" )) content_panels = Page.content_panels + [ FieldPanel('post_date'), FieldPanel('jumbotron'), FieldPanel('heading'), FieldPanel('description'), FieldPanel('body'), FieldPanel('template'), InlinePanel('navigation_links', label=_('Subnavigation Links')), ] search_fields = Page.search_fields + [ index.FilterField('post_date'), index.SearchField('description', partial_match=True), index.SearchField('body', partial_match=True), index.SearchField('heading', partial_match=True), ]
class PlaceSerializer(serializers.ModelSerializer): """Serializer for Place.""" description = MarkdownField() address = AddressSerializer() class Meta: # noqa model = Place fields = ('id', 'name', 'address', 'description')
class ConferencePage(Page): template = 'home/conference/index.jinja' introduction = MarkdownField( help_text=_("Lead introduction to the conference")) content = MarkdownField( help_text=_("Conference main body content markdown text")) start_date = models.DateField() end_date = models.DateField() external_url = models.URLField(help_text=_( "URL to the top-level Discourse category topic for this conference.")) submission_deadline = models.DateField(null=True, blank=True) submission_information = MarkdownField(help_text=_( "Markdown formatted info on how to submit a presentation to the conference" )) @property def is_accepting_submissions(self): if self.submission_deadline: return date.today() < self.submission_deadline return False @property def is_open(self): return self.start_date <= date.today() @property def is_archived(self): return date.today() > self.end_date content_panels = Page.content_panels + [ FieldPanel('start_date'), FieldPanel('end_date'), FieldPanel('introduction'), FieldPanel('content'), FieldPanel('external_url'), FieldPanel('submission_deadline'), FieldPanel('submission_information'), InlinePanel('themes', label='Themes'), ]
class ProjectSerializer(serializers.HyperlinkedModelSerializer): """Serializer for Project objects.""" description = MarkdownField() class Meta: # noqa model = Project fields = ('id', 'url', 'name', 'description', 'logo') extra_kwargs = { 'url': { 'view_name': 'api:project-detail' }, }
class ConferenceTheme(models.Model): CATEGORIES = Choices('Panel', 'Session') title = models.CharField(max_length=512) category = models.CharField(choices=CATEGORIES, default=CATEGORIES.Panel, max_length=16) description = MarkdownField() external_url = models.URLField(help_text=_( "URL to this conference theme's (panel / session) Discourse topic")) page = ParentalKey('home.ConferencePage', related_name='themes') def add_presentations(self, presentations): """ presentations must be a collection of dicts with the following keys: title, url, user_pk, contributors (optional) """ for presentation in presentations: user_id = presentation['user_pk'] submitter = MemberProfile.objects.get(user__pk=user_id) conference_presentation, created = self.presentations.get_or_create( title=presentation['title'], external_url=presentation['url'], submitter=submitter, ) contributors = presentation.get('contributors') if contributors: conference_presentation.contributors.set( Contributor.objects.filter(user__pk__in=contributors)) else: conference_presentation.contributors.add( Contributor.objects.get(user__pk=user_id)) conference_presentation.save() def __str__(self): return "{0} {1}".format(self.category, self.title) panels = [ FieldPanel('title'), FieldPanel('category'), FieldPanel('description'), FieldPanel('external_url'), # InlinePanel('presentations') ]
class EditionListSerializer(serializers.HyperlinkedModelSerializer): """List serializer for Edition objects.""" description = MarkdownField() project = serializers.StringRelatedField(read_only=True) organizers = serializers.SerializerMethodField() participations = serializers.SerializerMethodField() edition_form = EditionFormSerializer() participates = serializers.SerializerMethodField() def get_organizers(self, obj: Edition) -> int: """Return the number of organizers.""" return obj.organizers.count() def get_participations(self, obj: Edition) -> int: """Return the number of participations.""" return obj.participations.count() def get_participates(self, obj: Edition) -> bool: """Return whether the current user participates in the edition.""" request = self.context['request'] if not request.user: return False return request.user.pk in obj.participations.values_list('user__pk') class Meta: # noqa model = Edition fields = ( 'id', 'url', 'name', 'year', 'project', 'description', 'organizers', 'participations', 'edition_form', 'participates', ) extra_kwargs = { 'url': { 'view_name': 'api:edition-detail' }, }
class ConferenceSubmission(models.Model): submitter = models.ForeignKey(MemberProfile, on_delete=models.DO_NOTHING) presenters = models.ManyToManyField(Contributor) conference = models.ForeignKey(ConferencePage, related_name='submissions', on_delete=models.PROTECT) date_created = models.DateTimeField(default=timezone.now) last_modified = models.DateTimeField(auto_now=True) title = models.CharField(max_length=150, help_text=_('Presentation title')) abstract = MarkdownField(max_length=3000, help_text=_('Presentation abstract'), blank=False) video_url = models.URLField(help_text=_('URL to your video presentation')) model_url = models.URLField(help_text=_( 'Persistent URL to a model associated with your presentation (if applicable)' ), blank=True) def __str__(self): return "submission {} by {}".format(self.title, self.submitter)