コード例 #1
0
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))
コード例 #2
0
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))
コード例 #3
0
ファイル: datamaker.py プロジェクト: SeekTheError/Kuestions
def createUser(userName):
  u = User(login=userName,email='*****@*****.**',password=encode('123123'))
  u = u.create()
  u.isActivated=True
  
  #allocate ramdom profile image
  number=random.randrange(1, 30)
  u.picture='profile/'+str(number)+'.jpg'
  u.update()
コード例 #4
0
ファイル: datamaker.py プロジェクト: SeekTheError/Kuestions
def createInitialUserList():
  username = ''
  profileImgCount = 1
  f = open('/Users/macuser/Kuestions/kuestionsWS/userlist')
  for line in f:
    username = line.replace('\n', '')
    u = User(login=username,email='*****@*****.**',password=encode('123123'))
    u = u.create()
    u.isActivated=True
    
    #allocate ramdom profile image
    u.picture='profile/'+str(profileImgCount)+'.jpg'
    profileImgCount = profileImgCount + 1
    u.update()
  
  f.close()
コード例 #5
0
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/')
コード例 #6
0
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/')