Ejemplo n.º 1
0
def add_interest(request, interest):

    s = Session.objects.get(session_key=request.session["auth_token"])
    user = User.objects.get(login=s.get_decoded()['login'])
    if Thematic.objects.filter(name=interest).count() is 0:
        thematic = Thematic(name=interest)
        thematic.save()
    else:
        thematic = Thematic.objects.get(name=interest)
    interest = Interest(user=user, thematic=thematic)
    interest.save()
    return HttpResponse('Interest added successful')
Ejemplo n.º 2
0
 def form_valid(self, form):
     """ Edit or create a new Interest """
     name = form.cleaned_data['interest']
     if self.request.GET['interest']:
         interest = Interest.objects.get( pk = self.request.GET['interest'] )
     else:
         # Each interest must be unique. The form overrides unique_validate, so make sure 
         try:
             interest = Interest.objects.get( interest = name )
         except Interest.DoesNotExist:
             interest = Interest( interest = name )
     
     interest.status = form.cleaned_data['status']
     interest.save()
     
     return HttpResponseRedirect(reverse('interest'))
Ejemplo n.º 3
0
 def create_project(self, request):
     u = self.current_user(request)
     n = t = e = key = ''; c = 0
     for k, v in request.POST.items():
         if 'title' in k: n = '#%s' % v.replace(" ", "")
         elif 'credit' in k: c = v#+int(float(v)*0.1)
         elif 'content' in k: t = v
         elif 'deadline' in k: e = datetime.strptime(v, '%d/%m/%Y')
         elif 'keyword' in k: key = v
     project = Project(name=n,user=u,content=t,end_time=e,credit=int(c))
     project.save()
     interest = Interest(project=project,key=key)
     interest.save()
     service = StreamService()
     access_token = u.profile.google_token
     t = re.compile(r'<.*?>').sub('', t)
     url, token = service.video_entry(n[:1], t, 'efforia', access_token)
     return render(request, 'projectvideo.jade', {'static_url':settings.STATIC_URL,
                                         'hostname':request.get_host(),
                                         'url':url, 'token':token}, content_type='text/html')
Ejemplo n.º 4
0
def sync_user_fb_interests(user):
    fb_account = FacebookAccount.objects.get(user=user)
    fb_id = fb_account.social_id
    fb_token = fb_account.token

    graph = GraphAPI(fb_token)
    graph_likes = graph.get_connections(fb_id, "likes")
    likes = graph_likes['data']

    for like in likes:
        like_name = like['name']
        like_category = like['category']
        like_id = like['id']
        try:
            like_date = like['created_time']
            like_creation = strptime(like_date[:-5],"%Y-%m-%dT%H:%M:%S")
            like_datecreation = datetime.date(like_creation.tm_year, like_creation.tm_mon, like_creation.tm_mday)
        except KeyError:
            like_datecreation = datetime.date.today()
        (category, created) = InterestCategory.objects.get_or_create(name=like_category)
        interests = Interest.objects.filter(fb_id=like_id)
        if len(interests) == 0:
            interest = Interest(name=like_name, category=category, fb_id=like_id)
        else:
            interest = interests[0]

        interest.name = like_name
        interest.category = category
        interest.save()

        user_interests = UserInterests.objects.filter(user=user, interest=interest)
        if len(user_interests) == 0:
            user_interest = UserInterests.objects.create(user=user, interest=interest, created=like_datecreation)
        else:
            user_interest = user_interests[0]
        user_interest.created = like_datecreation
        user_interest.save()