def page_context(request, context): context['remote_user'] = request.user context['IS_MOBILE'] = request.MOBILE context['STATIC_URL'] = settings.STATIC_URL context['APP_URL_ROOT'] = settings.APP_URL_ROOT auth = Permitted() try: auth.is_admin(request.user) context['IS_ADMIN'] = True except PermittedException: context['IS_ADMIN'] = False try: auth.can_create(request.user) context['CAN_CREATE'] = True except PermittedException: context['CAN_CREATE'] = False return context
def page_context(request, context): context['remote_user'] = request.user context['IS_MOBILE'] = request.MOBILE context['STATIC_URL'] = settings.STATIC_URL context['APP_URL_ROOT'] = settings.APP_URL_ROOT auth = Permitted() try: auth.is_admin(request.user) context['IS_ADMIN'] = True except PermittedException: context['IS_ADMIN'] = False try: auth.can_create(request.user) context['CAN_CREATE'] = True except PermittedException: context['CAN_CREATE'] = False return context
def _space_list(self): filter = {} published = True complete = True json_rep = [] seen = {} permitted = Permitted() try: is_admin = permitted.is_admin(self._request.user) except PermittedException: is_admin = False try: schema = SpotSchema().get() except SpotSchemaException as e: return self.error_response(e.args[0]['status_code'], e.args[0]['status_text']) if 'published' in self._request.GET: p = self._request.GET.get('published') published = True if (p == '1' or p.lower() == 'true') else False filter['spot_id__isnull'] = True if (not published) else False if 'complete' in self._request.GET: i = self._request.GET.get('complete') complete = (i == '1' or i.lower() == 'true') filter['spot_id__isnull'] = True if not complete: filter['is_complete__isnull'] = True else: filter['is_complete'] = True if published: search_args = { #'manager': '', #'editors': '', 'limit': '0' } try: spots = self._get_spots(search_args) except Exception, errstr: return self.error_response(500, ("%s" % (errstr))) for spot in spots: try: spot_id = spot.get('id') try: space = Space.objects.get(spot_id=spot_id) if space.is_deleted: continue except Space.DoesNotExist: space = Space(spot_id=spot_id, manager=spot.get('manager'), is_complete=True) space.save() if not is_admin: permitted.can_edit(self._request.user, space, spot) if str(spot_id) not in seen: seen[str(spot_id)] = 1 json_rep.append(self._spacemap.space_rep(space, spot, schema)) except PermittedException: pass except SpaceMapException as e: return self.error_response(e.args[0]['status_code'], e.args[0]['status_text'])
def _space_list(self): filter = {} published = True complete = True json_rep = [] seen = {} permitted = Permitted() try: is_admin = permitted.is_admin(self._request.user) except PermittedException: is_admin = False try: schema = SpotSchema().get() except SpotSchemaException as e: return self.error_response(e.args[0]['status_code'], e.args[0]['status_text']) if 'published' in self._request.GET: p = self._request.GET.get('published') published = True if (p == '1' or p.lower() == 'true') else False filter['spot_id__isnull'] = True if (not published) else False if 'complete' in self._request.GET: i = self._request.GET.get('complete') complete = (i == '1' or i.lower() == 'true') filter['spot_id__isnull'] = True if not complete: filter['is_complete__isnull'] = True else: filter['is_complete'] = True if published: search_args = { #'manager': '', #'editors': '', 'limit': '0' } try: spots = self._get_spots(search_args) except Exception, errstr: return self.error_response(500, ("%s" % (errstr))) for spot in spots: try: spot_id = spot.get('id') try: space = Space.objects.get(spot_id=spot_id) if space.is_deleted: continue except Space.DoesNotExist: space = Space(spot_id=spot_id, manager=spot.get('manager'), is_complete=True) space.save() if not is_admin: permitted.can_edit(self._request.user, space, spot) if str(spot_id) not in seen: seen[str(spot_id)] = 1 json_rep.append( self._spacemap.space_rep(space, spot, schema)) except PermittedException: pass except SpaceMapException as e: return self.error_response(e.args[0]['status_code'], e.args[0]['status_text'])