def resolve_user(self, application, account): if application.user_id: try: return User.objects.get(pk=application.user_id) except User.DoesNotExist: return AccountAnonymousUser(account) return AccountAnonymousUser(account)
def handle(self, *args, **options): if not options['resource_id'] and not options['revision_id']: self.help() raise CommandError("--resource/-r or --revision/-e obligatorios") if not options['dataset'] and not options['datastream'] and not options[ 'visualization'] and not options['dashboard']: self.help() raise CommandError( "-T/--dataset|-S/--datastream|-V/--visualization son obligatorios" ) if not options['user_id'] and not options['account_id']: self.help() raise CommandError("--user/-u|--account/-a obligatorios") try: if options['user_id']: self.user = User.objects.get(pk=options['user_id']) else: account = Account.objects.get(pk=options['account_id']) preferences = account.get_preferences() self.user = AccountAnonymousUser( account, preferences['account_language']) print account if options['dataset']: self.resource = self.get_dataset( resource_id=options['resource_id'], revision_id=options['revision_id'], published=options['published']) elif options['datastream']: self.resource = self.get_datastream( resource_id=options['resource_id'], revision_id=options['revision_id'], published=options['published']) elif options['visualization']: self.resource = self.get_visualization( resource_id=options['resource_id'], revision_id=options['revision_id'], published=options['published']) elif options['dashboard']: self.resource = self.get_dashboard( resource_id=options['resource_id'], revision_id=options['revision_id'], published=options['published']) except User.DoesNotExist: raise CommandError( u"Usuario inexistente (administrador: 1647, administrator: 1)") except Account.DoesNotExist: raise CommandError(u"Account inexistente") # muy basico except: raise CommandError(u"Revisión inexistente") self.print_resource()
def authenticate(self, request): if hasattr(request, 'account') and request.account: account = request.account return (AccountAnonymousUser(account), { 'account': account, 'preferences': None, 'language': request.auth_manager.language, 'microsite_domain': get_domain(account.id), })
def get_catalog_xml(request): logger = logging.getLogger(__name__) account_id = request.account.id language = request.auth_manager.language preferences = request.preferences account = request.account domain = get_domain_by_request(request) api_domain = preferences['account_api_domain'] transparency_domain = preferences['account_api_transparency'] account = Account.objects.get(pk=account_id) msprotocol = 'https' if account.get_preference('account.microsite.https') else 'http' apiprotocol = 'https' if account.get_preference('account.api.https') else 'http' developers_link = msprotocol + '://' + domain + reverse('manageDeveloper.filter') datastreams_revision_ids = DataStream.objects.values_list('last_published_revision').filter(last_published_revision__status=StatusChoices.PUBLISHED, user__account_id=account_id) # necesario, porque el DAO.get requiere un usuario para obtener el language y el account user = AccountAnonymousUser(account, request.auth_manager.language) resources = [] for datastream_revision_id, in datastreams_revision_ids: ds = DataStreamDBDAO().get(user, datastream_revision_id=datastream_revision_id, published=True) permalink = reverse('viewDataStream.view', urlconf='microsites.urls', kwargs={'id': ds['resource_id'], 'slug': ds['slug']}) ds['link'] = '{}://{}{}'.format(msprotocol, domain, permalink) ds['export_csv_link'] = '{}://{}{}'.format(msprotocol, domain,reverse('datastreams-data', kwargs={'id': ds['resource_id'],'format':'csv'})) ds['export_html_link'] = '{}://{}{}'.format(msprotocol, domain, reverse('datastreams-data', kwargs={'id': ds['resource_id'], 'format': 'html'}) ) ds['api_link'] = apiprotocol + '://' + api_domain + '/datastreams/' + ds['guid'] + '/data/?auth_key=your_authkey' ds['visualizations'] = [] visualization_revision_ids = Visualization.objects.values_list('last_published_revision').filter( datastream_id=ds['resource_id'], last_published_revision__status=StatusChoices.PUBLISHED ) for visualization_revision_id, in visualization_revision_ids: vz = VisualizationDBDAO().get(user, visualization_revision_id=visualization_revision_id, published=True) permalink = reverse('chart_manager.view', urlconf='microsites.urls', kwargs={'id': vz['resource_id'], 'slug': vz['slug']}) vz['link'] = msprotocol + '://' + domain + permalink ds['visualizations'].append(vz) resources.append(ds) return render_to_response('catalog.xml', locals(), content_type='application/xml')
def process_request(self, request): domain = get_domain_by_request(request) request.bucket_name = settings.AWS_BUCKET_NAME try: account = Account.get_by_domain(domain) except Account.DoesNotExist: logger = logging.getLogger(__name__) logger.error('The account do not exists: %s' % domain) return HttpResponseForbidden('') request.account = account preferences = account.get_preferences() preferences.load_all() preferences['account_id'] = account.id request.preferences = preferences bucket_name = preferences['account_bucket_name'] if bucket_name: request.bucket_name = bucket_name is_signin = False #Deprecado is_login = False #Deprecado is_activate = False #Deprecado is_jsi18n = request.path.startswith('/jsi18n') language = request.preferences['account_language'] if language: request.session['django_language'] = language request.auth_manager.language = language # TODO: Esto debería ir en una url y hacer el redirect if settings.DOMAINS['microsites'] == domain: if request.META.get('REQUEST_URI') == '/': return redirect( get_domain_with_protocol('microsites') + "/home") # hacemos que el User sea un AccountAnonymousUser # lo creamos con el account y el lenguaje que tenga el account_language request.user = AccountAnonymousUser(request.account, preferences['account_language']) return None