def phonecall_panel(request): user = request.user GET = request.GET call_start = _build_date_or_404(get_from_GET_or_404(GET, 'call_start')) person_id = get_from_GET_or_404(GET, 'person_id') number = get_from_GET_or_404(GET, 'number') context = { 'type_id': act_constants.ACTIVITYTYPE_PHONECALL, 'call_start': call_start, 'number': number, 'user_contact_id': user.linked_contact.id, } pcall = None pcall_id = GET.get('pcall_id') if pcall_id is not None: context['phone_call'] = pcall = get_object_or_404( Activity, id=pcall_id, type_id=act_constants.ACTIVITYTYPE_PHONECALL, ) user.has_perm_to_view_or_die(pcall) context['participant_contacts'] = [ r.object_entity.get_real_entity() for r in pcall.get_participant_relations() ] context['participant_organisations'] = [*orga_subjects(pcall)] person = get_object_or_404(CremeEntity, pk=person_id).get_real_entity() user.has_perm_to_view_or_die(person) if isinstance(person, Contact): context['called_contact'] = person if not pcall: context['participant_contacts'] = [person] elif isinstance(person, Organisation): context['called_orga'] = person if not pcall: context['participant_organisations'] = [person] else: raise Http404('"person_id" must be the ID of a Contact/Organisation') return render(request, 'mobile/workflow_panel.html', context)
def get_save_settings(self): return utils.get_from_GET_or_404( self.request.GET, key=self.save_settings_arg, cast=utils.bool_from_str_extended, default='0', )
def get_order(self): return utils.get_from_GET_or_404( self.request.GET, key=self.order_arg, cast=Order.from_string, default='ASC', )
def get_chart(self): return utils.get_from_GET_or_404( self.request.GET, key=self.chart_arg, cast=self.cast_chart, default=None, )
def get_number(self): number = self.number if number is None: self.number = number = get_from_GET_or_404(self.request.GET, 'number') return number
def search_person(request): search = get_from_GET_or_404(request.GET, 'search') if len(search) < 3: raise ConflictError( _('Your search is too short.')) # TODO: client-side validation # TODO: populate employers contacts = EntityCredentials.filter( request.user, Contact.objects.exclude(is_deleted=True).filter( Q(first_name__icontains=search) | Q(last_name__icontains=search) | Q( relations__type__in=( persons_constants.REL_SUB_EMPLOYED_BY, persons_constants.REL_SUB_MANAGES, ), relations__object_entity__header_filter_search_field__icontains =search, )).distinct())[:30] orgas = EntityCredentials.filter( request.user, Organisation.objects.exclude(is_deleted=True).filter( name__icontains=search))[:30] return render( request, 'mobile/search.html', { 'search': search, 'contacts': contacts, 'contact_model': Contact, 'organisations': orgas, 'orga_model': Organisation, })
def get_neighbours(request): GET = request.GET address_id = get_from_GET_or_404(GET, 'address_id', int) filter_id = get_from_GET_or_404(GET, 'filter_id', default=None) source = get_object_or_404(get_address_model(), id=address_id) distance = get_radius() entity_filter = get_object_or_404(EntityFilter, id=filter_id) if filter_id else None query_distance = GET.get('distance', '') if query_distance.isdigit(): distance = float(query_distance) neighbours = source.geoaddress.neighbours(distance).select_related( 'address') if entity_filter: model = entity_filter.entity_type.model_class() # filter owners of neighbours owner_ids = entity_filter.filter( model.objects.filter( is_deleted=False, pk__in=neighbours.values_list('address__object_id', flat=True), )).values_list('pk', flat=True) neighbours = neighbours.filter( address__content_type=ContentType.objects.get_for_model(model), address__object_id__in=owner_ids, ) # Filter credentials has_perm = request.user.has_perm_to_view addresses = [ address_as_dict(neighbor.address) for neighbor in neighbours if has_perm(neighbor.address.owner) ] return { 'source_address': address_as_dict(source), 'addresses': addresses, }
def list_view(request, model, **kwargs): """See list_view_content() for arguments""" if request.method == 'POST': mode = get_from_POST_or_404(request.POST, 'selection', cast=str_to_mode, default='multiple') else: mode = get_from_GET_or_404(request.GET, 'selection', cast=str_to_mode, default='multiple') try: template_name, template_dict = list_view_content(request, model, mode=mode, **kwargs) except NoHeaderFilterAvailable: # from ..header_filter import add as add_header_filter # return add_header_filter(request, ContentType.objects.get_for_model(model).id, # {'help_message': _('The desired list does not have any view, please create one.')} # ) from ..header_filter import HeaderFilterCreation logger.critical( 'No HeaderFilter is available for <%s> ; ' 'the developer should have created one in "populate.py" script', model) class EmergencyHeaderFilterCreation(HeaderFilterCreation): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['help_message'] = _( 'The desired list does not have any view, please create one.' ) return context def get_success_url(self): return self.request.path return EmergencyHeaderFilterCreation.as_view()( request, ct_id=ContentType.objects.get_for_model(model).id) return render(request, template_name, template_dict)
def reload_matrix_brick(request, strategy_id, orga_id): brick_id = get_from_GET_or_404(request.GET, 'brick_id') if brick_id == AssetsMatrixBrick.id_: brick = AssetsMatrixBrick() elif brick_id == CharmsMatrixBrick.id_: brick = CharmsMatrixBrick() elif brick_id == AssetsCharmsMatrixBrick.id_: brick = AssetsCharmsMatrixBrick() else: raise Http404('Invalid brick ID') strategy, orga = _get_strategy_n_orga(request, strategy_id, orga_id) return bricks.bricks_render_info( request, bricks=[brick], context=bricks.build_context(request, orga=orga, strategy=strategy), )
def get_info(self, request): GET = request.GET source = get_object_or_404( Address, id=get_from_GET_or_404(GET, 'address_id', int), ) entity_filter = self.get_efilter() # TODO: error if value but invalid as float... query_distance = GET.get('distance', '') distance = float( query_distance) if query_distance.isdigit() else get_radius() neighbours = source.geoaddress.neighbours(distance).select_related( 'address') if entity_filter: ctype = entity_filter.entity_type # Filter owners of neighbours owner_ids = entity_filter.filter( ctype.model_class().objects.filter( is_deleted=False, pk__in=neighbours.values_list('address__object_id', flat=True), )).values_list('pk', flat=True) neighbours = neighbours.filter( address__content_type=ctype, address__object_id__in=owner_ids, ) # Filter credentials has_perm = request.user.has_perm_to_view addresses = [ address_as_dict(neighbour.address) for neighbour in neighbours if has_perm(neighbour.address.owner) # TODO: populate owner ? ] return { 'source_address': address_as_dict(source), 'addresses': addresses, }