<s> import itertools <EOL> import base64 <EOL> from django . contrib . syndication . views import Feed <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . contrib . auth import authenticate , login <EOL> from django . http import HttpResponse <EOL> from apps . ecidadania . proposals . models import Proposal <EOL> from apps . ecidadania . debate . models import Debate <EOL> from apps . ecidadania . news . models import Post <EOL> from core . spaces . models import Space , Event <EOL> class HTTPAuthFeed ( Feed ) : <EOL> basic_auth_realm = '<STR_LIT>' <EOL> def __call__ ( self , request , * args , ** kwargs ) : <EOL> if request . user . is_authenticated ( ) : <EOL> return super ( HTTPAuthFeed , self ) . __call__ ( request , * args , ** kwargs ) <EOL> if '<STR_LIT>' in request . META : <EOL> auth = request . META [ '<STR_LIT>' ] . split ( ) <EOL> if len ( auth ) == <NUM_LIT:2> : <EOL> if auth [ <NUM_LIT:0> ] . lower ( ) == "<STR_LIT>" : <EOL> uname , passwd = base64 . b64decode ( auth [ <NUM_LIT:1> ] ) . split ( '<STR_LIT::>' ) <EOL> user = authenticate ( username = uname , password = passwd ) <EOL> if user is not None : <EOL> if user . is_active : <EOL> login ( request , user ) <EOL> request . user = user <EOL> return super ( HTTPAuthFeed , self ) . __call__ ( request , <EOL> * args , ** kwargs ) <EOL> response = HttpResponse ( ) <EOL> response . status_code = <NUM_LIT> <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' % self . basic_auth_realm <EOL> return response <EOL> class SpaceFeed ( HTTPAuthFeed ) : <EOL> """<STR_LIT>""" <EOL> def get_object ( self , request , space_url ) : <EOL> current_space = get_object_or_404 ( Space , url = space_url ) <EOL> return current_space <EOL> def title ( self , obj ) : <EOL> return _ ( "<STR_LIT:%s>" ) % obj . name <EOL> def link ( self , obj ) : <EOL> return obj . get_absolute_url ( ) <EOL> def description ( self , obj ) : <EOL> return _ ( "<STR_LIT>" ) % obj . name <EOL> def items ( self , obj ) : <EOL> results = itertools . chain ( <EOL> Post . objects . filter ( space = obj ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:10> ] , <EOL> Proposal . objects . filter ( space = obj ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:10> ] , <EOL> Event . objects . filter ( space = obj ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:10> ] , <EOL> Debate . objects . filter ( space = obj ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:10> ] <EOL> ) <EOL> return results <EOL> def item_title ( self , item ) : <EOL> return type ( item ) . __name__ + "<STR_LIT>" + item . title <EOL> def item_description ( self , item ) : <EOL> return item . description <EOL> return sorted ( results , key = lambda x : x . pub_date , reverse = True ) </s>
