10 17 19 24 31 32 35 36 44 48 49 51 52 53 54 55 56 57 58 59 60 61 62 63 64 66 74 76 77 82 89 91 94 98 99 101 102 104 106 108 109 110 111 112 113 114 115 116 117 118 119 120 121 123 124 125 126 127 128 132 135 138 140 142 150 151 152 153 154 155 156 157 158 159 160 161 164 165 166 169 170 172 174 179 180 181 182 183 184 188 189 190 191 192 193 194 195 196 197 198 200 202 203 204 205 206 207 208 209 210 211 212 213 |
"""Parser that understand all the placeholder's parameters.""" raise template.TemplateSyntaxError(error_string) raise template.TemplateSyntaxError( "%r is not an correct option for a placeholder" % bit) raise template.TemplateSyntaxError( "Placeholder option '%s' need a parameter" % bit) else:
"""This template node is used to output page content and dynamically generate input fields in the admin.
:param name: the name of the placeholder you want to show/create :param page: the optional page object :param widget: the widget you want to use in the admin interface. Take a look into :mod:`pages.widgets` to see which widgets are available. :param parsed: if the ``parsed`` word is given, the content of the placeholder is evaluated as template code, within the current context. :param as_varname: if ``as_varname`` is defined, no value will be returned. A variable will be created in the context with the defined name. """
"""Given the name of a placeholder return a ``Widget`` subclass like Textarea or TextInput.""" else:
"""The field that will be shown within the admin.""" else: help_text=help_text, required=False)
"""Actually save the placeholder data into the Content object.""" # the page is being changed # we need create a new content if revision is enabled not in settings.PAGE_CONTENT_REVISION_EXCLUDE_LIST): page, language, self.name, data ) else: Content.objects.set_or_create_content( page, language, self.name, data ) # the page is being added else: page, language, self.name, data )
# current_page can be set to None
self.name, True)
"""Output the content of the node in the template.""" except template.TemplateSyntaxError, error: if global_settings.DEBUG: error = PLACEHOLDER_ERROR % { 'name': self.name, 'error': error, } if self.as_varname is None: return error context[self.as_varname] = error return '' else: return '' context[self.as_varname] = content return ''
widget=widget, initial=initial, help_text=help_text, required=False )
storage = FileSystemStorage() filename = os.path.join('upload', 'page_'+str(page.id), self.name + '-' + str(time.time())) filename = storage.save(filename, data) super(ImagePlaceholderNode, self).save( page, language, filename, change )
content = self.get_content(context) if not content: return '' if content: video_url = content m = re.search('youtube\.com\/watch\?v=([^&]+)', content) if m: video_url = 'http://www.youtube.com/v/'+m.group(1) context = {'video_url': video_url} renderer = render_to_string('pages/embed.html', context) return mark_safe(renderer) return '' |