Example #1
0
def twitter_edit(request, codigo): 
    mensaje = ''
    if request.method == 'POST':  
        itwitter = get_object_or_404(Twitter,pk=codigo)
        profile = request.user.get_profile()
        if profile.nivel.codigo == 1:
            itwitter.fec_mod = datetime.now()
            itwitter.idusuario_mod = profile
        else:
            itwitter.idadministrador_mod = profile
            itwitter.fec_modadm = datetime.now()      
        frmtwitter = TwitterForm(request.POST, instance=itwitter,error_class=DivErrorList)  
        if frmtwitter.is_valid():
            frmtwitter.save()
            fechas = request.POST.getlist('tfechas')
            tweets = request.POST.getlist('ttweets')
            siguiendos = request.POST.getlist('tsiguiendo')
            seguidores = request.POST.getlist('tseguidores')
	    #TWITTER_DETALLE_save
            query = TwitterDetalle.objects.filter(numtw=itwitter)
            for c in range(len(tweets)):
                fecha = datetime.strptime(fechas[c],"%d/%m/%Y")
                try:
                    row = TwitterDetalle.objects.get(numtw=itwitter,item=c+1)
                    row.fechadettw = fecha
                    row.tweets = tweets[c]
                    row.siguiendo = siguiendos[c]
                    row.siguidores = seguidores[c]
                    row.save()
                except TwitterDetalle.DoesNotExist:
                    TwitterDetalle(numtw=itwitter,item=c+1,fechadettw = fecha,tweets=tweets[c],siguiendo =siguiendos[c], seguidores = seguidores[c],).save()
            resto= len(tweets)
            while resto < len(query):
                row = TwitterDetalle.objects.get(numtw=itwitter,item=resto+1)
                row.delete()
                resto = resto + 1
            return redirect(reverse('ogcs-redes-twitter-query')+'?m=edit') 
    else: 
        itwitter = get_object_or_404(Twitter,pk=codigo)
        itwitter.fechacreac = itwitter.fechacreac.strftime("%d/%m/%Y")       
        frmtwitter = TwitterForm(instance = itwitter)
    detalle = TwitterDetalle.objects.filter(numtw=itwitter)#.order_by('-fechadettw')
    for row in detalle:
        row.fechadettw = row.fechadettw.strftime("%d/%m/%Y")
    tabla = DetalleTwitterTable(detalle)
    frmtwitterdetalle = TwitterDetalleForm()
    return render_to_response('redes/twitter.html', {'formulario': frmtwitter,'frm_detalle':frmtwitterdetalle,'opcion':'edit','codigo':codigo,'tabla':tabla}, context_instance=RequestContext(request),)
Example #2
0
def twitter(request): 
    mensaje = ''
    if request.method == 'POST':  
        num = Twitter.objects.values("numtw").order_by("-numtw",)[:1]
	num = 1 if len(num)==0 else int(num[0]["numtw"])+1
        profile = request.user.get_profile()
        itwittwer = Twitter(numtw=num,idusuario_creac=profile,organismo=profile.organismo,dependencia=profile.dependencia)
        frmtwitter = TwitterForm(request.POST, instance=itwittwer,error_class=DivErrorList) # A form bound to the POST data
        if frmtwitter.is_valid():
            frmtwitter.save()
            fechas = request.POST.getlist('tfechas')
            tweets = request.POST.getlist('ttweets')
            siguiendos = request.POST.getlist('tsiguiendo')
            seguidores = request.POST.getlist('tseguidores')
	    for co in range(len(fechas)):
                fecha = fechas[co]                
                fecha = datetime.strptime(fecha,"%d/%m/%Y")
                det = TwitterDetalle(numtw=itwittwer,item=co+1,fechadettw = fecha,tweets=tweets[co],siguiendo =siguiendos[co], seguidores = seguidores[co],)
                det.save() 
            mensaje = 'Registro grabado satisfactoriamente'
            frmtwitter = TwitterForm()
    else:        
        frmtwitter = TwitterForm()
    frmtwitterdetalle = TwitterDetalleForm()
    tabla = DetalleTwitterTable([])
    return render_to_response('redes/twitter.html', {'formulario': frmtwitter,'frm_detalle':frmtwitterdetalle,'opcion':'add','tabla':tabla,'mensaje':mensaje}, context_instance=RequestContext(request),)
Example #3
0
def other_services(request, template_name="account/other_services.html"):
    from zwitschern.utils import twitter_verify_credentials
    from zwitschern.pownce_utils import pownce_verify_credentials
    twitter_form = TwitterForm(request.user)
    pownce_form = PownceForm(request.user)
    twitter_authorized = False
    pownce_authorized = False
    if request.method == "POST":
        twitter_form = TwitterForm(request.user, request.POST)

        if request.POST['actionType'] == 'saveTwitter':
            if twitter_form.is_valid():
                from zwitschern.utils import twitter_account_raw
                twitter_account = twitter_account_raw(request.POST['username'], request.POST['password'])
                twitter_authorized = twitter_verify_credentials(twitter_account)
                if not twitter_authorized:
                    request.user.message_set.create(message="Twitter authentication failed")
                else:
                    twitter_form.save()
                
        if request.POST['actionType'] == 'savePownce':
            pownce_form = PownceForm(request.user, request.POST)     
            if pownce_form.is_valid():
                from zwitschern.pownce_utils import pownce_account_raw
                pownce_account = pownce_account_raw(request.POST['usernamep'], request.POST['passwordp'])
                pownce_authorized = pownce_verify_credentials(pownce_account)
                if not pownce_authorized:
                    request.user.message_set.create(message="Pownce authentication failed")
                else:
                    pownce_form.save()
    else:
        from zwitschern.utils import twitter_account_for_user
        from zwitschern.pownce_utils import pownce_account_for_user
        twitter_account = twitter_account_for_user(request.user)
        pownce_account  = pownce_account_for_user(request.user)
        twitter_authorized = twitter_verify_credentials(twitter_account)
        pownce_authorized = pownce_verify_credentials(pownce_account)
        twitter_form = TwitterForm(request.user)
        pownce_form = PownceForm(request.user)
    return render_to_response(template_name, {
        "twitter_form": twitter_form,
        "twitter_authorized": twitter_authorized,
        "pownce_form": pownce_form,
        "pownce_authorized":pownce_authorized,
    }, context_instance=RequestContext(request))