示例#1
0
def deleteEntry(request,entry_id):
    mlogger.debug("deleting an entry.............")    
    entry = Entry.objects.get(pk=entry_id)
    removeUserTagWeights(entry.tags,request.user,settings.CONTRIBUTION_WEIGHT)
    entry.delete()
    create_message(request,"Successfully deleted the entry")
    return HttpResponseRedirect(reverse('mypostsurl'))
示例#2
0
def activateEmail(request,userid,activation_key):
    mlogger.debug("Activating email.........................")    
    error = ''
    
    try :
          u =  User.objects.get(pk=userid)
          profile = u.get_profile()
                    
          if len(profile.activation_key) > 0 :
            if profile.activation_key == activation_key :                
                #logic for activation key expiration
                todaydate = datetime.datetime.now()
                if profile.createddate <   todaydate - datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS) :
                    #activation key has been expired
                    create_message(request,"Activation key has been expired.Please request for a new one")
                    return render_to_response("institution/activation_error.html",RequestContext(request))
                 
                #activate the user    
                profile.emailverified = True
                #reset the activation key
                profile.activation_key = ''
                profile.save()
                create_message(request,"Successfully activated your email")
                #either login or directly transfer him to the corresponding page
                return redirect_to_login(next='')
            else :                
                create_message(request,"Invalid activation key")         
          else :
            create_message(request,"Invalid Userid and activation key combination...............")
                
            return redirect_to_login(next='')
          return render_to_response("institution/activation_error.html",RequestContext(request))              
    except User.DoesNotExist :            
            create_message(request,"Invalid Userid and activation key combination...............")
            return render_to_response("institution/activation_error.html",RequestContext(request))
示例#3
0
def postAJob(request):
    mlogger.debug("posting a job.......................")    
    if request.method == "GET":
        form  = JobForm(user=request.user)        
        return render_to_response('jobs/postjob.html',{'form':form},RequestContext(request))
    elif request.method =="POST":
        form =  JobForm(request.POST,user=request.user)
        if form.is_valid() :
            j=form.save(commit=False)                        
            j.postedby = request.user
            j.institute = request.institute
            j.save()
            
            if j.sendemail is not None :
                emaillist = j.sendemail.getEmailList(request.institute)
                fullurl = j.getfullurl(request.institute)
                deliverEmail('new_job_subject.html','new_job_message.html',{'institute':request.institute,'job':j,'fullurl':fullurl},emaillist)
                
            #Assign tags to jobs    
            j.tags = form.cleaned_data['tags']
            assignUserTagWeights(j.tags,request.user,settings.CONTRIBUTION_WEIGHT)          
            create_message(request,"Successfuly posted your job")
            return HttpResponseRedirect(reverse('displayjoburl'))            
        else:
           return render_to_response('jobs/postjob.html',{'form':form},RequestContext(request))
示例#4
0
def editInstitute(request):
    mlogger.debug("Editing the institute data")
    
    if request.method == "GET" :
        admin = request.institute.admin
        profile = admin.get_profile()
        initial_data = {'adminname':profile.fullname,
                                           'adminemail':admin.email,
                                            }    
        form = IRegForm(request.institute.id,initial=initial_data,instance=request.institute)
    elif request.method == "POST" :
        admin = request.institute.admin
        profile = admin.get_profile()        
        form = IRegForm(request.institute.id,request.POST,instance=request.institute)
        
        if form.is_valid() :
            create_message(request,"Update the institute settings successfully ................")
            profile.fullname = form.cleaned_data['adminname']
            profile.user.username = form.cleaned_data['adminemail'].replace("@","_").replace(".","_")
            profile.save()
            admin.email = form.cleaned_data['adminemail']
            admin.save()
            inst = form.save(commit=False)
            inst.save()
            
    return render_to_response("institution/editinstitute.html",{'form':form},RequestContext(request))
示例#5
0
def deleteJob(request, jobid):
    ''' delete the above jobid '''
    j = Job.objects.get(pk=int(jobid))
    removeUserTagWeights(j.tags, request.user, settings.CONTRIBUTION_WEIGHT)
    j.delete()
    create_message(request, "Successfuly deleted the job")
    return HttpResponseRedirect(reverse('displayjoburl'))
示例#6
0
def editFund(request, fundid):
    fundid = int(fundid)
    fund = Fund.objects.get(pk=fundid)
    if request.user.id == fund.user.id:
        if request.method == "GET":
            mlogger.debug("the person who posted the fund is editing")
            form = FundForm(instance=fund)
            return render_to_response('payments/addfund.html', {
                'form': form,
                'editmode': True
            }, RequestContext(request))
        elif request.method == "POST":
            form = FundForm(request.POST, instance=fund)
            if form.is_valid():
                form.save()
                create_message(request, "Successfuly edited the fund")
                return HttpResponseRedirect(reverse('displayfundsurl'))
            else:
                return render_to_response('payments/addfund.html', {
                    'form': form,
                    'editmode': True
                }, RequestContext(request))
    else:
        create_message(request, "You are not authorized to edit this fund")
        return HttpResponseRedirect(reverse('displayfundsurl'))
示例#7
0
def askQuestion(request):
    ''' display form which allows user to ask question'''
    mlogger.debug("Ask question.................")
    if request.method == "GET":
        form = QuestionForm()
        return render_to_response("askalumini/askquestion.html",
                                  {'form': form}, RequestContext(request))
    else:
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.user = request.user
            question.institute = request.institute
            question.save()
            question.tags = form.cleaned_data['tags']
            assignUserTagWeights(question.tags, request.user,
                                 settings.CONTRIBUTION_WEIGHT)
            create_message(request, "Sucessfully posted your question")
            return HttpResponseRedirect(reverse('askaluminiurl'))
        else:
            pass
            #we will pass the same form

        return render_to_response("askalumini/askquestion.html",
                                  {'form': form}, RequestContext(request))
示例#8
0
def editJob(request,jobid):
    jobid = int(jobid)
    job = Job.objects.get(pk=jobid)
    originaltags = job.tags
    if request.user.id == job.postedby.id :
        if request.method == "GET" :
            mlogger.debug("the person who posted the job is editing")
            form = JobForm(instance=job,initial={'tags':' '.join(job.tags.values_list('name',flat=True))},user=request.user)            
            return render_to_response('jobs/postjob.html',{'form':form,'editmode':True},RequestContext(request))
        elif request.method == "POST":            
            form = JobForm(request.POST, instance=job,user=request.user)
            if form.is_valid() :
                newjob = form.save(commit=False)
                newjob.save()
                removeUserTagWeights(originaltags,request.user,settings.CONTRIBUTION_WEIGHT)                
                newjob.tags = form.cleaned_data['tags']
                #what about tags brother                  
                assignUserTagWeights(newjob.tags,request.user,settings.CONTRIBUTION_WEIGHT)                            
                create_message(request,"Successfuly edited your job")
                return HttpResponseRedirect(reverse('displayjoburl'))
            else:
                return render_to_response('jobs/postjob.html',{'form':form,'editmode':True},RequestContext(request))
    else :
        create_message(request,"You are not authorized to edit this job")
        return HttpResponseRedirect(reverse('viewjoburl',kwargs={'jobid':job.id}))
示例#9
0
def deleteEvent(request,eventid):
    eventid = int(eventid)
    event = Event.objects.get(id=eventid)
    removeUserTagWeights(event.tags,request.user,settings.CONTRIBUTION_WEIGHT)
    event.delete()
    create_message(request,"Successfuly deleted the event................")
    return HttpResponseRedirect(reverse('agendaviewurl'))
示例#10
0
def postAJob(request):
    mlogger.debug("posting a job.......................")
    if request.method == "GET":
        form = JobForm(user=request.user)
        return render_to_response('jobs/postjob.html', {'form': form},
                                  RequestContext(request))
    elif request.method == "POST":
        form = JobForm(request.POST, user=request.user)
        if form.is_valid():
            j = form.save(commit=False)
            j.postedby = request.user
            j.institute = request.institute
            j.save()

            if j.sendemail is not None:
                emaillist = j.sendemail.getEmailList(request.institute)
                fullurl = j.getfullurl(request.institute)
                deliverEmail('new_job_subject.html', 'new_job_message.html', {
                    'institute': request.institute,
                    'job': j,
                    'fullurl': fullurl
                }, emaillist)

            #Assign tags to jobs
            j.tags = form.cleaned_data['tags']
            assignUserTagWeights(j.tags, request.user,
                                 settings.CONTRIBUTION_WEIGHT)
            create_message(request, "Successfuly posted your job")
            return HttpResponseRedirect(reverse('displayjoburl'))
        else:
            return render_to_response('jobs/postjob.html', {'form': form},
                                      RequestContext(request))
示例#11
0
def publishNewsLetter(request,entry_id=None):
    mlogger.debug("publish new newsletters")
    if request.method == "GET" :
        if entry_id is None :
               form = PublishForm(user=request.user)
        else :
               entry=Entry.objects.get(pk=entry_id)
               form = PublishForm(instance=entry,user=request.user)
        return render_to_response('publish/institute_create_new.html',{'form':form},RequestContext(request))
    elif request.method == "POST" :        
        form = PublishForm(request.POST,user=request.user)
        if form.is_valid() :
            entry = form.save(commit=False)
            entry.institute = request.institute
            entry.user = request.user
            entry.save()
            if request.POST['whichbutton'] == "save" :                
                create_message(request,"saved your news letter")           
                return HttpResponseRedirect(reverse('publishnewurl2',kwargs={'entry_id':entry.id})+"?backto=publishhome")
            else:
                if entry.sendemail is not None :                    
                    emaillist = entry.sendemail.getEmailList(request.institute)
                    fullurl = entry.getfullurl(request.institute)
                    deliverEmail('new_newsletter_subject.html','new_newsletter.html',{'institute':request.institute,'entry':entry,'fullurl':fullurl},emaillist)
                
                entry.tags = form.cleaned_data['tags']
                assignUserTagWeights(entry.tags,request.user,settings.CONTRIBUTION_WEIGHT)
                create_message(request,"Successfully created blog post")
                return HttpResponseRedirect(reverse('newsletterurl'))               
        else:
            return render_to_response('publish/institute_create_new.html',{'form':form},RequestContext(request))            
示例#12
0
def deleteJob(request,jobid):
    ''' delete the above jobid '''
    j = Job.objects.get(pk=int(jobid))
    removeUserTagWeights(j.tags,request.user,settings.CONTRIBUTION_WEIGHT)
    j.delete()
    create_message(request,"Successfuly deleted the job")
    return HttpResponseRedirect(reverse('displayjoburl'))       
示例#13
0
def editMailGroup(request, mailgroupid):
    mlogger.debug("edit a mail group................................")
    mailgroupid = int(mailgroupid)
    mailgroup = MailGroup.objects.get(pk=mailgroupid)
    industries = Industry.objects.all()
    if request.user.id == mailgroup.user.id:
        if request.method == "GET":
            mlogger.debug("the person who posted the job is editing")
            form = MailGroupForm(instance=mailgroup,
                                 institute=request.institute)
            return render_to_response('mailgroups/createmailgroup.html', {
                'form': form,
                'editmode': True,
                'industries': industries
            }, RequestContext(request))
        elif request.method == "POST":
            form = MailGroupForm(request.POST,
                                 instance=mailgroup,
                                 institute=request.institute)
            if form.is_valid():
                form.save()
                create_message(request, "Successfuly edited the mailgroup")
                return HttpResponseRedirect(reverse('displaymailgroupurl'))
            else:
                return render_to_response('mailgroups/createmailgroup.html', {
                    'form': form,
                    'editmode': True,
                    'industries': industries
                }, RequestContext(request))
    else:
        create_message(request,
                       "You are not authorized to edit this mailgroup")
        return HttpResponseRedirect(reverse('displaymailgroupurl'))
示例#14
0
def changeLocation(request):
        profile = request.user.get_profile()
        if request.method == "GET" :           
                initial_data = {'country':profile.country.id,
                                           'state':profile.state,
                                           'city':profile.city,
                                           'address':profile.address,
                                           'latitude':profile.latitude,
                                           'longitude':profile.longitude
                                          }                   
                form = LocationForm(initial=initial_data)
                return render_to_response("institution/changelocation.html",{'form':form},RequestContext(request))
        elif request.method == "POST" :
            form = LocationForm(request.POST)
            if form.is_valid() :            
                up = profile
                up.country =  form.cleaned_data['country']
                up.state = None if len(form.cleaned_data['state'].strip())  <= 0  else  form.cleaned_data['state'].strip()
                up.city = None if len(form.cleaned_data['city'].strip())  <= 0  else  form.cleaned_data['city'].strip() 
                up.address = None if len(form.cleaned_data['address'].strip())  <= 0  else  form.cleaned_data['address'].strip()  
                up.latitude = float(form.cleaned_data['latitude'])
                up.longitude = float(form.cleaned_data['longitude'])
                up.save()
                create_message(request,"Successfully changed to new location")
                return HttpResponseRedirect(reverse('changelocationurl'))     
            else:
                return render_to_response("institution/changelocation.html",{'form':form},RequestContext(request))
示例#15
0
def editEvent(request,eventid):
    eventid = int(eventid)
    event = Event.objects.get(id=eventid)
    originaltags = event.tags
    if request.user.id == event.user.id :
        if request.method == "GET" :
            mlogger.debug("the person who posted the event is editing")
            form = EventForm(instance=event,initial={'tags':' '.join(event.tags.values_list('name',flat=True))},user=request.user)            
            return render_to_response('events/create_event.html',{'form':form,'editmode':True},RequestContext(request))
        elif request.method == "POST":            
            form = EventForm(request.POST,instance=event,user=request.user)
            if form.is_valid() :
                   newevent = form.save(commit=False)
                   newevent.save()                   
                   removeUserTagWeights(originaltags,request.user,settings.CONTRIBUTION_WEIGHT)
                   newevent.tags = form.cleaned_data['tags']
                   assignUserTagWeights(newevent.tags,request.user,settings.CONTRIBUTION_WEIGHT)               
                   if event.sendemail is not None :
                        emaillist = event.sendemail.getEmailList(request.institute)                          
                        deliverEmail('event_created_subject.html','event_created.html',{'institute':request.institute,'event':event,'edit':True,'site':settings.SITE_URL},emaillist)
                    
                   create_message(request,"Successfuly edited the event")
                   return HttpResponseRedirect(reverse('agendaviewurl')) 
            else:      
                   return render_to_response('events/create_event.html',{'form':form,'editmode':True},RequestContext(request))  
            
    else :
        create_message(request,"You are not authorized to edit this event")
        return HttpResponseRedirect(reverse('agendaviewurl'))
示例#16
0
def login_user(request):
    password_form = PasswordResetForm()
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('logout'))
    if request.method == 'POST':
        login_form = LoginForm(data=request.POST)
        if login_form.is_valid():
            login(request, login_form.get_user())
            request.session.set_expiry(1800)
            return conditional_redirect(request, reverse('profile'))
        else:
            # invalid login form
            create_message(
                request,
                _("Due to recent complex changes in our shop you have to register even if you've had an account in old biolander"
                  ),
                type=1)
            return render_to_response('customers/login.html', {
                'form': login_form,
                'password_form': password_form
            },
                                      context_instance=RequestContext(request))
    else:
        # empty form
        login_form = LoginForm()
        return render_to_response('customers/login.html', {
            'form': login_form,
            'password_form': password_form,
            'next': request.GET.get('next', '')
        },
                                  context_instance=RequestContext(request))
示例#17
0
def deletePaper(request,entry_id):
    mlogger.debug("deleting an entry.............")    
    entry = Entry.objects.get(pk=entry_id)
    removeUserTagWeights(entry.tags,request.user,settings.CONTRIBUTION_WEIGHT)
    entry.delete()
    create_message(request,"Successfully deleted the paper")
    return HttpResponseRedirect(reverse('facultyarchiveurl',kwargs={'faculty_name':entry.user.get_profile().getSlugifyName()}))                
示例#18
0
def deleteQuestion(request, questionno):
    ''' deleting a question '''
    question = Question.objects.get(pk=questionno)
    removeUserTagWeights(question.tags, request.user,
                         settings.CONTRIBUTION_WEIGHT)
    question.delete()
    create_message(request, "Sucessfully deleted the new question")
    return HttpResponseRedirect(reverse('askaluminiurl'))
示例#19
0
def cart_flush(request):
    """
    Remove all items from cart and flush session data related to cart.
    """
    cart = Cart(request)
    cart.flush()
    create_message(request, _("Cart has been flushed"))
    return conditional_redirect(request, '/')
示例#20
0
def cart_flush(request):
    """
    Remove all items from cart and flush session data related to cart.
    """
    cart = Cart(request)
    cart.flush()
    create_message(request, _("Cart has been flushed"))
    return conditional_redirect(request, '/')
示例#21
0
def approveMemebers(request):
    mlogger.debug('admin approving %s .............')
    if request.method == "GET" :
        if not  request.user.get_profile().isadmin :
             create_message(request,"Your are not authorized to do this operation............")
             return HttpResponseRedirect(reverse('dashboardurl'))
        
       
        paginator =  Paginator(Faculty.objects.filter(institutes__in=[request.institute.id],profile__approved=0).order_by('-createddate'),1)
        toapprove = paginator.page(1)
        if toapprove.object_list :
            fi = FacultyInstitute.objects.get(faculty__id = toapprove.object_list[0].id,institute__id = request.institute.id)
            return render_to_response("institution/approve_member.html",{'institute':request.institute,'toapprove':toapprove.object_list[0],'entity':'faculty','fi':fi},RequestContext(request))
        else :            
            si = None
            paginator = Paginator(Student.objects.filter(institutes__in=[request.institute.id],profile__approved=0).order_by('-createddate'),1)
            toapprove = paginator.page(1)
            
            if toapprove.object_list :                
                toapprove = toapprove.object_list[0]
                si = StudentInstitute.objects.get(student__id = toapprove.id,institute__id=request.institute.id)
            else :
                toapprove = None
            return render_to_response("institution/approve_member.html",{'toapprove':toapprove,'entity':'student','si':si},RequestContext(request))
    elif request.method == "POST":
         d = {}
         id = int(request.POST['id'])
         entity = request.POST['entity']
         flag = int(request.POST['flag'])
         
         k = None
        
         if entity == "student":
            k = Student.objects.get(pk=id)            
         else :
            k = Faculty.objects.get(pk=id)
        
         profile = k.profile
         #approve
         if flag :
            profile.approved = 1
            d['message'] = "Sucessfully approved..........."
         #Reject the member ship
         else:
             profile.approved = -1
             d['message'] = "Successfully rejected .................."
         
         profile.save()
         #deliver mail
         if entity =="student":
            deliverEmail('studentapproved_subject.html','studentapproved_message.html',{'user':request.user,'approved':profile.approved},profile.user.email)
         else :
            deliverEmail('facultyapproved_subject.html','facultyapproved_message.html',{'user':request.user,'approved':profile.approved},profile.user.email)
            
         
         d['success'] = "yes"      
         json = simplejson.dumps(d)         
         return HttpResponse(json)    
示例#22
0
def cart_add(request, slug):
    product = get_object_or_404(Product, slug=slug)
    quantity = request.GET.get('quantity', False)
    cart = Cart(request)
    if quantity:
        cart.add([product.pk for i in range(0, int(quantity))])
    else:
        cart.add(product)
    create_message(request, _("Product %s added") % product.name)
    return conditional_redirect(request, reverse('show_cart'))
示例#23
0
def cart_add(request, slug):
    product = get_object_or_404(Product, slug=slug)
    quantity = request.GET.get('quantity', False)
    cart = Cart(request)
    if quantity:
        cart.add([product.pk for i in range(0, int(quantity))])
    else:
        cart.add(product)
    create_message(request, _("Product %s added") % product.name)
    return conditional_redirect(request, reverse('show_cart'))
示例#24
0
def password_change(request):
  if request.method == 'POST' and not request.user.is_staff:
    password_form = PasswordChangeForm(user=request.user, data=request.POST)
    if password_form.is_valid():
      password_form.save()
      password_form = PasswordChangeForm(user=request.user)
      create_message(request, _("Password change successfull"))
  else:
    password_form = PasswordChangeForm(user=request.user)
  return render_to_response('customers/profile_password.html', {'password_form':password_form }, context_instance=RequestContext(request)) 
示例#25
0
def address_delete(request, address_id):
  address = Address.published.get(pk=address_id)
  if not address.customer == request.user.get_profile() or request.user.is_staff:
    raise Http404
  try:
    address.delete()
    #create_message(request, "Address successfully deleted")
    create_message(request, _("Address successfully deleted"))
  except: 
    create_message(request, _("You cannot delete all your addresses"))
  return conditional_redirect(request, reverse('profile_address'))
示例#26
0
def panel(request):
    if not request.user.get_profile().is_active_partner():
        create_message(request, _("You have not registered as partner or your account has not been aprooved"))
        return conditional_redirect(request, reverse('profile'))
    partner = Partner.objects.get(user=request.user)
    history = PartnerHistory.objects.income_daily(partner=partner)
    return render_to_response(
        'resellers/panel.html', {
            'partner':partner,
            'history':json.dumps(history),
            'next': request.REQUEST.get('next', ''),
        }, context_instance=RequestContext(request))
示例#27
0
def address_delete(request, address_id):
    address = Address.published.get(pk=address_id)
    if not address.customer == request.user.get_profile(
    ) or request.user.is_staff:
        raise Http404
    try:
        address.delete()
        #create_message(request, "Address successfully deleted")
        create_message(request, _("Address successfully deleted"))
    except:
        create_message(request, _("You cannot delete all your addresses"))
    return conditional_redirect(request, reverse('profile_address'))
示例#28
0
def address_edit(request, address_id):
  address = Address.published.get(pk=address_id)
  if not address.customer == request.user.get_profile():
    raise Http404
  if request.method == 'POST' and not request.user.is_staff:
    form = AddressEditForm(request.POST, instance=address)
    if form.is_valid():
      form.save()
      create_message(request, _("Operation successfull"))
      return conditional_redirect(request, reverse('profile_address'))
  else:
    form = AddressEditForm(instance=address)
  return render_to_response('customers/profile_address_add.html', {'form':form }, context_instance=RequestContext(request)) 
示例#29
0
def subscribe(request):
    if request.method == 'POST':
        from django.forms.fields import email_re
        if email_re.match(request.POST['email']):
            sub = Subscription(email=request.POST['email'])
            sub.save()
            create_message(request, "Dodano do newslettera")
            return conditional_redirect(request, '/')
        else:
            create_message(request, "Błędny adres e-mail")
            return conditional_redirect(request, '/')
    else:
        return conditional_redirect(request, '/')
示例#30
0
def password_change(request):
    if request.method == 'POST' and not request.user.is_staff:
        password_form = PasswordChangeForm(user=request.user,
                                           data=request.POST)
        if password_form.is_valid():
            password_form.save()
            password_form = PasswordChangeForm(user=request.user)
            create_message(request, _("Password change successfull"))
    else:
        password_form = PasswordChangeForm(user=request.user)
    return render_to_response('customers/profile_password.html',
                              {'password_form': password_form},
                              context_instance=RequestContext(request))
示例#31
0
def changePicture(request):   
    mlogger.debug("Changing the picture of the user...............")
    if request.method == "GET" :        
        form = ImageUploadForm()
        return render_to_response("institution/changephoto.html",{'form':form},RequestContext(request))                        
    elif request.method == "POST" :         
         form = ImageUploadForm(request.POST,request.FILES)
         if form.is_valid() :            
            createAdminAvatar(request,request.user,'newphoto')
            create_message(request,"Successfully uploaded the new photo.............")
            return HttpResponseRedirect(reverse('changepictureurl'))
            
         return render_to_response("institution/changephoto.html",{'form':form},RequestContext(request))                        
示例#32
0
def set_message(message, request=None, user=None):
    """
    Sets a user message for one-time display
    """
    if user or request:
        if request:
            _user = request.user
        else:
            _user = user
        if _user.is_authenticated():
            _user.message_set.create(message=message)
        else:
            create_message(request, message)
示例#33
0
def subscribe(request):
  if request.method == 'POST':
    from django.forms.fields import email_re
    if email_re.match(request.POST['email']):
      sub = Subscription(email=request.POST['email'])
      sub.save()
      create_message(request, "Dodano do newslettera")
      return conditional_redirect(request, '/')
    else:
      create_message(request, "Błędny adres e-mail")
      return conditional_redirect(request, '/')
  else:
      return conditional_redirect(request, '/')
示例#34
0
def changePassword(request):
    mlogger.debug("Changing the password.........................")
    if request.method == "GET" :
       form = ChangePasswordForm(request.user.id)
    elif request.method == "POST" :        
        form = ChangePasswordForm(request.user.id,request.POST)
        if form.is_valid():
            user = request.user
            user.set_password(form.cleaned_data['new_password'])
            user.save()
            create_message(request,"Sucessfully changed your password..............")
            return HttpResponseRedirect(reverse('changepasswordurl'))
   
    return render_to_response("institution/changepassword.html",{'form':form},RequestContext(request))                        
示例#35
0
def editEntry(request,entry_id):
    mlogger.debug("editing an entry....................")    
    entry = Entry.objects.get(pk=int(entry_id))
    originaltags = entry.tags
    if request.method == "GET":
        form = PublishForm(instance=entry,initial={'tags':' '.join(entry.tags.values_list('name',flat=True))},user=request.user,editmode=entry.id)      
        backto =  request.GET['backto']        
        return render_to_response('publish/institute_create_new.html',{'form':form,'editmode':True,'backto':backto},RequestContext(request))
    elif request.method == "POST":
        form = PublishForm(request.POST, instance=entry,user=request.user)
        if form.is_valid() :
            newentry = form.save(commit=False)            
            newentry.save()
            removeUserTagWeights(originaltags,request.user,settings.CONTRIBUTION_WEIGHT)
            newentry.tags = form.cleaned_data['tags']
            assignUserTagWeights(newentry.tags,request.user,settings.CONTRIBUTION_WEIGHT)            
            if request.POST['whichbutton'] == "save":
                create_message(request,"saved your news letter")
                return HttpResponseRedirect(reverse('editentryurl',kwargs={'entry_id':entry.id})+"?backto="+request.POST['backto'])
            else :            
                if request.POST['backto'] == "publishhome" :
                    create_message(request,"Successfully created blog post")
                    return HttpResponseRedirect(reverse('newsletterurl'))                
                elif request.POST['backto'] == "archive":
                    create_message(request,"Successfully edited the blog post")
                    return HttpResponseRedirect(reverse('archiveurl'))
                else :
                    create_message(request,"Successfully edited the blog post")
                    return HttpResponseRedirect(reverse('mypostsurl'))
        else:
            return render_to_response('publish/institute_create_new.html',{'form':form,'editmode':True,'backto':request.POST['backto']},RequestContext(request))            
示例#36
0
def address_add(request):
  next = request.REQUEST.get('next', False)
  if request.method == 'POST' and not request.user.is_staff:
    form = AddressEditForm(request.POST)
    if form.is_valid():
      address = form.save(commit=False)
      customer = request.user.get_profile()
      address.customer = customer
      address.save()
      create_message(request, _("Operation successfull"))
      return conditional_redirect(request, reverse('profile_address'))
  else:
    form = AddressEditForm()
  return render_to_response('customers/profile_address_add.html', {'form':form, 'next':next }, context_instance=RequestContext(request)) 
示例#37
0
def address_edit(request, address_id):
    address = Address.published.get(pk=address_id)
    if not address.customer == request.user.get_profile():
        raise Http404
    if request.method == 'POST' and not request.user.is_staff:
        form = AddressEditForm(request.POST, instance=address)
        if form.is_valid():
            form.save()
            create_message(request, _("Operation successfull"))
            return conditional_redirect(request, reverse('profile_address'))
    else:
        form = AddressEditForm(instance=address)
    return render_to_response('customers/profile_address_add.html',
                              {'form': form},
                              context_instance=RequestContext(request))
示例#38
0
 def is_valid(self):
   """
   Validates shipping and payment methods
   """
   from session_messages import create_message
   if not self.shipment is None and not self.payment is None:
     from orders.models import PAYMENT_TYPES, SHIPMENT_TYPES
     if self.shipment in [m[0] for m in SHIPMENT_TYPES] and self.payment in [p[0] for p in PAYMENT_TYPES]:
       return True
     else:
       create_message(self.request, _("Invalid payment/shipment type. Please contact system administrator."), type=1)
       return False
   else:
     create_message(self.request, _("You have to choose payment and shipment method"), type=1)
     return False
示例#39
0
def addNewFund(request):
    mlogger.debug("adding new fund")
    if request.method == "GET":
        form = FundForm()
        return render_to_response('payments/addfund.html',{'form':form},RequestContext(request))
    elif request.method == "POST":
        form = FundForm(request.POST)
        if form.is_valid() :
            fund = form.save(commit=False)
            fund.institute = request.institute
            fund.user = request.user
            fund.save()
            create_message(request,"Created new fund successfully...............")
            return HttpResponseRedirect(reverse('displayfundsurl'))
        else :
            return render_to_response('payments/addfund.html',{'form':form},RequestContext(request))
示例#40
0
def addDegree(request):
    if request.method == "GET":
        form = DegreeForm()
        return render_to_response("institution/degrees/add_degree.html",{'form':form},RequestContext(request))
    elif request.method == "POST":
        form = DegreeForm(request.POST)
        if form.is_valid() :
            d = Degree()
            d.name = form.cleaned_data['name']
            d.established = form.cleaned_data['established']
            d.institute = request.institute
            d.user = request.user
            d.save()
            create_message(request,"Succesfully added the degree")
            return HttpResponseRedirect(reverse('showdegreeurl'))
        else:
            return render_to_response("institution/degrees/add_degree.html",{'form':form},RequestContext(request))
示例#41
0
def address_add(request):
    next = request.REQUEST.get('next', False)
    if request.method == 'POST' and not request.user.is_staff:
        form = AddressEditForm(request.POST)
        if form.is_valid():
            address = form.save(commit=False)
            customer = request.user.get_profile()
            address.customer = customer
            address.save()
            create_message(request, _("Operation successfull"))
            return conditional_redirect(request, reverse('profile_address'))
    else:
        form = AddressEditForm()
    return render_to_response('customers/profile_address_add.html', {
        'form': form,
        'next': next
    },
                              context_instance=RequestContext(request))
示例#42
0
def login_user(request):
  password_form = PasswordResetForm()
  if request.user.is_authenticated():
    return HttpResponseRedirect(reverse('logout'))
  if request.method == 'POST':
    login_form = LoginForm(data=request.POST)
    if login_form.is_valid():
      login(request, login_form.get_user())
      request.session.set_expiry(1800)
      return conditional_redirect(request, reverse('profile'))
    else:
      # invalid login form
      create_message(request, _("Due to recent complex changes in our shop you have to register even if you've had an account in old biolander"), type=1)
      return render_to_response('customers/login.html', {'form':login_form, 'password_form':password_form}, context_instance=RequestContext(request)) 
  else:
    # empty form
    login_form = LoginForm()
    return render_to_response('customers/login.html', {'form':login_form, 'password_form':password_form, 'next':request.GET.get('next', '')}, context_instance=RequestContext(request)) 
示例#43
0
def profile_edit(request):
  if request.method == 'POST' and not request.user.is_staff:
    profile_form = ProfileChangeForm(request.POST)
    if profile_form.is_valid():
      email = profile_form.cleaned_data['email']
      first_name = profile_form.cleaned_data['first_name']
      last_name = profile_form.cleaned_data['last_name']
      username = base64.b64encode(email)[:30]
      user = User.objects.get(username=request.user.username)
      user.first_name = first_name
      user.last_name = last_name
      user.email = email
      user.username = username
      user.save()
      create_message(request, _("Operation successfull"))
  else:
    profile_form = ProfileChangeForm(instance=request.user)
  return render_to_response('customers/profile_edit.html', {'profile_form':profile_form }, context_instance=RequestContext(request)) 
示例#44
0
def search(request, page=1):
    if request.method == 'GET':
        q = request.GET.get('q', "").strip()
        if len(q) < 3:
            create_message(request, "Fraza zbyt któtka")
            return conditional_redirect(request, '/')
        products = Product.published.filter(
            Q(name__icontains=q) | Q(description__icontains=q)
            | Q(usage__icontains=q) | Q(ingredients__icontains=q))
    else:
        return conditional_redirect(request, '/')
    template = 'products/product_search.html'
    return list_detail.object_list(request,
                                   queryset=products,
                                   paginate_by=PRODUCTS_PER_PAGE,
                                   page=page,
                                   allow_empty=True,
                                   template_name=template,
                                   extra_context={'phrase': q})
示例#45
0
def addCourse(request):
    mlogger.debug("show all courses in all the departments...........")
    if request.method == "GET":
        form = CourseForm(institute=request.institute)
        return render_to_response("institution/courses/add_course.html",{'form':form},RequestContext(request))
    elif request.method == "POST" :
        form = CourseForm(request.POST,institute=request.institute)
        if form.is_valid():
            c = Course()
            c.name = form.cleaned_data['name']
            c.introduced = form.cleaned_data['introduced']
            c.user = request.user
            c.institute = request.institute
            c.save()
            c.departments = form.cleaned_data['departments']
            create_message(request,"Succesfully added the course")
            return HttpResponseRedirect(reverse('showcoursesurl'))           
        else:
            return render_to_response("institution/courses/add_course.html",{'form':form},RequestContext(request))
示例#46
0
def addNewFund(request):
    mlogger.debug("adding new fund")
    if request.method == "GET":
        form = FundForm()
        return render_to_response('payments/addfund.html', {'form': form},
                                  RequestContext(request))
    elif request.method == "POST":
        form = FundForm(request.POST)
        if form.is_valid():
            fund = form.save(commit=False)
            fund.institute = request.institute
            fund.user = request.user
            fund.save()
            create_message(request,
                           "Created new fund successfully...............")
            return HttpResponseRedirect(reverse('displayfundsurl'))
        else:
            return render_to_response('payments/addfund.html', {'form': form},
                                      RequestContext(request))
示例#47
0
def editFund(request,fundid):
    fundid = int(fundid)
    fund = Fund.objects.get(pk=fundid)
    if request.user.id == fund.user.id :
        if request.method == "GET" :
            mlogger.debug("the person who posted the fund is editing")
            form = FundForm(instance=fund)            
            return render_to_response('payments/addfund.html',{'form':form,'editmode':True},RequestContext(request))
        elif request.method == "POST":            
            form = FundForm(request.POST, instance=fund)
            if form.is_valid() :                
                form.save()                
                create_message(request,"Successfuly edited the fund")
                return HttpResponseRedirect(reverse('displayfundsurl'))
            else:
                return render_to_response('payments/addfund.html',{'form':form,'editmode':True},RequestContext(request))
    else :
        create_message(request,"You are not authorized to edit this fund")
        return HttpResponseRedirect(reverse('displayfundsurl'))
示例#48
0
def displayQuestion(request, questionno):
    ''' display question and its answers'''
    q = Question.objects.get(pk=questionno)
    answers = q.answer_set.all().order_by('createddate')
    page = getPage(request)
    if request.method == "GET":
        mlogger.debug("Display question and its answers.................")
        form = AnswerForm()
        if request.user.id != q.user.id:
            assignUserTagWeights(q.tags, request.user, settings.VIEW_WEIGHT)
        return object_list(request,
                           queryset=answers,
                           extra_context={
                               'question': q,
                               'form': form
                           },
                           template_object_name="answers",
                           paginate_by=settings.ANSWERS_PER_PAGE,
                           page=page,
                           template_name="askalumini/question.html")
    elif request.method == "POST":
        mlogger.debug("REcieve answer")
        form = AnswerForm(request.POST)
        if form.is_valid():
            answer = form.save(commit=False)
            answer.user = request.user
            answer.question = q
            answer.institute = request.institute
            answer.save()
            create_message(request, "Sucessfully posted your answer")
            return HttpResponseRedirect(
                reverse('displayquestionurl', kwargs={'questionno': q.id}))
        else:
            return object_list(request,
                               queryset=answers,
                               extra_context={
                                   'question': q,
                                   'form': form
                               },
                               template_object_name="answers",
                               paginate_by=settings.ANSWERS_PER_PAGE,
                               page=page,
                               template_name="askalumini/question.html")
示例#49
0
def profile_edit(request):
    if request.method == 'POST' and not request.user.is_staff:
        profile_form = ProfileChangeForm(request.POST)
        if profile_form.is_valid():
            email = profile_form.cleaned_data['email']
            first_name = profile_form.cleaned_data['first_name']
            last_name = profile_form.cleaned_data['last_name']
            username = base64.b64encode(email)[:30]
            user = User.objects.get(username=request.user.username)
            user.first_name = first_name
            user.last_name = last_name
            user.email = email
            user.username = username
            user.save()
            create_message(request, _("Operation successfull"))
    else:
        profile_form = ProfileChangeForm(instance=request.user)
    return render_to_response('customers/profile_edit.html',
                              {'profile_form': profile_form},
                              context_instance=RequestContext(request))
示例#50
0
def editDegree(request,degree_id):
    mlogger.debug("Editing the department  %s ", (degree_id,))
    degree_id = int(degree_id)
    degree = Degree.objects.get(pk=degree_id)
    if request.user.id == degree .user.id :
        if request.method == "GET" :
                mlogger.debug("the person who posted the degreeis editing")
                form = DegreeForm(instance=degree)            
                return render_to_response('institution/degrees/add_degree.html',{'form':form,'editmode':True},RequestContext(request))
        elif request.method == "POST":            
                form = DegreeForm(request.POST, instance=degree)
                if form.is_valid() :
                    form.save()
                    create_message(request,"Successfuly  edited the degree")
                    return HttpResponseRedirect(reverse('showdegreeurl'))
                else:
                    return render_to_response('institution/degrees/add_degree.html',{'form':form,'editmode':True},RequestContext(request))
    else :
        create_message(request,"You are not authorized to edit this degree")
        return HttpResponseRedirect(reverse('showdegreeurl'))
示例#51
0
def editCourse(request,course_id):
    mlogger.debug("Editing the Course  %s ", (course_id,))
    course_id = int(course_id)
    course = Course.objects.get(pk=course_id)
    if request.user.id == course.user.id :
        if request.method == "GET" :
                mlogger.debug("the person who posted the Course is editing")
                form = CourseForm(instance=course,institute=request.institute)            
                return render_to_response("institution/courses/add_course.html",{'form':form,'editmode':True},RequestContext(request))
        elif request.method == "POST":            
                form = CourseForm(request.POST, instance=course,institute=request.institute)
                if form.is_valid() :
                    form.save()
                    create_message(request,"Successfuly  edited the Course")
                    return HttpResponseRedirect(reverse('showcoursesurl'))
                else:
                    return render_to_response("institution/courses/add_course.html",{'form':form,'editmode':True},RequestContext(request))
    else :
        create_message(request,"You are not authorized to edit this job")
        return HttpResponseRedirect(reverse('showcoursesurl'))
示例#52
0
def editQuestion(request, questionno):
    ''' editing a question '''
    questionid = int(questionno)
    question = Question.objects.get(id=questionid)
    originaltags = question.tags
    if request.user.id == question.user.id:
        if request.method == "GET":
            mlogger.debug("the person who posted the question is editing")
            form = QuestionForm(instance=question,
                                initial={
                                    'tags':
                                    ' '.join(
                                        question.tags.values_list('name',
                                                                  flat=True))
                                })
            return render_to_response('askalumini/askquestion.html', {
                'form': form,
                'editmode': True
            }, RequestContext(request))
        elif request.method == "POST":
            form = QuestionForm(request.POST, instance=question)
            if form.is_valid():
                newquestion = form.save(commit=False)
                newquestion.save()
                removeUserTagWeights(originaltags, request.user,
                                     settings.CONTRIBUTION_WEIGHT)
                newquestion.tags = form.cleaned_data['tags']
                #what about tags brother
                assignUserTagWeights(newquestion.tags, request.user,
                                     settings.CONTRIBUTION_WEIGHT)
                create_message(request, "Successfuly edited the event")
                return HttpResponseRedirect(reverse('askaluminiurl'))
            else:
                return render_to_response('askalumini/askquestion.html', {
                    'form': form,
                    'editmode': True
                }, RequestContext(request))

    else:
        create_message(request, "You are not authorized to edit this question")
        return HttpResponseRedirect(reverse('askaluminiurl'))
示例#53
0
def search(request, page=1):
    if request.method == "GET":
        q = request.GET.get("q", "").strip()
        if len(q) < 3:
            create_message(request, "Fraza zbyt któtka")
            return conditional_redirect(request, "/")
        products = Product.published.filter(
            Q(name__icontains=q) | Q(description__icontains=q) | Q(usage__icontains=q) | Q(ingredients__icontains=q)
        )
    else:
        return conditional_redirect(request, "/")
    template = "products/product_search.html"
    return list_detail.object_list(
        request,
        queryset=products,
        paginate_by=PRODUCTS_PER_PAGE,
        page=page,
        allow_empty=True,
        template_name=template,
        extra_context={"phrase": q},
    )
示例#54
0
def editJob(request, jobid):
    jobid = int(jobid)
    job = Job.objects.get(pk=jobid)
    originaltags = job.tags
    if request.user.id == job.postedby.id:
        if request.method == "GET":
            mlogger.debug("the person who posted the job is editing")
            form = JobForm(instance=job,
                           initial={
                               'tags':
                               ' '.join(job.tags.values_list('name',
                                                             flat=True))
                           },
                           user=request.user)
            return render_to_response('jobs/postjob.html', {
                'form': form,
                'editmode': True
            }, RequestContext(request))
        elif request.method == "POST":
            form = JobForm(request.POST, instance=job, user=request.user)
            if form.is_valid():
                newjob = form.save(commit=False)
                newjob.save()
                removeUserTagWeights(originaltags, request.user,
                                     settings.CONTRIBUTION_WEIGHT)
                newjob.tags = form.cleaned_data['tags']
                #what about tags brother
                assignUserTagWeights(newjob.tags, request.user,
                                     settings.CONTRIBUTION_WEIGHT)
                create_message(request, "Successfuly edited your job")
                return HttpResponseRedirect(reverse('displayjoburl'))
            else:
                return render_to_response('jobs/postjob.html', {
                    'form': form,
                    'editmode': True
                }, RequestContext(request))
    else:
        create_message(request, "You are not authorized to edit this job")
        return HttpResponseRedirect(
            reverse('viewjoburl', kwargs={'jobid': job.id}))
示例#55
0
def newLocationForm(request):       
        profile = request.user.get_profile()
        if request.method == "GET" :           
                form = LocationForm()
                return render_to_response("institution/locationform.html",{'form':form},RequestContext(request))
        elif request.method == "POST" :
            form = LocationForm(request.POST)
            if form.is_valid() :            
                up = profile
                up.country =  form.cleaned_data['country']
                up.state = None if len(form.cleaned_data['state'].strip())  <= 0  else  form.cleaned_data['state'].strip()
                up.city = None if len(form.cleaned_data['city'].strip())  <= 0  else  form.cleaned_data['city'].strip() 
                up.address = None if len(form.cleaned_data['address'].strip())  <= 0  else  form.cleaned_data['address'].strip()
                if (int(form.cleaned_data['latitude']) != 0):
                        up.latitude = float(form.cleaned_data['latitude'])
                if (int(form.cleaned_data['longitude']) != 0):        
                    up.longitude = float(form.cleaned_data['longitude'])
                up.save()
                create_message(request,"Added your location")                
                return HttpResponseRedirect(reverse('newprofessionalformurl'))     
            else:
                return render_to_response("institution/locationform.html",{'form':form},RequestContext(request))
示例#56
0
def createEvent(request):
    mlogger.debug("Create new event ..........................")
    if request.method == "GET":
        form = EventForm(user=request.user)
        return render_to_response('events/create_event.html',{'form':form},RequestContext(request))        
    elif request.method == "POST" :
        form = EventForm(request.POST,user=request.user)        
        if form.is_valid() :
            event = form.save(commit=False)
            event.user = request.user
            event.institute = request.institute
            event.save()
            
            event.tags = form.cleaned_data['tags']
            assignUserTagWeights(event.tags,request.user,settings.CONTRIBUTION_WEIGHT)
            
            if event.sendemail is not None :
                emaillist = event.sendemail.getEmailList(request.institute)                
                deliverEmail('event_created_subject.html','event_created.html',{'institute':request.institute,'event':event,'edit':False,'site':settings.SITE_URL},emaillist)
                
            create_message(request,"Succesfully created the event ...............")
            return HttpResponseRedirect(reverse('agendaviewurl'))               
    return render_to_response('events/create_event.html',{'form':form},RequestContext(request))                
示例#57
0
def forgotPassword(request) :   
    mlogger.debug("resetting password")
    if request.method == 'GET' :
        form =  ForgotPasswordForm()
        return render_to_response("institution/forgotpassword.html",{'form':form},RequestContext(request))
    elif request.method == 'POST' :
        form = ForgotPasswordForm(request.POST)
        if form.is_valid() :            
            user = User.objects.get(email=form.cleaned_data['email'])
            #generate new password
            newpassword = UserManager().make_random_password()
            user.set_password(newpassword)
            user.save()
            subject = render_to_string('institution/emails/forgotpassword_subject.html',{'institute':request.institute,'fuser':user}, RequestContext(request))
            message = render_to_string('institution/emails/forgotpassword_message.html',{'institute':request.institute,'password':newpassword,'fuser':user} ,RequestContext(request))            
            mlogger.debug("Subject = %s message = %s " % (subject,message))
            msg = EmailMessage(subject,message, settings.EMAIL_HOST_USER, [user.email])
            msg.content_subtype = "html"
            msg.send(fail_silently=True)       
            create_message(request,"Successfully resetted the password and sent it to your mail")
            return redirect_to_login(next='')                  
        else :
            return render_to_response("institution/forgotpassword.html",{'form':form},RequestContext(request))   
示例#58
0
def register(request):
    if request.user.get_profile().is_active_partner():
        return conditional_redirect(request, reverse('profile'))
    if request.method == 'GET':
        form = RegistrationForm(user=request.user)
    else:
        form = RegistrationForm(request.POST, user=request.user)
        if form.is_valid():
            partner = form.save(commit=False)
            partner.user = request.user
            partner.save()
            create_message(request, _("Registration successfull"))
            subject = "Nowy partner: %s %s" % (partner.user.first_name, partner.user.last_name)
            subject = ''.join(subject.splitlines())
            message = render_to_string('email/new_reseller.html', {
                'partner':partner
            })
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, settings.SHOP_STAFF_EMAILS)
            return conditional_redirect(request, reverse("profile"))
    return render_to_response(
        'resellers/registration.html', {
            'form':form,
            'next': request.REQUEST.get('next', ''),
        }, context_instance=RequestContext(request))