def get_place_info(request, id): """ search get the details of the curr ent """ if 'excluded_blood' in request.session : bloods_out_ids = request.session['excluded_blood'] else : bloods_out_ids = [] # alerts = Alert.objects\ .values('blood__blood', 'blood')\ .exclude(blood_id__in=bloods_out_ids)\ .filter(organization__id__iexact=id)\ .annotate(count=Count('blood'))\ .order_by('-count') # iterate throw out the choices choices = dict(Blood.BLOOD_TYPE) data = [] for item in alerts: # get the blood choice name , A+, O+ ... bType = choices[item['blood__blood']] data.append({'type': bType, 'count': item['count']}) t = get_template('home/organization/organization_popup.html') html = t.render(Context({'alerts': data})) return bloodon_renderAsJson(request, {'html' : html})
def send_via_mail_to(request): """ send email to list of freinds :param request: in the square represented by : west < longitude < east north < latitude < south """ idAlert = int(request.POST['id']) emails = request.POST['list'] text = request.POST['text'] listMails = emails.rstrip('#').split('#') alert = Alert.objects.get(id=idAlert) # email path = reverse("public_show_alert", args=(idAlert,)) subject = "BloodOn team team," message = '' if len(text): message += '%s \n,' % text message += 'This message has been sent from <href ="http://%s">BloodOn Inc</href>, ' \ 'Because Some one need blood , the %s, ' \ 'at %s \n ' % (settings.SITE_PATH, alert.date_for, alert.organization.name) message += '\n for more detail please refer to : <href ="http://%s%s">BloodOn' \ 'Inc</href> \n' % (settings.SITE_PATH, path) messageMail = (subject, message, settings.DEFAULT_FROM_EMAIL, listMails) send_mass_mail((messageMail,), fail_silently=False) return bloodon_renderAsJson(request, {'success' : True})
def get_event(request, day, month, year): start = datetime.combine(datetime(int(year), int(month), int(day)), time(00, 00)) end = start + timedelta(1) try : organizations = request.session['bounded_organizations'] except : organizations = [] #= organizations bloods_out_ids = request.session['excluded_blood'] # alerts = Alert.objects\ .values('blood__blood', 'blood')\ .exclude(blood_id__in=bloods_out_ids)\ .filter(date_for__gte=start, date_for__lt=end, organization_id__in = organizations)\ .annotate(count=Count('blood'))\ .order_by('-count') # iterate throw out the choices choices = dict(Blood.BLOOD_TYPE) data = [] for item in alerts: # get the blood choice name , A+, O+ ... bType = choices[item['blood__blood']] data.append({'type': bType, 'count': item['count']}) t = get_template('home/calendar/calendar_tooltip.html') html = t.render(Context({'alerts': data})) return bloodon_renderAsJson(request, {'html' : html})
def get_place_details(request, id, page): if 'excluded_blood' in request.session : bloods_out_ids = request.session['excluded_blood'] else : bloods_out_ids = [] # """ search get the details of the current """ alerts = Alert.objects\ .exclude(blood_id__in=bloods_out_ids).filter(organization__id__iexact=id)[int(page):int(page) + 10] t = get_template('home/organization/organization_detail.html') html = t.render(Context({'alerts': alerts})) return bloodon_renderAsJson(request, {'html': html})
def send_map_data(request, organizations_dictionary_by_ids): # save request request.session['map_view'] = request.GET['center'] request.session['map_zoom'] = request.GET['zoom'] organizations_ids = organizations_dictionary_by_ids.keys () request.session['bounded_organizations'] = organizations_ids if 'excluded_blood' in request.session : bloods_out_ids = request.session['excluded_blood'] else : bloods_out_ids = [] # # add date filter alerts = Alert.objects.exclude(blood_id__in=bloods_out_ids).filter(organization_id__in=organizations_ids) """\ .values('organization__id', 'organization__name', 'organization__latitude', 'organization__longitude')\ .annotate(count=Count('organization__id'))\ .order_by('-count') """ calendar = {} result = organizations_dictionary_by_ids for item in alerts : organization = item.organization id = organization.id day = item.date_for.strftime("%d-%m-%Y") if not 'count' in result[id]: result[id]['count'] = 0 result[id]["count"] += 1 if not day in calendar : calendar[day] = 0 calendar[day] += 1 # build a dictionary of organization # loop throw out alerts # # return two dictionary """ alerts = Alert.objects.filter(date_for__gte=start, date_for__lte=end) field = lambda alert: str(alert.date_for.day) + '_' + str(alert.date_for.month) alerts_ = dict( [(day, list(items)) for day, items in groupby(alerts, field)] ) return null """ return bloodon_renderAsJson(request, {'html': result , 'calendar' : calendar })
def index(request): organizations_dictionary_by_ids = search_organization_arround(request) ids = organizations_dictionary_by_ids.keys() alerts = Alert.objects.filter(organization_id__in=ids).reverse().order_by("date_for")[0:20] list = [] # for alert in alerts: # populate list list.append( { "id": alert.id, "blood": alert.blood.get_blood_display(), "organization": alert.organization.name, "date": alert.date_for.strftime("%m/%d/%Y"), } ) # recipe_list_json = #dump list as JSON # return HttpResponse(json.dumps(list), 'application/javascript') # data = serializers.serialize('json', alerts, use_natural_foreign_keys =True, fields=('blood','organization')) return bloodon_renderAsJson(request, list)
def get_event_details(request, day, month, year, page): start = datetime.combine(datetime(int(year), int(month), int(day)), time(00, 00)) end = start + timedelta(1) try : organizations = request.session['bounded_organizations'] except : organizations = [] #= organizations bloods_out_ids = request.session['excluded_blood'] # page = int(page) alerts = Alert.objects\ .exclude(blood_id__in=bloods_out_ids)\ .filter(date_for__gte=start, date_for__lt=end, organization_id__in = organizations)[page: page + 10] t = get_template('home/organization/organization_detail.html') html = t.render(Context({'alerts': alerts})) return bloodon_renderAsJson(request, { 'html': html, 'at' : date_tag(start, "D d M Y").encode('utf-8') } )