def view(request, login):
    #TODO distinguish those case: the user see his page, the user see another page
    #And : Distinguish GET/POST method (need to split in different method)
    context = RequestContext(request)
    context = userauth.checkSession(request, context)
    currentUser = userauth.getCurrentUser(context)
    context['currentUser'] = currentUser
    if currentUser and currentUser.login == login:
        print currentUser.login
        context['isAdmin'] = True
        imageForm = ImageUploadForm()
        context['form'] = imageForm
    else:
        context['isAdmin'] = False
    user = User(login=login)
    user = user.findByLogin()
    if user is None:
        print "not found"
        return userNotFound(request)
    if not user.picture:
        user.picture = 'default.png'
    if user.picture is None:
        user.picture = 'default.png'

    context["user"] = user
    t = loader.get_template('profile.html')
    return HttpResponse(t.render(context))
def view(request, login) :
  #TODO distinguish those case: the user see his page, the user see another page
  #And : Distinguish GET/POST method (need to split in different method)
  context = RequestContext(request)
  context = userauth.checkSession(request, context)
  currentUser = userauth.getCurrentUser(context)
  context['currentUser']=currentUser
  if currentUser and currentUser.login == login:
    print currentUser.login
    context['isAdmin'] = True
    imageForm = ImageUploadForm()
    context['form'] = imageForm
  else :
    context['isAdmin'] =False
  user = User(login=login)
  user = user.findByLogin()
  if user is None :
    print "not found"
    return userNotFound(request)
  if not user.picture:
    user.picture='default.png'
  if user.picture is None:
    user.picture='default.png'

  context["user"] = user  
  t = loader.get_template('profile.html')
  return HttpResponse(t.render(context))
Beispiel #3
0
def addTopic(request):
    '''
  this function add a new topic with form post data "newTopic"
  '''
    currentUser = getCurrentUser(request)
    if currentUser:
        user = User(login=currentUser.login)
        user = user.findByLogin()

        if request.POST['newTopic']:
            inputTopicStr = smart_unicode(request.POST["newTopic"],
                                          encoding='utf-8',
                                          strings_only=False,
                                          errors='strict')
            inputArray = inputTopicStr.split(' ')
            for newTopic in inputArray:
                print "add Topic:" + newTopic
                topics = user.topics
                if not (newTopic.lower() in (topic.lower()
                                             for topic in topics)):
                    if newTopic is not '':
                        user.topics.append(newTopic.lower())
                        user.update()
                        print "result: " + str(user.topics)
    return HttpResponseRedirect('/user/')
Beispiel #4
0
    def testBasicPersistence(self):
        switchToTestDatabase()
        u = User(login='******')
        u.create()
        u = u.findByLogin()
        id = u.id
        print id

        q = Question(asker=id, content="To be or not to be?")
        #print "before persistence: ",q
        print q.content
        question = q.create()
        deleteTestDatabase()
Beispiel #5
0
 def testBasicPersistence(self):
   switchToTestDatabase()  
   u=User(login='******')
   u.create()
   u=u.findByLogin()
   id=u.id
   print id
   
   q=Question(asker=id,content="To be or not to be?")
   #print "before persistence: ",q
   print q.content
   question=q.create()
   deleteTestDatabase()
def updateResume(request):
  '''
  this function updates user resume with form post data "newResume"
  '''
  currentUser = getCurrentUser(request)
  if currentUser:
    user = User(login=currentUser.login)
    user = user.findByLogin()
    newResume = smart_unicode(request.POST["newResume"], encoding='utf-8', strings_only=False, errors='strict')
    #newResume = request.POST['newResume'].decode('UTF-8')
    if newResume:
      user.resume = newResume
      user.update()
  return HttpResponseRedirect('/user/')
def pictureUpload(request):
  if request.method == 'POST':
    form = ImageUploadForm(request.POST, request.FILES)
    if form.is_valid():
      currentUser = getCurrentUser(request)
      if currentUser:
        path = "profile/"+currentUser.login+strftime("(%Y-%m-%d_%H.%M.%S)", gmtime())+".jpg"
        destination = open(STATIC_MEDIA_ROOT+"/"+path, 'wb+')
        for chunk in request.FILES['picture'].chunks():
          destination.write(chunk)
        destination.close()
        user = User(login=currentUser.login)
        user = user.findByLogin()
        user.picture=path
        user.update()
  
  return HttpResponseRedirect('/user/')
def updateResume(request):
    '''
  this function updates user resume with form post data "newResume"
  '''
    currentUser = getCurrentUser(request)
    if currentUser:
        user = User(login=currentUser.login)
        user = user.findByLogin()
        newResume = smart_unicode(request.POST["newResume"],
                                  encoding='utf-8',
                                  strings_only=False,
                                  errors='strict')
        #newResume = request.POST['newResume'].decode('UTF-8')
        if newResume:
            user.resume = newResume
            user.update()
    return HttpResponseRedirect('/user/')
def pictureUpload(request):
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            currentUser = getCurrentUser(request)
            if currentUser:
                path = "profile/" + currentUser.login + strftime(
                    "(%Y-%m-%d_%H.%M.%S)", gmtime()) + ".jpg"
                destination = open(STATIC_MEDIA_ROOT + "/" + path, 'wb+')
                for chunk in request.FILES['picture'].chunks():
                    destination.write(chunk)
                destination.close()
                user = User(login=currentUser.login)
                user = user.findByLogin()
                user.picture = path
                user.update()

    return HttpResponseRedirect('/user/')
def signin(request) :
  login=request.POST['login']
  password=request.POST['password']
  user=User(login=login)
  user=user.findByLogin()
  password=encode(password)
  if login=='' or password=='' :
    message='Please enter a login and a password'
  elif not user :
    message = 'This account does not exist'
  elif not user.isActivated :
    message= 'This account has not been activated yet'
  elif not user.password == password :
    message= 'wrong login/password combination'
  else : #every thing went fine, the session can be open
    return openSession(request,user)
  #return a response in case an error occurred
  return render_to_response('index.html', {'message': message},context_instance=RequestContext(request))
Beispiel #11
0
def signin(request) :
  login=request.POST['login']
  password=request.POST['password']
  user=User(login=login)
  user=user.findByLogin()
  password=encode(password)
  if login=='' or password=='' :
    message='Please enter a login and a password'
  elif not user :
    message = 'This account does not exist'
  elif not user.isActivated :
    message= 'This account has not been activated yet'
  elif not user.password == password :
    message= 'wrong login/password combination'
  else : #every thing went fine, the session can be open
    return openSession(request,user)
  #return a response in case an error occurred
  return render_to_response('index.html', {'message': message},context_instance=RequestContext(request))
def addTopic(request):
  '''
  this function add a new topic with form post data "newTopic"
  '''
  currentUser = getCurrentUser(request)
  if currentUser:
    user = User(login=currentUser.login)
    user = user.findByLogin()
    
    if request.POST['newTopic']:
      newTopic = smart_unicode(request.POST["newTopic"], encoding='utf-8', strings_only=False, errors='strict')
      #newTopic = request.POST['newTopic'].decode('UTF-8')
      print "add Topic:"+newTopic
      topics = user.topics
      if not (newTopic.lower() in (topic.lower() for topic in topics)):
        
        user.topics.append(newTopic)
        user.update()
        print "result: "+str(user.topics)
  return HttpResponseRedirect('/user/')
def deleteTopic(request):
  '''
  this function delete a topic with form post data "deleteTopic"
  '''
  currentUser = getCurrentUser(request)
  if currentUser:
    user = User(login=currentUser.login)
    user = user.findByLogin()
    
    
    if request.POST['deleteTopic']:
      deleteTopic = request.POST['deleteTopic']
      #deleteTopic = smart_unicode(request.POST["deleteTopic"], encoding='utf-8', strings_only=False, errors='strict')
      print "del Topic:"+deleteTopic
      topics = user.topics
      user.topics = [topic for topic in topics if deleteTopic.lower() != topic.lower()]
        #if deleteTopic.lower() == topic.lower():
        #  print topics
        #  print topic
      user.update()
      print "result: "+str(user.topics)
  return HttpResponseRedirect('/user/') 
def deleteTopic(request):
    '''
  this function delete a topic with form post data "deleteTopic"
  '''
    currentUser = getCurrentUser(request)
    if currentUser:
        user = User(login=currentUser.login)
        user = user.findByLogin()

        if request.POST['deleteTopic']:
            deleteTopic = request.POST['deleteTopic']
            #deleteTopic = smart_unicode(request.POST["deleteTopic"], encoding='utf-8', strings_only=False, errors='strict')
            print "del Topic:" + deleteTopic
            topics = user.topics
            user.topics = [
                topic for topic in topics
                if deleteTopic.lower() != topic.lower()
            ]
            #if deleteTopic.lower() == topic.lower():
            #  print topics
            #  print topic
            user.update()
            print "result: " + str(user.topics)
    return HttpResponseRedirect('/user/')
def userPicture(request, login):
    user = User(login=login)
    user = user.findByLogin()
    if not user:
        return HttpResponse('No User', mimetype="image/jpg")
    return HttpResponseRedirect('/kuestions/media/' + user.picture)
def userPicture(request, login):
  user=User(login=login)
  user=user.findByLogin()
  if not user:
    return HttpResponse('No User',mimetype="image/jpg")  
  return HttpResponseRedirect('/kuestions/media/'+user.picture)
Beispiel #17
0
def userPicture(request, login):
    user = User(login=login)
    user = user.findByLogin()
    if not user:
        return HttpResponseRedirect('/kuestions/media/profile.png')
    return HttpResponseRedirect('/kuestions/media/' + user.picture)
def userPicture(request, login):
  user=User(login=login)
  user=user.findByLogin()
  if not user:
    return HttpResponseRedirect('/kuestions/media/profile.png')
  return HttpResponseRedirect('/kuestions/media/'+user.picture)