Esempio n. 1
0
def facebook_edit(request, codigo): 
    mensaje = ''
    if request.method == 'POST':  
        obj = get_object_or_404(Facebook,pk=codigo)
        profile = request.user.get_profile()
        if profile.nivel.codigo == 1:
            obj.fec_mod = datetime.now()
            obj.idusuario_mod = profile
        else:
            obj.idadministrador_mod = profile
            obj.fec_modadm = datetime.now()      
        formulario = FacebookForm(request.POST, instance=obj,error_class=DivErrorList)  
        if formulario.is_valid():
            formulario.save()
            fechas = request.POST.getlist('tfechas')
            likes = request.POST.getlist('tlikes')            
	    #FACEBOOK_DETALLE_save
            query = FacebookDetalle.objects.filter(numfb=obj)
            for c in range(len(likes)):
                fecha = datetime.strptime(fechas[c],"%d/%m/%Y")
                try:
                    row = FacebookDetalle.objects.get(numfb=obj,item=c+1)
                    row.fechadetfb = fecha
                    row.cantidad = likes[c]
                    row.save()
                except FacebookDetalle.DoesNotExist:
                    FacebookDetalle(numfb=obj,item=c+1,fechadetfb = fecha,cantidad=likes[c],).save()
            resto= len(likes)
            while resto < len(query):
                row = FacebookDetalle.objects.get(numfb=obj,item=resto+1)
                row.delete()
                resto = resto + 1
            return redirect(reverse('ogcs-redes-facebook-query')+'?m=edit') 
    else: 
        obj = get_object_or_404(Facebook,pk=codigo)
        obj.fechacreac = obj.fechacreac.strftime("%d/%m/%Y")       
        formulario = FacebookForm(instance = obj)
    detalle = FacebookDetalle.objects.filter(numfb=obj)#.order_by('-fechadettw')
    for row in detalle:
        row.fechadetfb = row.fechadetfb.strftime("%d/%m/%Y")
    tabla = FacebookDetalleTable(detalle)
    frm_detalle = FacebookDetalleForm()
    return render_to_response('redes/facebook.html', {'formulario': formulario,'frm_detalle':frm_detalle,'opcion':'edit','codigo':codigo,'tabla':tabla}, context_instance=RequestContext(request),)
Esempio n. 2
0
def facebooksettings():
    if request.method == 'POST' and 'user' in session:
        f = FacebookForm(request.form)

        user = db.session.query(User).get(session['user'].fb_id)
        if f.auto_remind.data:
            user.remind_by_default = 't'
        else:
            user.remind_by_default = 'f'
        user.reminder_time = convert(f.reminder_time_count.data, f.reminder_time_unit.data)
        db.session.commit()

        session['user'] = user
   
        flash('Facebook Settings Updated!')
        return redirect(url_for('index'))
    elif 'user' in session:
        remind_inf = get_unit(session['user'].reminder_time)
        return render_template('facebook.html', auto_remind=session['user'].remind_by_default,
            remind_time=remind_inf['num'], remind_unit=remind_inf['unit'])
    else:
        flash('You are not logged in')
        return redirect(url_for('index'))
Esempio n. 3
0
def facebook(request): 
    mensaje = ''  
    if request.method == 'POST':  
        num = Facebook.objects.values("numfb").order_by("-numfb",)[:1]
	num = 1 if len(num)==0 else int(num[0]["numfb"])+1
        profile = Usuario.objects.get(user = request.user) 
        ifacebook = Facebook(numfb=num,idusuario_creac=profile,organismo=profile.organismo,dependencia=profile.dependencia)
        frmfacebook = FacebookForm(request.POST, instance=ifacebook,error_class=DivErrorList) # A form bound to the POST data
        if frmfacebook.is_valid():
            frmfacebook.save()
            fechas = request.POST.getlist('tfechas')
            likes = request.POST.getlist('tlikes')
	    for co in range(len(fechas)):
                fecha = fechas[co]
                fecha = datetime.strptime(fecha,"%d/%m/%Y")
                det = FacebookDetalle(numfb=ifacebook,item=co+1,fechadetfb = fecha,cantidad=likes[co],)
                det.save() 
                mensaje = 'Registro grabado satisfactoriamente'   
                frmfacebook = FacebookForm()
    else:        
        frmfacebook = FacebookForm()
    frmfacebookdetalle = FacebookDetalleForm()
    tabla = FacebookDetalleTable([])
    return render_to_response('redes/facebook.html', {'formulario': frmfacebook,'frm_detalle':frmfacebookdetalle,'opcion':'add','tabla':tabla,'mensaje':mensaje}, context_instance=RequestContext(request),)