예제 #1
0
파일: views.py 프로젝트: nedo99/TS
def register(request):
    if usercheck(request, request.session.get('id'), 'user'):
      return HttpResponseRedirect("/Centar/user/" + str (request.session.get('id')))
    elif usercheck(request, request.session.get('id'), 'admin'):
      return HttpResponseRedirect("/Centar/employee/" + str(request.session.get('id')))
    elif usercheck(request, request.session.get('id'), 'superadmin'):
	    return HttpResponseRedirect("/Centar/superadmin/" + str(request.session.get('id')))
    elif request.POST:
      form = RegisterForm(request.POST) # A form bound to the POST data
      if form.is_valid():
	  user = form.cleaned_data['username']
	  user = strip_tags(user)	  
	  kor_test = Korisnici.objects.filter(username = user).count()
	  if kor_test == 0:
	    pass1 = form.cleaned_data['password']	    	
	    pass2 = form.cleaned_data['password1']	    
	    ime = form.cleaned_data['ime']	    
	    prezime = form.cleaned_data['prezime']	    
	    mail = form.cleaned_data['mail']	    
	    telefon = form.cleaned_data['telefon']	    
	    adresa = form.cleaned_data['adresa']	    
	    rodjenje = form.cleaned_data['rodjenje']	    
	    
	    if pass1 != pass2:
	      return render_to_response("Centar/register.html", {'error_message' : 'Sifre nisu jednake.', 'form': form}, context_instance = RequestContext(request))	    
	    
	    if (telefon.isalpha()):
	      return render_to_response("Centar/register.html", {'error_message' : 'Broj telefona ne moze sadrzavati slova.', 'form': form}, context_instance = RequestContext(request))
	    
	    
	    ime=strip_tags(ime)
	    prezime=strip_tags(prezime)
	    mail=strip_tags(mail)
	    telefon=strip_tags(telefon)
	    adresa=strip_tags(adresa)	
	  
	    pr = Privilegije.objects.get(tip = 'user')
	    m = md5.new()
	    m.update(pass1)
	    korisnik = Korisnici(username = user, password = m.hexdigest(), ime = ime, prezime = prezime, mail = mail, telefon = telefon, adresa = adresa, datum_rodjenja = rodjenje, vrsta = pr)
	    korisnik.save()
	    return HttpResponseRedirect('/Centar/uspjeh/')
	  else:
	    return render_to_response("Centar/register.html", {'error_message' : 'Korinsik sa unesenim korisnickim imenom vec postoji u sistemu.', 'form' : form}, context_instance = RequestContext(request))
      else:
	  return render_to_response("Centar/register.html", {'error_message' : 'Doslo je do greske prilikom registracije.', 'form': form}, context_instance = RequestContext(request))
    else :
	  form = RegisterForm()
	  return render_to_response("Centar/register.html", {'form' : form, 'info_message' : 'Unesite vase informacije.'}, context_instance = RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: nedo99/TS
def centar(request, c_id):
  message = ""
  vidi = 'hidden'
  if usercheck(request, request.session.get('id'), 'superadmin'):
    registerform = RegisterForm()
    if request.POST.get('izmjeni'):
      if request.session.get('centar') == c_id:	
	form =CentarRegister(request.POST)
	if form.is_valid():
	  naziv = form.cleaned_data['naziv']
	  adresa = form.cleaned_data['adresa']
	  
	  naziv=strip_tags(naziv)
	  adresa=strip_tags(adresa)
	
	  centar_test = SportCentri.objects.filter(naziv = naziv).exclude(id = c_id).count()
	  if centar_test == 0:
	    centar = SportCentri.objects.get(id = c_id)
	    centar.naziv = naziv
	    centar.adresa = adresa
	    centar.save()
	    message = "Podaci o sport centru izmijenjeni."
	  else:	    
	    message='Sport centar sa unsenim nazivom vec postoji u sistemu.'	
	      
    if request.POST.get('brisi'):
      if request.session.get('centar') == c_id:
	centar = SportCentri.objects.get(id = c_id)
	centar.delete()
	return HttpResponseRedirect('/Centar/superadmin/' + str(request.session.get('id')) + '/')
    centar_count = SportCentri.objects.filter(id = c_id).count()
    centar = 0
    if centar_count > 0:
      centar = SportCentri.objects.get(id = c_id)
    else:
      raise Http404
    if request.POST.get('dodajradnika'):
      if request.session.get('centar') == c_id:
	registerform =RegisterForm(request.POST)
	if registerform.is_valid():
	  user = registerform.cleaned_data['username']
	  user = strip_tags(user)
	  pass1 = registerform.cleaned_data['password']
	  pass2 = registerform.cleaned_data['password1']
	  if pass1 != pass2:
	    message = "Sifre nisu jednake."
	  else:
	    m = md5.new()
	    m.update(pass1)
	    kor_test = Korisnici.objects.filter(username = user).count()
	    if kor_test == 0 :
	      ime = registerform.cleaned_data['ime']
	      prezime = registerform.cleaned_data['prezime']
	      mail = registerform.cleaned_data['mail']
	      telefon = registerform.cleaned_data['telefon']
	      adresa = registerform.cleaned_data['adresa']
	      rodjenje = registerform.cleaned_data['rodjenje']
	      
	      ime=strip_tags(ime)
	      prezime=strip_tags(prezime)
	      mail=strip_tags(mail)
	      telefon=strip_tags(telefon)
	      adresa=strip_tags(adresa)	
	      
	      pr = Privilegije.objects.get(tip = 'admin')
	      korisnik = Korisnici(username = user, password = m.hexdigest(), ime = ime, prezime = prezime, mail = mail, telefon = telefon, adresa = adresa, datum_rodjenja = rodjenje, vrsta = pr)
	      korisnik.save()
	      radnik = Radnici(radnik = korisnik, centar = centar)
	      radnik.save()
	      message = "Radnik je dodan."
	      registerform = RegisterForm()
	      request.session['user_reg'] = user
	    else:
	      if user == request.session.get('user_reg'):
		del request.session['user_reg']
		return HttpResponseRedirect('/Centar/superadmin/centar/' + c_id + '/')
	      else:
		message = "Korisnik sa unesenim korisnickim imenom vec postoji"
		vidi = 'visible'
	else:
	  vidi = 'visible'
    request.session['centar'] = c_id
    if request.POST.get('obicnikorisnik'):
      u_id = request.POST.get('id')
      kor = Korisnici.objects.get(id = u_id)
      radnici_count = Radnici.objects.filter(radnik = kor).count()
      if radnici_count > 0:
	pr = Privilegije.objects.get(tip = 'user')
	kor.vrsta = pr
	kor.save()
	rad = Radnici.objects.get( radnik = kor)
	rad.delete()
	message = "Korisnik prebacen u obicne korisnike"
	
    if request.POST.get('izbrisiradnika'):
      u_id = request.POST.get('id')
      kor = Korisnici.objects.get(id = u_id)
      radnici_count = Radnici.objects.filter(radnik = kor).count()
      if radnici_count > 0:
	kor.delete()
	message = "Radnik izbrisan"
	
    radnici_count = Radnici.objects.filter(centar = centar).count()
    radnici_kor = []
    if radnici_count > 0:
      radnici = Radnici.objects.filter(centar = centar)
      for radnik in radnici:
	radnici_kor.append(radnik.radnik)
    korisnik = Korisnici.objects.get (id = request.session.get('id'))    
    formcentar = CentarRegister(initial={'naziv': centar.naziv, 'adresa' : centar.adresa})
    
    return render_to_response("Centar/centar.html", {"korisnik" : korisnik, 'message' : message, 'centar' : centar, 'formcentar' : formcentar, 'registerform' : registerform, 'radnici' : radnici_kor, 'vidi' : vidi}, context_instance = RequestContext(request))
  else:
    raise Http404