def add_offer(request):
    enterprise = Enterprise.objects.get(pk=request.user.id)
    error = None

    # If the enterprise has closed offers without feedback
    if enterprise.get_closed_offers_without_feedback():
        request.flash[
            'error_message'] = 'No puede crear nuevas ofertas hasta entregar el feedback de las ya cerradas'
        return HttpResponseRedirect(
            reverse('bolsa_trabajo.views_enterprise.offer'))

    if request.method == 'POST':
        form = OfferForm(request.POST)
        if form.is_valid():
            offer = Offer.create_from_form(enterprise, form)
            offer.save()

            UserProfile.notify_staff_of_new_offer()

            request.flash[
                'message'] = 'Oferta propuesta exitosamente, por favor espere a que un encargado la valide'
            url = reverse('bolsa_trabajo.views_account.index')
            return HttpResponseRedirect(url)
    else:
        form = OfferForm()

    return append_user_to_response(request, 'enterprise/add_offer.html', {
        'offer_form': form,
        'error': error
    })
def edit_offer(request, offer_id):
    offer = Offer.objects.get(pk=offer_id)
    enterprise = Enterprise.objects.get(pk=request.user.id)

    # check if user has permission to edit this offer
    if offer.enterprise != enterprise:
        request.flash[
            'error_message'] = 'No tiene permisos para editar esta oferta'
        return redirect('bolsa_trabajo.views_enterprise.offer')

    # check first if offer is closed
    if offer.is_closed():
        request.flash['error_message'] = "No puede editar una oferta cerrada"
        return redirect('bolsa_trabajo.views_enterprise.offer')

    if request.method == 'POST':
        form = OfferForm(request.POST)
        if form.is_valid():
            offer.load_from_form(form)
            offer.save()

            request.flash['message'] = 'Oferta editada exitosamente'
            url = reverse('bolsa_trabajo.views_enterprise.offer_details',
                          args=[offer.id])
            return HttpResponseRedirect(url)
    else:
        form = OfferForm.create_from_offer(offer)

    close_form = OfferStatusForm()

    return append_user_to_response(request, 'enterprise/edit_offer.html', {
        'offer': offer,
        'offer_form': form,
        'close_form': close_form,
    })
def edit_offer(request, offer_id):
    offer = Offer.objects.get(pk=offer_id)
    enterprise = Enterprise.objects.get(pk=request.user.id)

    # check if user has permission to edit this offer
    if offer.enterprise != enterprise:
        request.flash['error_message'] = 'No tiene permisos para editar esta oferta'
        return redirect('bolsa_trabajo.views_enterprise.offer')

    # check first if offer is closed
    if offer.is_closed():
        request.flash['error_message'] = "No puede editar una oferta cerrada"
        return redirect('bolsa_trabajo.views_enterprise.offer')

    if request.method == 'POST':
        form = OfferForm(request.POST)
        if form.is_valid():
            offer.load_from_form(form)
            offer.save()

            request.flash['message'] = 'Oferta editada exitosamente'
            url = reverse('bolsa_trabajo.views_enterprise.offer_details', args=[offer.id])
            return HttpResponseRedirect(url)
    else:
        form = OfferForm.create_from_offer(offer)

    close_form = OfferStatusForm()

    return append_user_to_response(request, 'enterprise/edit_offer.html', {
        'offer': offer,
        'offer_form': form,
        'close_form': close_form,
    })
def add_offer(request):
    enterprise = Enterprise.objects.get(pk=request.user.id)
    error = None

    # If the enterprise has closed offers without feedback
    if enterprise.get_closed_offers_without_feedback():
        request.flash['error_message'] = 'No puede crear nuevas ofertas hasta entregar el feedback de las ya cerradas'
        return HttpResponseRedirect(reverse('bolsa_trabajo.views_enterprise.offer'))

    if request.method == 'POST':
        form = OfferForm(request.POST)
        if form.is_valid():
            offer = Offer.create_from_form(enterprise, form)
            offer.save()

            UserProfile.notify_staff_of_new_offer()

            request.flash['message'] = 'Oferta propuesta exitosamente, por favor espere a que un encargado la valide'
            url = reverse('bolsa_trabajo.views_account.index')
            return HttpResponseRedirect(url)
    else:
        form = OfferForm()

    return append_user_to_response(request, 'enterprise/add_offer.html', {
        'offer_form': form,
        'error': error
    })
Exemple #5
0
def add_offer():
    form = OfferForm()
    if form.validate_on_submit():
        offer = Offer.query.filter_by(name=form.name.data).first()
        if not offer:
            db_session.add(
                Offer(form.name.data, form.cost.data, form.description.data,
                      form.capacity.data))
            db_session.commit()
        return redirect('/all_abonements')
    return render_template('add_offer.html', form=form)
Exemple #6
0
def offer_post(request):
    if request.method == "POST":
        form = OfferForm(request.POST)

        if form.is_valid():
            redirect_to = resolve_url('/partime/manage/')
            user = get_user(request)
            form.save(user)
            return HttpResponseRedirect(redirect_to)
    else:
        form = OfferForm()
    return render(request, 'partime/offer/offer_post.html', {'form': form, 'url': 'partime:offer_post'})
Exemple #7
0
def offer_update(request, id):
    user = get_user(request)
    user_info = get_user_info(user)
    instance = get_object_or_404(Offer, id=id, employer=user_info)
    if request.method == "POST":
        form = OfferForm(request.POST, instance=instance)

        if form.is_valid():
            redirect_to = resolve_url('/partime/manage/')
            form.save()
            return HttpResponseRedirect(redirect_to)
    else:
        form = OfferForm(instance=instance)
    return render(request, 'partime/offer/offer_post.html', {'form': form, 'url': 'partime:offer_update', 'id': id})
Exemple #8
0
 def get(self, offer_id=None, **kwargs):
     """Return an offer to edit or an empty form to create"""
     template = 'admin/daily/new.html'
     files = get_files()
     context = {
         'form': self.form,
         'files': files,
     }
     # render edit
     if offer_id is not None:
         offer = Offer.get_by_id(offer_id)
         offer_photo = ''
         if offer.photo:
             offer_photo = offer.photo.key().id()
         if offer:
             self.form = OfferForm(obj=offer)
             context.update({ 'form': self.form, 'offer_photo': offer_photo })
             template = 'admin/daily/edit.html'
         else:
             return redirect('admin/daily/')
     # render new
     return self.render_response(template, **context)
Exemple #9
0
class OfferHandler(BaseHandler):
    """Manage individual blog posts"""
    @admin_required
    def get(self, offer_id=None, **kwargs):
        """Return an offer to edit or an empty form to create"""
        template = 'admin/daily/new.html'
        files = get_files()
        context = {
            'form': self.form,
            'files': files,
        }
        # render edit
        if offer_id is not None:
            offer = Offer.get_by_id(offer_id)
            offer_photo = ''
            if offer.photo:
                offer_photo = offer.photo.key().id()
            if offer:
                self.form = OfferForm(obj=offer)
                context.update({ 'form': self.form, 'offer_photo': offer_photo })
                template = 'admin/daily/edit.html'
            else:
                return redirect('admin/daily/')
        # render new
        return self.render_response(template, **context)
    
    @admin_required
    def post(self, offer_id=None, **kwargs):
        """Handle submitted form data"""
        photo = self.request.form.get('photo') or None
        if photo:
            photo = File.get_by_id(int(photo))
        # validate form
        if self.form.validate():
            title = self.form.title.data
            intro = self.form.intro.data
            content = self.form.content.data
            promoted = self.form.promoted.data
            live = self.form.live.data
            language = self.form.language.data
            
            if offer_id:
                offer = Offer.get_by_id(offer_id)
                offer.title = title
                offer.intro = intro
                offer.content = content
                offer.live = live
                offer.promoted = promoted
                offer.language = language
                offer.photo = photo
            # creating new
            else:
                offer = Offer(title=title, intro=intro, content=content, live=live, promoted=promoted, language=language, photo=photo)
            if offer.put():
                return redirect('admin/daily')
        return self.get(**kwargs)
    
    @cached_property
    def form(self):
        """Form instance as cached_property"""
        return OfferForm(self.request)