class views.Feed
This example illustrates all possible attributes and methods for a Feed
class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | from django.contrib.syndication.views import Feed from django.utils import feedgenerator class ExampleFeed(Feed): # FEED TYPE -- Optional. This should be a class that subclasses # django.utils.feedgenerator.SyndicationFeed. This designates # which type of feed this should be: RSS 2.0, Atom 1.0, etc. If # you don't specify feed_type, your feed will be RSS 2.0. This # should be a class, not an instance of the class. feed_type = feedgenerator.Rss201rev2Feed # TEMPLATE NAMES -- Optional. These should be strings # representing names of Django templates that the system should # use in rendering the title and description of your feed items. # Both are optional. If a template is not specified, the # item_title() or item_description() methods are used instead. title_template = None description_template = None # TITLE -- One of the following three is required. The framework # looks for them in this order. def title( self , obj): """ Takes the object returned by get_object() and returns the feed's title as a normal Python string. """ def title( self ): """ Returns the feed's title as a normal Python string. """ title = 'foo' # Hard-coded title. # LINK -- One of the following three is required. The framework # looks for them in this order. def link( self , obj): """ # Takes the object returned by get_object() and returns the URL # of the HTML version of the feed as a normal Python string. """ def link( self ): """ Returns the URL of the HTML version of the feed as a normal Python string. """ link = '/blog/' # Hard-coded URL. # FEED_URL -- One of the following three is optional. The framework # looks for them in this order. def feed_url( self , obj): """ # Takes the object returned by get_object() and returns the feed's # own URL as a normal Python string. """ def feed_url( self ): """ Returns the feed's own URL as a normal Python string. """ feed_url = '/blog/rss/' # Hard-coded URL. # GUID -- One of the following three is optional. The framework looks # for them in this order. This property is only used for Atom feeds # (where it is the feed-level ID element). If not provided, the feed # link is used as the ID. def feed_guid( self , obj): """ Takes the object returned by get_object() and returns the globally unique ID for the feed as a normal Python string. """ def feed_guid( self ): """ Returns the feed's globally unique ID as a normal Python string. """ feed_guid = '/foo/bar/1234' # Hard-coded guid. # DESCRIPTION -- One of the following three is required. The framework # looks for them in this order. def description( self , obj): """ Takes the object returned by get_object() and returns the feed's description as a normal Python string. """ def description( self ): """ Returns the feed's description as a normal Python string. """ description = 'Foo bar baz.' # Hard-coded description. # AUTHOR NAME --One of the following three is optional. The framework # looks for them in this order. def author_name( self , obj): """ Takes the object returned by get_object() and returns the feed's author's name as a normal Python string. """ def author_name( self ): """ Returns the feed's author's name as a normal Python string. """ author_name = 'Sally Smith' # Hard-coded author name. # AUTHOR EMAIL --One of the following three is optional. The framework # looks for them in this order. def author_email( self , obj): """ Takes the object returned by get_object() and returns the feed's author's email as a normal Python string. """ def author_email( self ): """ Returns the feed's author's email as a normal Python string. """ author_email = 'test@example.com' # Hard-coded author email. # AUTHOR LINK --One of the following three is optional. The framework # looks for them in this order. In each case, the URL should include # the "http://" and domain name. def author_link( self , obj): """ Takes the object returned by get_object() and returns the feed's author's URL as a normal Python string. """ def author_link( self ): """ Returns the feed's author's URL as a normal Python string. """ # CATEGORIES -- One of the following three is optional. The framework # looks for them in this order. In each case, the method/attribute # should return an iterable object that returns strings. def categories( self , obj): """ Takes the object returned by get_object() and returns the feed's categories as iterable over strings. """ def categories( self ): """ Returns the feed's categories as iterable over strings. """ categories = ( "python" , "django" ) # Hard-coded list of categories. # COPYRIGHT NOTICE -- One of the following three is optional. The # framework looks for them in this order. def feed_copyright( self , obj): """ Takes the object returned by get_object() and returns the feed's copyright notice as a normal Python string. """ def feed_copyright( self ): """ Returns the feed's copyright notice as a normal Python string. """ feed_copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright notice. # TTL -- One of the following three is optional. The framework looks # for them in this order. Ignored for Atom feeds. def ttl( self , obj): """ Takes the object returned by get_object() and returns the feed's TTL (Time To Live) as a normal Python string. """ def ttl( self ): """ Returns the feed's TTL as a normal Python string. """ ttl = 600 # Hard-coded Time To Live. # ITEMS -- One of the following three is required. The framework looks # for them in this order. def items( self , obj): """ Takes the object returned by get_object() and returns a list of items to publish in this feed. """ def items( self ): """ Returns a list of items to publish in this feed. """ items = ( 'Item 1' , 'Item 2' ) # Hard-coded items. # GET_OBJECT -- This is required for feeds that publish different data # for different URL parameters. (See "A complex example" above.) def get_object( self , request, * args, * * kwargs): """ Takes the current request and the arguments from the URL, and returns an object represented by this feed. Raises django.core.exceptions.ObjectDoesNotExist on error. """ # ITEM TITLE AND DESCRIPTION -- If title_template or # description_template are not defined, these are used instead. Both are # optional, by default they will use the unicode representation of the # item. def item_title( self , item): """ Takes an item, as returned by items(), and returns the item's title as a normal Python string. """ def item_title( self ): """ Returns the title for every item in the feed. """ item_title = 'Breaking News: Nothing Happening' # Hard-coded title. def item_description( self , item): """ Takes an item, as returned by items(), and returns the item's description as a normal Python string. """ def item_description( self ): """ Returns the description for every item in the feed. """ item_description = 'A description of the item.' # Hard-coded description. def get_context_data( self , * * kwargs): """ Returns a dictionary to use as extra context if either description_template or item_template are used. Default implementation preserves the old behavior of using {'obj': item, 'site': current_site} as the context. """ # ITEM LINK -- One of these three is required. The framework looks for # them in this order. # First, the framework tries the two methods below, in # order. Failing that, it falls back to the get_absolute_url() # method on each item returned by items(). def item_link( self , item): """ Takes an item, as returned by items(), and returns the item's URL. """ def item_link( self ): """ Returns the URL for every item in the feed. """ # ITEM_GUID -- The following method is optional. If not provided, the # item's link is used by default. def item_guid( self , obj): """ Takes an item, as return by items(), and returns the item's ID. """ # ITEM_GUID_IS_PERMALINK -- The following method is optional. If # provided, it sets the 'isPermaLink' attribute of an item's # GUID element. This method is used only when 'item_guid' is # specified. def item_guid_is_permalink( self , obj): """ Takes an item, as returned by items(), and returns a boolean. """ item_guid_is_permalink = False # Hard coded value # ITEM AUTHOR NAME -- One of the following three is optional. The # framework looks for them in this order. def item_author_name( self , item): """ Takes an item, as returned by items(), and returns the item's author's name as a normal Python string. """ def item_author_name( self ): """ Returns the author name for every item in the feed. """ item_author_name = 'Sally Smith' # Hard-coded author name. # ITEM AUTHOR EMAIL --One of the following three is optional. The # framework looks for them in this order. # # If you specify this, you must specify item_author_name. def item_author_email( self , obj): """ Takes an item, as returned by items(), and returns the item's author's email as a normal Python string. """ def item_author_email( self ): """ Returns the author email for every item in the feed. """ item_author_email = 'test@example.com' # Hard-coded author email. # ITEM AUTHOR LINK -- One of the following three is optional. The # framework looks for them in this order. In each case, the URL should # include the "http://" and domain name. # # If you specify this, you must specify item_author_name. def item_author_link( self , obj): """ Takes an item, as returned by items(), and returns the item's author's URL as a normal Python string. """ def item_author_link( self ): """ Returns the author URL for every item in the feed. """ # ITEM ENCLOSURES -- One of the following three is optional. The # framework looks for them in this order. If one of them is defined, # ``item_enclosure_url``, ``item_enclosure_length``, and # ``item_enclosure_mime_type`` will have no effect. def item_enclosures( self , item): """ Takes an item, as returned by items(), and returns a list of ``django.utils.feedgenerator.Enclosure`` objects. """ def item_enclosures( self ): """ Returns the ``django.utils.feedgenerator.Enclosure`` list for every item in the feed. """ item_enclosures = [] # Hard-coded enclosure list # ITEM ENCLOSURE URL -- One of these three is required if you're # publishing enclosures and you're not using ``item_enclosures``. The # framework looks for them in this order. def item_enclosure_url( self , item): """ Takes an item, as returned by items(), and returns the item's enclosure URL. """ def item_enclosure_url( self ): """ Returns the enclosure URL for every item in the feed. """ item_enclosure_url = "/foo/bar.mp3" # Hard-coded enclosure link. # ITEM ENCLOSURE LENGTH -- One of these three is required if you're # publishing enclosures and you're not using ``item_enclosures``. The # framework looks for them in this order. In each case, the returned # value should be either an integer, or a string representation of the # integer, in bytes. def item_enclosure_length( self , item): """ Takes an item, as returned by items(), and returns the item's enclosure length. """ def item_enclosure_length( self ): """ Returns the enclosure length for every item in the feed. """ item_enclosure_length = 32000 # Hard-coded enclosure length. # ITEM ENCLOSURE MIME TYPE -- One of these three is required if you're # publishing enclosures and you're not using ``item_enclosures``. The # framework looks for them in this order. def item_enclosure_mime_type( self , item): """ Takes an item, as returned by items(), and returns the item's enclosure MIME type. """ def item_enclosure_mime_type( self ): """ Returns the enclosure MIME type for every item in the feed. """ item_enclosure_mime_type = "audio/mpeg" # Hard-coded enclosure MIME type. # ITEM PUBDATE -- It's optional to use one of these three. This is a # hook that specifies how to get the pubdate for a given item. # In each case, the method/attribute should return a Python # datetime.datetime object. def item_pubdate( self , item): """ Takes an item, as returned by items(), and returns the item's pubdate. """ def item_pubdate( self ): """ Returns the pubdate for every item in the feed. """ item_pubdate = datetime.datetime( 2005 , 5 , 3 ) # Hard-coded pubdate. # ITEM UPDATED -- It's optional to use one of these three. This is a # hook that specifies how to get the updateddate for a given item. # In each case, the method/attribute should return a Python # datetime.datetime object. def item_updateddate( self , item): """ Takes an item, as returned by items(), and returns the item's updateddate. """ def item_updateddate( self ): """ Returns the updateddate for every item in the feed. """ item_updateddate = datetime.datetime( 2005 , 5 , 3 ) # Hard-coded updateddate. # ITEM CATEGORIES -- It's optional to use one of these three. This is # a hook that specifies how to get the list of categories for a given # item. In each case, the method/attribute should return an iterable # object that returns strings. def item_categories( self , item): """ Takes an item, as returned by items(), and returns the item's categories. """ def item_categories( self ): """ Returns the categories for every item in the feed. """ item_categories = ( "python" , "django" ) # Hard-coded categories. # ITEM COPYRIGHT NOTICE (only applicable to Atom feeds) -- One of the # following three is optional. The framework looks for them in this # order. def item_copyright( self , obj): """ Takes an item, as returned by items(), and returns the item's copyright notice as a normal Python string. """ def item_copyright( self ): """ Returns the copyright notice for every item in the feed. """ item_copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright notice. |
Please login to continue.