Ejemplo n.º 1
0
def plot_service_daily(month, year, event_type, dbhostip="127.0.0.1"):
    db = mdb.connect(charset='utf8', host=dbhostip, user="******", passwd="root", db="lwc_members")
    cur = db.cursor()
    days = range(1,monthrange(year, month)[1]+1) 
#     print days

    d1 = date(year, month, 1)
    d2 = date(year, month, calendar.monthrange(year, month)[1])# get last day of the month
    delta = d2 - d1
    date_list = [d1+td(days=i) for i in range(delta.days+1)]
#     print date_list
    
    present_list = []
    for day in days:
        cur.execute("SELECT count(*) FROM member_attendance_summary WHERE DAY(event_date)=%d AND MONTH(event_date)=%d AND YEAR(event_date)=%d \
        AND event_type='%s' AND status='P' " % (day,month,year, event_type))
        count = cur.fetchall()[0][0] 
        present_list.append(count) 
        
    broadcast_list = []
    for day in days:
        cur.execute("SELECT count(*) FROM member_attendance_summary WHERE DAY(event_date)=%d AND MONTH(event_date)=%d AND YEAR(event_date)=%d \
        AND event_type='%s' AND status='B' " % (day,month,year,event_type))
        count = cur.fetchall()[0][0] 
        broadcast_list.append(count) 
    
#     print present_list
#     print broadcast_list
    db.close()
    return present_list, broadcast_list, days, date_list
Ejemplo n.º 2
0
def listar(request):
    
    q=request.GET.get('q','')
    fecha__gte=request.GET.get('fecha__gte','1900-01-01')
    fecha__lt=request.GET.get('fecha__lt','2050-01-01')
    usuario=request.user
        
    if not usuario.has_perm(USUARIO_LIMITADO):
           objeto_total=AsientoContableDetalle.objects.filter(asiento_contable__fecha__contains=q,
                                                          asiento_contable__fecha__gt=fecha__gte,
                                                       asiento_contable__fecha__lt=fecha__lt).count()
    else:
        id_comunidad=get_comunidad(usuario)
        objeto_total=AsientoContableDetalle.objects.filter(asiento_contable__fecha__contains=q,
                                                          asiento_contable__fecha__gt=fecha__gte,
                                                       asiento_contable__fecha__lt=fecha__lt,asiento_contable__comunidad_id=id_comunidad).count()
    page=request.GET.get('page',1)
    
    lines=[]
    for i in range(objeto_total):
        lines.append(u'Line %s' % (i + 1))
    nro_lineas=100
    paginator = Paginator(lines, nro_lineas)
    try:
        page=int(page)
    except:
        page=1
    if int(page)*nro_lineas>objeto_total or int(page)>0:
        try:
            items = paginator.page(page)
            fin=int(page)*nro_lineas
            ini =fin-nro_lineas
        except PageNotAnInteger or EmptyPage:
            fin=nro_lineas
            ini=0
            items = paginator.page(1)
    else:
        fin=nro_lineas
        ini=0
        items = paginator.page(1)
        
    if not usuario.has_perm(USUARIO_LIMITADO):
           asientos=AsientoContableDetalle.objects.filter(asiento_contable__fecha__contains=q,
                                                          asiento_contable__fecha__gt=fecha__gte,
                                                       asiento_contable__fecha__lt=fecha__lt)[ini:fin]
    else:
        id_comunidad=get_comunidad(usuario)
        if id_comunidad == 0:
            pass
        asientos=AsientoContableDetalle.objects.filter(asiento_contable__fecha__contains=q,
                                                          asiento_contable__fecha__gt=fecha__gte,
                                                       asiento_contable__fecha__lt=fecha__lt,asiento_contable__comunidad_id=id_comunidad)

    hoy = datetime.datetime.today()
    ayer=hoy+datetime.timedelta(days=-1)
    ultimos_7dias = hoy + datetime.timedelta(days=-7)
    manana = hoy + datetime.timedelta(days=1)
    today=timezone_today()
    
    cant_dias=calendar.monthrange(today.year,1)[1]
    ultimos_30dias_max=  str(today.year)+'-'+str(today.month)+'-'+str(today.day)
    ultimos_30dias_min = str(today.year) + '-' + str(today.month) + '-01'
    este_anho_max=str(today.year+1) + '-01-01'
    este_anho_min=str(today.year) + '-01-01'
    
    return render_to_response('asientos/nuevo_asientos_list.html',
    {'asientos':asientos,'hoy':str(hoy.date()),'ultimos_30dias_max':ultimos_30dias_max,'page' : page,
     'ayer':str(ayer.date()),'ultimos_30dias_min':ultimos_30dias_min,'este_anho_max':este_anho_max,'este_anho_min':este_anho_min
        ,'ultimo_7dias':str(ultimos_7dias.date()),'manana':str(manana.date())},
    context_instance=RequestContext(request,{ 'lines': items }))
Ejemplo n.º 3
0
def next_month(d):
    days_in_month = calendar.monthrange(d.year, d.month)[1]
    last = d.replace(day=days_in_month)
    next_month = last + timedelta(days=1)
    month = 'month=' + str(next_month.year) + '-' + str(next_month.month)
    return month
Ejemplo n.º 4
0
    def myhandler(self, document, http, error):
        self.album._requests -= 1

        if error:
            if "Temporarily Unavailable" in http.errorString():
                log.info(
                    "HTTP Temporarily Unavailable - Repeating lookup later")
                self.mydolookup()
            else:
                self.album._finalize_loading(True)
            return

        log.debug("Track = %s (%s)", self.track_node.recording[0].id,
                  self.track_node.recording[0].title[0].text)
        olddate = datetime.now()
        newdate = datetime(1, 1, 1, 0, 0, 0)
        for release in document.metadata[0].recording[0].release_list[
                0].release:

            try:
                log.debug("\tDate=%s", release.date[0].text)

                calcmonthlength = False

                if len(release.date[0].text) == 10:
                    dtstrmin = dtstrmax = release.date[0].text
                elif len(release.date[0].text) == 7:
                    dtstrmin = dtstrmax = release.date[0].text + "-01"
                    calcmonthlength = True
                elif len(release.date[0].text) == 4:
                    dtstrmin = release.date[0].text + "-01-01"
                    dtstrmax = release.date[0].text + "-12-31"
                else:
                    continue
            except:
                continue

            try:
                dtobjmin = datetime.strptime(dtstrmin, '%Y-%m-%d')
                dtobjmax = datetime.strptime(dtstrmax, '%Y-%m-%d')
                if calcmonthlength:
                    dtobjmax.day = calendar.monthrange(dtobjmax.year,
                                                       dtobjmax.month)[1]
            except:
                log.info(
                    "ERROR: Unknown date format dtstrmin='%s' dtstrmax='%s' for Recording ID: %s",
                    dtstrmin, dtstrmax, self.track_node.recording[0].id)
                continue

            if dtobjmax < olddate:
                olddate = dtobjmax
                olddatestr = release.date[0].text

            if dtobjmin > newdate:
                newdate = dtobjmin
                newdatestr = release.date[0].text

        try:
            self.metadata['firstrecorded'] = olddatestr
            log.debug("Oldest Date = %s", olddatestr)
        except:
            log.info("Unable to find oldest date for Recording ID: %s",
                     self.track_node.recording[0].id)
        finally:
            self.album._finalize_loading(None)
Ejemplo n.º 5
0
def add_months(sourcedate, months):
    month = sourcedate.month - 1 + months
    year = sourcedate.year + month // 12
    month = month % 12 + 1
    day = min(sourcedate.day, calendar.monthrange(year, month)[1])
    return datetime.date(year, month, day)