def list_studygroups(parser, token): """ Example: {% list_studygroups as studygroups_list [user=user limit=3 tags=bloop bleep q=searchterm] %} {% for studygroup in studygroups %} {{ studygroup.something }} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires more than 2" % bits[0] raise TemplateSyntaxError(message) if bits[1] != "as": message = "'%s' second argument must be 'as'" % bits[0] raise TemplateSyntaxError(message) kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = '-create_dt' return ListStudyGroupsNode(context_var, *args, **kwargs)
def list_events(parser, token): """ Used to pull a list of :model:`events.Event` items. Usage:: {% list_events as [varname] [options] %} Be sure the [varname] has a specific name like ``events_sidebar`` or ``events_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. Custom options include ``next_upcoming`` for the events starting after now, and ``current_and_upcoming`` for events going on as well as upcoming. **Default: Next Upcoming by date** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``type`` The type of the event. ``tags`` The tags required on items to be included. ``group`` The group id associated with items to be included. ``random`` Use this with a value of true to randomize the items included. ``start_dt`` Specify the date that events should start after to be shown. MUST be in the format 1/20/2013-06:45 Example:: {% list_events as events_list limit=5 tags="cool" %} {% for event in events_list %} {{ event.title }} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires more than 3" % bits[0] raise TemplateSyntaxError(message) if bits[1] != "as": message = "'%s' second argument must be 'as" % bits[0] raise TemplateSyntaxError(message) kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = 'next_upcoming' return ListEventsNode(context_var, *args, **kwargs)
def list_events(parser, token): """ Used to pull a list of :model:`events.Event` items. Usage:: {% list_events as [varname] [options] %} Be sure the [varname] has a specific name like ``events_sidebar`` or ``events_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. Custom options include ``next_upcoming`` for the events starting after now, and ``current_and_upcoming`` for events going on as well as upcoming. **Default: Next Upcoming by date** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``type`` The type of the event. ``tags`` The tags required on items to be included. ``group`` The group id associated with items to be included. ``random`` Use this with a value of true to randomize the items included. ``start_dt`` Specify the date that events should start after to be shown. MUST be in the format 1/20/2013-06:45 Example:: {% list_events as events_list limit=5 tags="cool" %} {% for event in events_list %} {{ event.title }} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires more than 3" % bits[0] raise TemplateSyntaxError(_(message)) if bits[1] != "as": message = "'%s' second argument must be 'as" % bits[0] raise TemplateSyntaxError(_(message)) kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = 'next_upcoming' return ListEventsNode(context_var, *args, **kwargs)
def list_files(parser, token): """ Used to pull a list of :model:`files.File` items. Usage:: {% list_files as [varname] [options] %} Be sure the [varname] has a specific name like ``files_sidebar`` or ``files_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. **Default: Newest Added** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``query`` The text to search for items. Will not affect order. ``tags`` The tags required on items to be included. ``group`` The group id associated with items to be included. ``random`` Use this with a value of true to randomize the items included. Example:: {% list_files as files_list limit=5 tags="cool" %} {% for file in files_list %} {{ file.name }} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires more than 3" % bits[0] raise TemplateSyntaxError(message) if bits[1] != "as": message = "'%s' second argument must be 'as" % bits[0] raise TemplateSyntaxError(message) kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = '-create_dt' return ListFilesNode(context_var, *args, **kwargs)
def list_boxes(parser, token): """ Used to pull a list of :model:`boxes.Box` items. Usage:: {% list_boxes as [varname] [options] %} Be sure the [varname] has a specific name like ``boxes_sidebar`` or ``boxes_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. **Default: Newest First** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``query`` The text to search for items. Will not affect order. ``tags`` The tags required on items to be included. ``random`` Use this with a value of true to randomize the items included. Example:: {% list_boxes as boxes_list limit=5 tags="cool" %} {% for box in boxes_list %} <div class="boxes">{{ box.safe_content }} {% include 'boxes/edit-link.html' %}</div> {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() if len(bits) < 3: message = "'%s' tag requires more than 2" % bits[0] raise TemplateSyntaxError(message) if bits[1] != "as": message = "'%s' second argument must be 'as'" % bits[0] raise TemplateSyntaxError(message) context_var = bits[2] kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = '-create_dt' return ListBoxesNode(context_var, *args, **kwargs)
def list_photos(parser, token): """ Used to pull a list of :model:`photos.Image` items. Usage:: {% list_photos as [varname] [options] %} Be sure the [varname] has a specific name like ``photos_sidebar`` or ``photos_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. **Default: Newest Added** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``query`` The text to search for items. Will not affect order. ``tags`` The tags required on items to be included. ``group`` The group id associated with items to be included. ``random`` Use this with a value of true to randomize the items included. Example:: {% list_photos as photos_list limit=5 tags="cool" %} {% for photo in photos_list %} {{ photo.title }} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires more than 3" % bits[0] raise TemplateSyntaxError(message) if bits[1] != "as": message = "'%s' second argument must be 'as" % bits[0] raise TemplateSyntaxError(message) kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = '-create_dt' return ListPhotosNode(context_var, *args, **kwargs)
def list_boxes(parser, token): """ Used to pull a list of :model:`boxes.Box` items. Usage:: {% list_boxes as [varname] [options] %} Be sure the [varname] has a specific name like ``boxes_sidebar`` or ``boxes_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. **Default: Newest First** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``query`` The text to search for items. Will not affect order. ``tags`` The tags required on items to be included. ``random`` Use this with a value of true to randomize the items included. Example:: {% list_boxes as boxes_list limit=5 tags="cool" %} {% for box in boxes_list %} <div class="boxes">{{ box.safe_content }} {% include 'boxes/edit-link.html' %}</div> {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() if len(bits) < 3: message = "'%s' tag requires more than 2" % bits[0] raise TemplateSyntaxError(_(message)) if bits[1] != "as": message = "'%s' second argument must be 'as'" % bits[0] raise TemplateSyntaxError(_(message)) context_var = bits[2] kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = '-create_dt' return ListBoxesNode(context_var, *args, **kwargs)
def list_navs(parser, token): """ Used to pull a list of :model:`navs.Nav` items. Usage:: {% list_case_studies as [varname] [options] %} Be sure the [varname] has a specific name like ``case_studies_sidebar`` or ``case_studies_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. **Default: ID** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``query`` The text to search for items. Will not affect order. ``tags`` The tags required on items to be included. ``random`` Use this with a value of true to randomize the items included. Example:: {% list_navs as nav_list limit=5 tags="cool" %} {% for nav in nav_list %} {% nav nav %} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires at least 2 parameters" % bits[0] raise TemplateSyntaxError(message) if bits[1] != "as": message = "'%s' second argument must be 'as'" % bits[0] raise TemplateSyntaxError(message) kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = 'pk' return ListNavNode(context_var, *args, **kwargs)
def list_navs(parser, token): """ Used to pull a list of :model:`navs.Nav` items. Usage:: {% list_case_studies as [varname] [options] %} Be sure the [varname] has a specific name like ``case_studies_sidebar`` or ``case_studies_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. **Default: ID** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``query`` The text to search for items. Will not affect order. ``tags`` The tags required on items to be included. ``random`` Use this with a value of true to randomize the items included. Example:: {% list_navs as nav_list limit=5 tags="cool" %} {% for nav in nav_list %} {% nav nav %} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires at least 2 parameters" % bits[0] raise TemplateSyntaxError(message) if bits[1] != "as": message = "'%s' second argument must be 'as'" % bits[0] raise TemplateSyntaxError(message) kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = 'pk' return ListNavNode(context_var, *args, **kwargs)
def list_stories(parser, token): """ Used to pull a list of :model:`stories.Story` items. Usage:: {% list_stories as [varname] [options] %} Be sure the [varname] has a specific name like ``stories_sidebar`` or ``stories_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``tags="cool"``. Options include: ``limit`` The number of stories that are shown. **Default: 3** ``order`` The order of the stories. **Default: Order in Admin** ``user`` Specify a user to only show public stories to all. **Default: Viewing user** ``query`` The text to search for stories. Will not affect order. ``tags`` The tags required on stories to be included. ``group`` The group id of stories to be included. ``random`` Use this with a value of true to randomize the stories included. Example:: {% list_stories as stories_list limit=5 tags="cool" %} {% for story in stories_list %} {{ story.title }} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires more than 3" % bits[0] raise TemplateSyntaxError(_(message)) if bits[1] != "as": message = "'%s' second argument must be 'as" % bits[0] raise TemplateSyntaxError(_(message)) kwargs = parse_tag_kwargs(bits) return ListStoriesNode(context_var, *args, **kwargs)
def list_corporate_memberships(parser, token): """ Used to pull a list of :model:`corporate_memberships.CorpMembership` items. Usage:: {% list_corporate_memberships as [varname] [options] %} Be sure the [varname] has a specific name like ``corpmembership_sidebar`` or ``corpmembership_list``. Options can be used as [option]=[value]. Wrap text values in quotes like ``query="cool"``. Options include: ``limit`` The number of items that are shown. **Default: 3** ``order`` The order of the items. **Default: Newest Approved** ``user`` Specify a user to only show public items to all. **Default: Viewing user** ``query`` The text to search for items. Will not affect order. ``random`` Use this with a value of true to randomize the items included. Example:: {% list_corporate_memberships as corpmembership_list limit=5 %} {% for corpmembership in corpmembership_list %} {{ corpmembership.corp_profile.name }} {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() context_var = bits[2] if len(bits) < 3: message = "'%s' tag requires at least 2 parameters" % bits[0] raise TemplateSyntaxError(_(message)) if bits[1] != "as": message = "'%s' second argument must be 'as'" % bits[0] raise TemplateSyntaxError(_(message)) kwargs = parse_tag_kwargs(bits) if 'order' not in kwargs: kwargs['order'] = '-join_dt' return ListCorpMembershipNode(context_var, *args, **kwargs)
def get_rss(parser, token): """ Take an RSS feed so you can iterate through the entries. Usage:: {% get_rss [rss_feed_url] as [variable] cache=600 %} Options include: ``cache`` The length of time to cache the feed in seconds. **Default: 300** Example:: {% get_rss "http://www.freesound.org/blog/?feed=rss2" as rss %} {% for entry in rss.entries %} <h1>{{entry.title}}</h1> <p> {{entry.summary|safe}} </p> <p> <a href="{{entry.link}}">read more...</a> </p> {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() url_string = bits[1] context_var = bits[3] if len(bits) < 4: message = "'%s' tag requires more than 3" % bits[0] raise TemplateSyntaxError(message) if bits[2] != "as": message = "'%s' third argument must be 'as" % bits[0] raise TemplateSyntaxError(message) kwargs = parse_tag_kwargs(bits) if url_string[0] == url_string[-1] and url_string[0] in ('"', "'"): url = url_string[1:-1] else: url = url_string return RssParserNode(context_var, url, *args, **kwargs)
def get_rss(parser, token): """ Take an RSS feed so you can iterate through the entries. Usage:: {% get_rss [rss_feed_url] as [variable] cache=600 %} Options include: ``cache`` The length of time to cache the feed in seconds. **Default: 300** Example:: {% get_rss "http://www.freesound.org/blog/?feed=rss2" as rss %} {% for entry in rss.entries %} <h1>{{entry.title}}</h1> <p> {{entry.summary|safe}} </p> <p> <a href="{{entry.link}}">read more...</a> </p> {% endfor %} """ args, kwargs = [], {} bits = token.split_contents() url_string = bits[1] context_var = bits[3] if len(bits) < 4: message = "'%s' tag requires more than 3" % bits[0] raise TemplateSyntaxError(message) if bits[2] != "as": message = "'%s' third argument must be 'as" % bits[0] raise TemplateSyntaxError(message) kwargs = parse_tag_kwargs(bits) if url_string[0] == url_string[-1] and url_string[0] in ('"', "'"): url = url_string[1:-1] else: url = url_string return RssParserNode(context_var, url, *args, **kwargs)