def get_distribution(request): if request.method == 'GET': raise Http404 data = json.loads(request.body) signed_data = data.get('signed_data') if not (signed_data and gpgtools.check_data_sign( {'data': data.get('id'), 'sign': signed_data})): raise Http404 _id = data.get('id') if not _id: raise Http404 distribution_qs = Distribution.objects.filter(pk=_id) if len(distribution_qs) != 1: return HttpResponse(json.dumps([0, ]), content_type='text/json') dist = distribution_qs[0] results = [] sadiks_ids = Requestion.objects.filter( distributed_in_vacancy__distribution=dist).distinct().values_list( 'distributed_in_vacancy__sadik_group__sadik', flat=True) options = data.get('options') for sadik in Sadik.objects.filter( id__in=sadiks_ids).distinct().order_by('number'): requestions = Requestion.objects.filter( distributed_in_vacancy__distribution=dist, distributed_in_vacancy__sadik_group__sadik=sadik, status__in=[ STATUS_DECISION, STATUS_DISTRIBUTED, STATUS_DISTRIBUTED_FROM_ES ]) if options.get('only_decision'): requestions = requestions.filter(status=STATUS_DECISION) if requestions: req_list = add_requestions_data(requestions, request) kg_dict = {'kindergtn': sadik.id, 'requestions': req_list} results.append(kg_dict) data = [{ 'id': dist.id, 'start': dttools.date_to_stamp(dist.init_datetime), 'end': dttools.date_to_stamp(dist.end_datetime), 'year': dist.year.year, 'results': results, }] return HttpResponse(gpgtools.get_signed_json(data), content_type='text/json')
def get_child_from_es(birth_cert): u""" Получаем по свидетельству о рожденнии данные о ребенке из Электросада. """ # во время тестирования api ЭС недоступно, возвращаем "dummy" объект if settings.TEST_MODE: return [] post_data = gpgtools.get_signed_json({'birth_cert': birth_cert}) domain = settings.ES_DOMAIN if not domain: site = Site.objects.get_current() domain = site.domain.split('.')[0] + '.electrosadik.ru' url = "http://{}/api/base/get_child_by_birth_cert/".format(domain) req = urllib2.Request(url) req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, post_data).read() decrypted_data = gpgtools.decrypt_data(response) return json.loads(decrypted_data)
def convert_context_to_json(self, context): return gpgtools.get_signed_json(context)