Esempio n. 1
0
def settings(request):
    base_vars = get_base_vars(request)
    try:
        pwdChng=request.GET['pwdChng']
        if pwdChng == 'Success':
            base_vars.update({'pwdMsg':"<span style='color:#008800'>Password Change Successful</span>"})
        elif pwdChng == "Fail":
            base_vars.update({'pwdMsg':"<span style='color:#880000'>Password Change Fail</span>"})

                    
    except:
        pass

    if request.user.is_authenticated():
        user_current=User.objects.get(email=request.user.email)
        person_current=account_models.person.objects.get(user_ptr=user_current.pk)
        user_data={}
        user_data['first_name']=user_current.first_name
        user_data['last_name']=user_current.last_name
        user_data['sex']=person_current.sex
        user_data['occupation']=person_current.occupation
        user_data['phno']=person_current.phno
        user_data['institution']=person_current.institution
        user_data['address']=person_current.address
        user_data['pin']=person_current.pin

        pool=AccountSettingsForm(user_data)
        base_vars.update({'pool':pool})	
        return render_to_response("account_settings.html",base_vars)
    else:
        base_vars.update({"reg_form":SignupForm,"login_form":LoginForm()})
        return render_to_response("account_login_register.html",base_vars)
Esempio n. 2
0
def index(request):
    base_vars = get_base_vars(request)

    if request.user.is_authenticated():
        # doesn't need to signup
		return HttpResponseRedirect("/account/settings/")
    if request.method=="POST":
    # verify fields and login
        login_form = LoginForm( request.POST )
        if login_form.is_valid():
            email=request.POST['email']
            username=User.objects.get(email=email)
            password=request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                # authenticated so returning as authenticated
                login(request,user)
                return HttpResponseRedirect("/");
            else:
                # error page with retry
                login_form._errors['email'] = ErrorList( ['Wrong email or password'] )
                base_vars.update({"reg_form":SignupForm(),"login_form":login_form})
                return render_to_response("account_login_register.html",base_vars) 
        else:
            base_vars.update({"reg_form":SignupForm(), "login_form":login_form})
            return render_to_response("account_login_register.html", base_vars)
    else:
        # if method is get returns login form 
        base_vars.update({"reg_form":SignupForm(),"login_form":LoginForm()})
        return render_to_response("account_login_register.html",base_vars)
Esempio n. 3
0
def logout(request):
    if request.user.is_authenticated():	
        auth_logout(request)
        return HttpResponseRedirect("/")
    else:
        base_vars = get_base_vars(request)

    base_vars.update({"message":"You are not authorised to be here"})
    return render_to_response("message.html", base_vars)
Esempio n. 4
0
def pages(request, url):
    base_vars = get_base_vars(request)

    try:
        page = Page.objects.get( url=url )
        url = 'page/%s' %url
    except:
        page = Page.objects.get( pk=1 ) 
        url = ''
    base_vars.update({'page' : page, 'url' : url })
    return render_to_response('pages.html', base_vars)
Esempio n. 5
0
def pages(request, url):
    base_vars = get_base_vars(request)

    try:
        page = Page.objects.get(url=url)
        url = 'page/%s' % url
    except:
        page = Page.objects.get(pk=1)
        url = ''
    base_vars.update({'page': page, 'url': url})
    return render_to_response('pages.html', base_vars)
Esempio n. 6
0
def home(request):
    base_vars = get_base_vars(request)
    
    # fetching updates and snippets
    updates = Updates.objects.all().filter( active = True ).order_by( '-date' )[:4]
    snippets = Snippets.objects.all().order_by( 'pk' )[:4] 
    nf = nfEntry.objects.all().filter( published = True )

    # adding updates to the template dict
    base_vars.update({'updates':updates})
    base_vars.update({'snippets':snippets})
    base_vars.update({'nf':nf})

    return render_to_response("home.html", base_vars  )
Esempio n. 7
0
def home(request):
    base_vars = get_base_vars(request)

    # fetching updates and snippets
    updates = Updates.objects.all().filter(active=True).order_by('-date')[:4]
    snippets = Snippets.objects.all().order_by('pk')[:4]
    nf = nfEntry.objects.all().filter(published=True)

    # adding updates to the template dict
    base_vars.update({'updates': updates})
    base_vars.update({'snippets': snippets})
    base_vars.update({'nf': nf})

    return render_to_response("home.html", base_vars)
Esempio n. 8
0
def article(request, url):
    base_vars = get_base_vars(request)
    url_bak = url

    # stripping url of trailing /
    # neccessary in case a url like /initiativse/kljsaf/lsfjdsl/// is entered
    url = url.split('/')
    while url[-1] is u'':
        del (url[-1])

    if url.__len__() is 1:
        '''Do whatever for top level elements'''
        sector = Sector.objects.get(url=url.pop(), parent=None)
    else:
        '''Return the article matching the given sector and pass it to the template with the updated base_var dictionary'''
        sector = Sector.objects.get(url=url.pop(),
                                    parent=Sector.objects.get(url=url.pop()))

    # generating article content & heading
    heading = sector.name
    text = sector.article.content

    # generating breadcrumbs
    crumbs = [sector]
    while crumbs[-1].parent is not None:
        crumbs.append(crumbs[-1].parent)
    crumbs.reverse()

    # generating top_nav level 2
    current_root_sector = crumbs[0]

    # generating sidebar
    siblings = Sector.objects.filter(parent=sector.parent)
    children = Sector.objects.filter(parent=sector)

    base_vars.update({
        'article': text,
        'heading': heading,
        'url': url_bak,
        'crumbs': crumbs,
        'siblings': siblings,
        'children': children,
        'current_root_sector': current_root_sector
    })
    return render_to_response("article.html", base_vars)

    # Otherwise return Http404 since no match could be found
    return render_to_response("404.html", base_vars)
Esempio n. 9
0
def signup(request):
    base_vars = get_base_vars(request)

    if request.user.is_authenticated():
    # cant allow a logged in user to signup
        base_vars.update({"message":"You are already logged in. Please logout and then signup for a new account"})
        return render_to_response("message.html",base_vars)
    else:
        if request.method=="POST":
        # Submission 
            suForm=SignupForm(request.POST)
            if suForm.is_valid():
                pk=len(User.objects.all()).__str__()
                username=pk.join([request.POST['first_name'],request.POST['last_name']])
                user=User.objects.create_user(username=username,email=request.POST['email'],password=request.POST['password1']) #create a User with the given name as username and password 
                user.first_name=request.POST['first_name']
                user.last_name=request.POST['last_name']
                user.save()
                #save the other credentials of the Person
                person = account_models.person()
                person.user_ptr = user
                person.sex = request.POST['sex']
                person.occupation = request.POST['occupation']
                person.phno = request.POST['phno']
                person.institution = request.POST['institution']
                person.address = request.POST['address']
                person.pin = request.POST['pin']
                person.save()
                # log him in and go to home page
                logged_in_user = authenticate(username=username,password=request.POST['password1'])
                if logged_in_user is not None:
                    login(request,logged_in_user)
                    return HttpResponseRedirect("/")        
            else:
			    # invalid form
                base_vars.update({"reg_form":suForm,"login_form":LoginForm()})
                return render_to_response("account_login_register.html",base_vars)
        else:
        # unauthenticated user so return a blank form
            base_vars.update({"reg_form":SignupForm(),"login_form":LoginForm()})
            return render_to_response("account_login_register.html",base_vars)
Esempio n. 10
0
def article(request,url):
    base_vars = get_base_vars(request)
    url_bak = url

    # stripping url of trailing /
    # neccessary in case a url like /initiativse/kljsaf/lsfjdsl/// is entered
    url = url.split('/')
    while url[-1] is u'':
       del(url[-1])

    if url.__len__() is 1:
        '''Do whatever for top level elements'''
        sector = Sector.objects.get( url =url.pop() , parent = None )
    else:
        '''Return the article matching the given sector and pass it to the template with the updated base_var dictionary'''
        sector = Sector.objects.get( url = url.pop() , parent = Sector.objects.get( url = url.pop()))

    # generating article content & heading
    heading = sector.name
    text = sector.article.content

    # generating breadcrumbs
    crumbs = [sector]
    while crumbs[-1].parent is not None:
        crumbs.append( crumbs[-1].parent )
    crumbs.reverse()

    # generating top_nav level 2
    current_root_sector = crumbs[0] 

    # generating sidebar
    siblings = Sector.objects.filter( parent = sector.parent )
    children = Sector.objects.filter( parent = sector )

    base_vars.update({'article':text,'heading':heading, 'url' : url_bak , 'crumbs' : crumbs , 'siblings' : siblings , 'children' : children , 'current_root_sector' : current_root_sector })
    return render_to_response("article.html", base_vars)

    # Otherwise return Http404 since no match could be found
    return render_to_response("404.html",base_vars)
Esempio n. 11
0
def change(request):
    if request.user.is_authenticated() and request.method == "POST":
        user = request.user
        person = account_models.person.objects.get( user_ptr = user )
        # assignments follow
        user.first_name = request.POST['first_name']
        user.last_name = request.POST['last_name']
        user.save()

        person.occupation = request.POST['occupation']
        person.phno = request.POST['phno']
        person.institution = request.POST['institution']
        person.address = request.POST['address']
        person.pin = request.POST['pin']
        person.save()

        return HttpResponseRedirect('/account/settings')

    else:
        base_vars = get_base_vars(request)

        base_vars.update({"message":"You are not authorised to be here"})
        return render_to_response("message.html", base_vars)