Beispiel #1
0
def add_offer(request):
    is_young=is_young_check(request)
    is_principal=is_principal_check(request)
    
    principal = PrincipalInvestigator.objects.filter(user_id=request.user.id)
    if len(principal)!=0:
        prin=principal[0]
    
    if request.method=='POST':
        formulario = OfferForm(request.POST)
        keywords=KeywordsForm(request.POST)
        if formulario.is_valid() and keywords.is_valid():
              
            ##Creacion de la oferta
#                title=models.CharField(max_length=140)
#                 description=models.CharField(max_length=3000)
#                 deadline=models.DateField()
#                 publication_date=models.DateField()
#                 keywords=models.ManyToManyField(Keyword)
#                 principal=models.ForeignKey(PrincipalInvestigator, on_delete=models.CASCADE)

            offer_inst=Offer.objects.create(
                              principal=prin,
                              title=formulario.cleaned_data['title'],
                              description=formulario.cleaned_data['description'],
                              deadline=formulario.cleaned_data['deadline'],
                              publication_date=datetime.now(),
                              )
            
            #Keywords
            key_for_offer=""
            keywords=keywords.cleaned_data['word']
            if keywords!=None: 
            #la separamos por comas y eliminamos la ultima tupla si estaa vacia
                key_vector=keywords.split(",")
                if (key_vector[len(key_vector)-1].strip()==''):
                    key_vector.pop()
                
                if len(key_vector)!=0:
                    #linkeamos todas las keys con su oferta y le hacemos strip para quitarle espacios en blanco a izq y der
                    for keyword in key_vector:
                        key = keyword.strip()
                        if key!='' or key!=None:
                            Keyword.objects.create(word=key.capitalize(),offer=offer_inst)
                            key_for_offer+=key.capitalize()+","
                    #capitalize() strip(' '), .split(", ")
            offer_inst.keywords=key_for_offer[:len(key_for_offer)-1]
            offer_inst.save()
            
            ###por aqui
            return HttpResponseRedirect('list')
            
    else:
        formulario = OfferForm()
        keywords=KeywordsForm(request.POST)

    
    return render_to_response('offer/create.html',
                              {'formulario':formulario,'keywords':keywords,
                               'is_young':is_young,'is_principal':is_principal,},
                              context_instance = RequestContext(request))
Beispiel #2
0
def add_offer(request):
    is_young = is_young_check(request)
    is_principal = is_principal_check(request)

    principal = PrincipalInvestigator.objects.filter(user_id=request.user.id)
    if len(principal) != 0:
        prin = principal[0]

    if request.method == 'POST':
        formulario = OfferForm(request.POST)
        keywords = KeywordsForm(request.POST)
        if formulario.is_valid() and keywords.is_valid():

            ##Creacion de la oferta
            #                title=models.CharField(max_length=140)
            #                 description=models.CharField(max_length=3000)
            #                 deadline=models.DateField()
            #                 publication_date=models.DateField()
            #                 keywords=models.ManyToManyField(Keyword)
            #                 principal=models.ForeignKey(PrincipalInvestigator, on_delete=models.CASCADE)

            offer_inst = Offer.objects.create(
                principal=prin,
                title=formulario.cleaned_data['title'],
                description=formulario.cleaned_data['description'],
                deadline=formulario.cleaned_data['deadline'],
                publication_date=datetime.now(),
            )

            #Keywords
            key_for_offer = ""
            keywords = keywords.cleaned_data['word']
            if keywords != None:
                #la separamos por comas y eliminamos la ultima tupla si estaa vacia
                key_vector = keywords.split(",")
                if (key_vector[len(key_vector) - 1].strip() == ''):
                    key_vector.pop()

                if len(key_vector) != 0:
                    #linkeamos todas las keys con su oferta y le hacemos strip para quitarle espacios en blanco a izq y der
                    for keyword in key_vector:
                        key = keyword.strip()
                        if key != '' or key != None:
                            Keyword.objects.create(word=key.capitalize(),
                                                   offer=offer_inst)
                            key_for_offer += key.capitalize() + ","
                    #capitalize() strip(' '), .split(", ")
            offer_inst.keywords = key_for_offer[:len(key_for_offer) - 1]
            offer_inst.save()

            ###por aqui
            return HttpResponseRedirect('list')

    else:
        formulario = OfferForm()
        keywords = KeywordsForm(request.POST)

    return render_to_response('offer/create.html', {
        'formulario': formulario,
        'keywords': keywords,
        'is_young': is_young,
        'is_principal': is_principal,
    },
                              context_instance=RequestContext(request))
Beispiel #3
0
def view_profile(request):
    is_young=is_young_check(request)
    is_principal=is_principal_check(request)
    
    try:
        users = YoungInvestigator.objects.get(user_id__exact=request.user.id)
        keywords=Keyword.objects.filter(young=users)
        offers=[]

    except:
        users = PrincipalInvestigator.objects.get(user_id__exact=request.user.id)
        keywords=Keyword.objects.filter(principal=users)
        a=datetime.now()
        offers=Offer.objects.filter(principal=users, deadline__gt=a)
    

    if request.method=='POST':
        if(is_young):
            users_form=YoungInvestigatorForm(request.POST)
        else:
            users_form=PrincipalInvestigatorForm(request.POST)
        keywords_form = KeywordsForm(request.POST)
        if (keywords_form.is_valid()):
            if(is_young):
                Keyword.objects.create(young=users,word=keywords_form.cleaned_data['word'])
                
            elif(is_principal):
                Keyword.objects.create(principal=users,word=keywords_form.cleaned_data['word'])
                
                
        if  users_form.is_valid():
                
            if is_young:
            #                 'telephone','title','specialty','research_field','research_speciality','h_index','country','city',
#                 'facebook_link','twitter_link','linkedIn_link','principal_text','other_text'                
                users.telephone=users_form.cleaned_data['telephone']
                users.title=users_form.cleaned_data['title']
                users.specialty=users_form.cleaned_data['specialty']
                users.research_field=users_form.cleaned_data['research_field']
                users.research_speciality=users_form.cleaned_data['research_speciality']
                users.h_index=users_form.cleaned_data['h_index']
                users.country=users_form.cleaned_data['country']
                users.city=users_form.cleaned_data['city']
                users.facebook_link=users_form.cleaned_data['facebook_link']
                users.twitter_link=users_form.cleaned_data['twitter_link']
                users.linkedIn_link=users_form.cleaned_data['linkedIn_link']
                users.principal_text=users_form.cleaned_data['principal_text']
                users.other_text=users_form.cleaned_data['other_text']
                users.save()
            elif(is_principal):
#                 'telephone','research_field','research_speciality','h_index','country','city','facebook_link',
#                   'twitter_link','linkedIn_link','principal_text','other_text','number_of_authorisating'
#                   ,'interested_in_premium'
                users.telephone=users_form.cleaned_data['telephone']
                users.research_field=users_form.cleaned_data['research_field']
                users.research_speciality=users_form.cleaned_data['research_speciality']
                users.h_index=users_form.cleaned_data['h_index']
                users.country=users_form.cleaned_data['country']
                users.city=users_form.cleaned_data['city']
                users.facebook_link=users_form.cleaned_data['facebook_link']
                users.twitter_link=users_form.cleaned_data['twitter_link']
                users.linkedIn_link=users_form.cleaned_data['linkedIn_link']
                users.principal_text=users_form.cleaned_data['principal_text']
                users.other_text=users_form.cleaned_data['other_text']
                users.number_of_authorisating=users_form.cleaned_data['number_of_authorisating']
                users.interested_in_premium=users_form.cleaned_data['interested_in_premium']
                users.save()
            
                

    keywords_form = KeywordsForm()
    if(is_young):
        users_form=YoungInvestigatorForm(instance=users)
    else:
        users_form=PrincipalInvestigatorForm(instance=users)
        
    return render_to_response('users/profile.html',
                              {'users':users,'is_young':is_young,'is_principal':is_principal,
                               'keywords_form':keywords_form,'keywords':keywords,'users_form':users_form,
                               'offers':offers,},
                              context_instance = RequestContext(request))
Beispiel #4
0
def view_profile(request):
    is_young = is_young_check(request)
    is_principal = is_principal_check(request)

    try:
        users = YoungInvestigator.objects.get(user_id__exact=request.user.id)
        keywords = Keyword.objects.filter(young=users)
        offers = []

    except:
        users = PrincipalInvestigator.objects.get(
            user_id__exact=request.user.id)
        keywords = Keyword.objects.filter(principal=users)
        a = datetime.now()
        offers = Offer.objects.filter(principal=users, deadline__gt=a)

    if request.method == 'POST':
        if (is_young):
            users_form = YoungInvestigatorForm(request.POST)
        else:
            users_form = PrincipalInvestigatorForm(request.POST)
        keywords_form = KeywordsForm(request.POST)
        if (keywords_form.is_valid()):
            if (is_young):
                Keyword.objects.create(young=users,
                                       word=keywords_form.cleaned_data['word'])

            elif (is_principal):
                Keyword.objects.create(principal=users,
                                       word=keywords_form.cleaned_data['word'])

        if users_form.is_valid():

            if is_young:
                #                 'telephone','title','specialty','research_field','research_speciality','h_index','country','city',
                #                 'facebook_link','twitter_link','linkedIn_link','principal_text','other_text'
                users.telephone = users_form.cleaned_data['telephone']
                users.title = users_form.cleaned_data['title']
                users.specialty = users_form.cleaned_data['specialty']
                users.research_field = users_form.cleaned_data[
                    'research_field']
                users.research_speciality = users_form.cleaned_data[
                    'research_speciality']
                users.h_index = users_form.cleaned_data['h_index']
                users.country = users_form.cleaned_data['country']
                users.city = users_form.cleaned_data['city']
                users.facebook_link = users_form.cleaned_data['facebook_link']
                users.twitter_link = users_form.cleaned_data['twitter_link']
                users.linkedIn_link = users_form.cleaned_data['linkedIn_link']
                users.principal_text = users_form.cleaned_data[
                    'principal_text']
                users.other_text = users_form.cleaned_data['other_text']
                users.save()
            elif (is_principal):
                #                 'telephone','research_field','research_speciality','h_index','country','city','facebook_link',
                #                   'twitter_link','linkedIn_link','principal_text','other_text','number_of_authorisating'
                #                   ,'interested_in_premium'
                users.telephone = users_form.cleaned_data['telephone']
                users.research_field = users_form.cleaned_data[
                    'research_field']
                users.research_speciality = users_form.cleaned_data[
                    'research_speciality']
                users.h_index = users_form.cleaned_data['h_index']
                users.country = users_form.cleaned_data['country']
                users.city = users_form.cleaned_data['city']
                users.facebook_link = users_form.cleaned_data['facebook_link']
                users.twitter_link = users_form.cleaned_data['twitter_link']
                users.linkedIn_link = users_form.cleaned_data['linkedIn_link']
                users.principal_text = users_form.cleaned_data[
                    'principal_text']
                users.other_text = users_form.cleaned_data['other_text']
                users.number_of_authorisating = users_form.cleaned_data[
                    'number_of_authorisating']
                users.interested_in_premium = users_form.cleaned_data[
                    'interested_in_premium']
                users.save()

    keywords_form = KeywordsForm()
    if (is_young):
        users_form = YoungInvestigatorForm(instance=users)
    else:
        users_form = PrincipalInvestigatorForm(instance=users)

    return render_to_response('users/profile.html', {
        'users': users,
        'is_young': is_young,
        'is_principal': is_principal,
        'keywords_form': keywords_form,
        'keywords': keywords,
        'users_form': users_form,
        'offers': offers,
    },
                              context_instance=RequestContext(request))