Esempio n. 1
0
def api_saveGoodThing(request):
    if request.user.is_authenticated():
        fb = django_facebook.api.get_persistent_graph(request)
        
        gt = GoodThing()
        gt.user = request.user
        gt = GoodThingForm(request.POST,instance=gt)
        gt.save()
        
        #if gt.instance.public:
            #vals = {'id':gt.instance.link(),'scrape':'true'}
            #data = urllib.urlencode(vals)
            #req = urllib2.Request("https://graph.facebook.com", data)
            #response = urllib2.urlopen(req)
            #scrapeGoodThing.delay(gt.instance.id)
                        
        try:
            wc = WordClouds.objects.get(user=request.user)
        except:
            wc = WordClouds()
            wc.user = request.user
        wc.updateClouds()
        
        if gt.instance.wall:
            if not gt.instance.public:
                gt.instance.postFB(fb,useog=False)
            else:
                gt.instance.postFB(fb)
        
        t =  loader.get_template('thingjson.json')
        c = RequestContext(request,{'obj':gt.instance})
        return HttpResponse(t.render(c))
    else:
        return HttpResponseForbidden()
Esempio n. 2
0
def api_delete(request):
    if request.user.is_authenticated():
        gt = GoodThing.objects.get(id=request.POST['gtid'])
        if gt.user == request.user:
            gt.deleted = True
            gt.save()
            
            try:
               wc = WordClouds.objects.get(user=request.user)
            except:
               wc = WordClouds()
               wc.user = request.user
           
            wc.updateClouds()
            return HttpResponse("")

    return HttpResponseForbidden()
Esempio n. 3
0
def index(request,username=None,inFb=False):

    if request.user.is_authenticated() or username is not None:
        
        import datetime
        if request.user.is_authenticated(): gtForm = GoodThingForm()
        else: gtForm = None
        
        #get some stats for the user
        if username is not None: 
            try:
                statsuser = User.objects.get(username=username)
            except:
                return HttpResponseNotFound("User not found.")
        else:
            #someone is looking at their homepage. let's make sure we have a current token.
            fb = django_facebook.api.get_persistent_graph(request)
            try: 
                trial = fb.get('me/friends')
            except:
                #no valid oauth token, get them to log in again.
                logout(request) 
                t = loader.get_template('index.html')
                c = RequestContext(request,{'inFb':inFb})
                return HttpResponse(t.render(c))
            
            statsuser = request.user
            #okay, so we should add some settings
            try:
                settings = Settings.objects.select_related().get(user=request.user)
            except:
                settings = Settings()
                settings.user = request.user
                settings.save()
            
            initial={'defaultFB': settings.defaultFB, 'defaultPublic': settings.defaultPublic}
            if settings.reminderDays != 0:
                initial['reminders']=True
                initial['reminderDays']=settings.reminderDays
            else: 
                initial['reminders'] = False;
            
            settingsForm = SettingsForm(initial=initial)
            
        gtcount = GoodThing.objects.filter(user=statsuser).filter(deleted=False).count()
        perday = float(gtcount)/max(((timezone.now() - statsuser.date_joined).days),1)
        
        if gtcount > 0:
            try:
                wc = WordClouds.objects.get(user=statsuser)
            except:
                wc = WordClouds()
                wc.user = statsuser
                wc.updateClouds()
        else: wc = None
        
        t = loader.get_template('myview.html')
        cdict = {'form':gtForm,'gtcount':gtcount,'perday':perday,'wc':wc,'inFb':inFb}
        if username is not None: cdict['viewuser'] = statsuser
        else:
            cdict['settings'] = settings
            cdict['settingsform'] = settingsForm
        
        c = RequestContext(request,cdict)
        
        return HttpResponse(t.render(c))
    #and if not, let's get them logged in
    
    else:
        #return HttpResponse(request.__str__())
        t = loader.get_template('index.html')
        c = RequestContext(request,{'inFb':inFb})
        return HttpResponse(t.render(c))