Beispiel #1
0
def misc(request):
    if 'action' in request.GET:
        action = request.GET['action']
        if action =='markread':
            user = request.user
            PostTracking.objects.filter(user__id=user.id).update(last_read=datetime.now(), topics=None)
            return HttpResponseRedirect(reverse('djangobb:index'))

        elif action == 'report':
            if request.GET.get('post_id', ''):
                post_id = request.GET['post_id']
                post = get_object_or_404(Post, id=post_id)
                form = build_form(ReportForm, request, reported_by=request.user, post=post_id)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                    return HttpResponseRedirect(post.get_absolute_url())
                return {'form':form}

    elif 'submit' in request.POST and 'mail_to' in request.GET:
        form = MailToForm(request.POST)

        if form.is_valid():
            user = get_object_or_404(User, username=request.GET['mail_to'])
            subject = form.cleaned_data['subject']
            body = form.cleaned_data['body'] + '\n %s %s [%s]' % (Site.objects.get_current().domain,
                                                                  request.user.username,
                                                                  request.user.email)
            # user.email_user(subject, body, request.user.email)
            ###sending the email with postmark
            data = {'sender': request.user.get_full_name(),
                    'recipient': user.get_full_name(),
                    'subject': form.cleaned_data['subject'],
                    'body': form.cleaned_data['body'],
                    'email': user.email,
                    'mydomain': Site.objects.get(id=1).domain,
                    'encryptedUsername': urlsafe_b64encode(str(user.id)),
                    }
            if user.get_profile().idioma == u'es':
                subject = u'Tienes un mensaje nuevo'
                template = 'foro-email_es.html'
            else:
                subject = u'You have a new message'
                template = 'foro-email_en.html'
            
            if user.get_profile().accept_email_updates:             
                sendHtmlMail("*****@*****.**", subject,template,
                             data,user.email,form.cleaned_data['body'], 'forum/email-templates/')
            #################################
            #aumentando en 1 el puntaje del usuario que envio el mail
            request.user.get_profile().add_points(1)
            ##########################
            return HttpResponseRedirect(reverse('djangobb:index'))

    elif 'mail_to' in request.GET:
        mailto = get_object_or_404(User, username=request.GET['mail_to'])
        form = MailToForm()
        return {'form':form,
                'mailto': mailto,
               'TEMPLATE': 'forum/mail_to.html'
               }
Beispiel #2
0
    def save(self, *args, **kwargs):
        """
        Método para guardar un servicio, cuando este es moderado se manda el
        correo electrónico de confirmación
        """
        if self.estado == u"A":
            admin = get_object_or_none(AdministradorServicio, servicio=self)
            if admin:
                sendHtmlMail("*****@*****.**",
                             _(u"Confirm registration in MP100"),
                             "ser_confirmacion_mail_%s.html" % admin.idioma,
                             {"nombre": self.nombre,
                              "clave": admin.clave_activacion,
                              "sitio": Site.objects.get_current(),
                              "email": admin.user.email},
                             admin.user.email,
                             path="servicios/email_templates/")

        super(Servicio, self).save(*args, **kwargs)

        if self.estado == u"R":
            Servicio.objects.get(id=self.id).delete()
Beispiel #3
0
    def save(self, *args, **kwargs):
        """
        Método para guardar un servicio, cuando este es moderado se manda el
        correo electrónico de confirmación
        """
        if self.estado == u"A":
            admin = get_object_or_none(AdministradorServicio, servicio=self)
            if admin:
                sendHtmlMail("*****@*****.**",
                             _(u"Confirm registration in MP100"),
                             "ser_confirmacion_mail_%s.html" % admin.idioma, {
                                 "nombre": self.nombre,
                                 "clave": admin.clave_activacion,
                                 "sitio": Site.objects.get_current(),
                                 "email": admin.user.email
                             },
                             admin.user.email,
                             path="servicios/email_templates/")

        super(Servicio, self).save(*args, **kwargs)

        if self.estado == u"R":
            Servicio.objects.get(id=self.id).delete()
Beispiel #4
0
def ser_perfil_publico(request, id_servicio):
    """
    Muestra el perfil público de alguno de los servicios donde se puede puntuar
    el servicio y dejar opiniones
    """
    servicio = get_object_or_404(Servicio, id=id_servicio, estado=u"A")
    opiniones = Opinion.objects.filter(servicio=servicio, moderado=True)
    destacados = Servicio.accepted.filter(destacado=True).order_by("?")[:5]
    puntaje = Puntaje.get_or_none(servicio, request.user)
    comentado = False
    msg_enviado = False
    if request.method == "POST":
        if "opinion" in request.POST:
            opinion_form = OpinionForm(request.POST)
            puntuacion_form = PuntajeForm(request.POST, instance=puntaje)
            if opinion_form.is_valid() and puntuacion_form.is_valid(
            ) or not puntuacion_form:
                Opinion.save_form(opinion_form, servicio, request.user)
                Puntaje.save_form(puntuacion_form, servicio, request.user,
                                  puntaje)
                opinion_form = OpinionForm()
                puntuacion_form = PuntajeForm(instance=puntaje)
                request.user.get_profile().add_points(5)
            if AdministradorServicio.objects.filter(
                    servicio=servicio).exists():
                contacto_form = ContactoForm()
            else:
                contacto_form = None
            comentado = True

        elif "contacto" in request.POST:
            contacto_form = ContactoForm(request.POST)
            if contacto_form.is_valid():
                sendHtmlMail(
                    "*****@*****.**",
                    u"You've received a contact request",
                    "ser_contacto_mail_%s.html" %
                    servicio.administradorservicio.idioma, {
                        "datos": contacto_form.cleaned_data,
                        "nombre_sitio": Site.objects.get_current().domain,
                        "email": servicio.administradorservicio.user.email,
                    },
                    servicio.administradorservicio.user.email,
                    path="servicios/email_templates/")
                msg_enviado = True
                contacto_form = ContactoForm()
                request.user.get_profile().add_points(5)
            opinion_form = OpinionForm()
            puntuacion_form = PuntajeForm()
    else:
        servicio.add_vista(request)
        opinion_form = OpinionForm()
        puntuacion_form = PuntajeForm(instance=puntaje)
        if AdministradorServicio.objects.filter(servicio=servicio).exists():
            contacto_form = ContactoForm()
        else:
            contacto_form = None

    return direct_response(
        request, "servicios/ser_perfil_publico.html", {
            "servicio": servicio,
            "galeria": Foto.objects.filter(servicio=servicio, moderado=True),
            "caracteristicas": servicio.caracteristicas.all(),
            "opiniones": get_paginated(request, opiniones, 4),
            "destacados": destacados,
            "resultados": Servicio.get_search(request.session)[:3],
            "opinion_form": opinion_form,
            "puntuacion_form": puntuacion_form,
            "contacto_form": contacto_form,
            "msg_enviado": msg_enviado,
            "comentado": comentado,
            "fans": servicio.get_fans()
        })
Beispiel #5
0
def ser_inicio(request):
    """
    Muestra la página de inicio de servicios y procesa búsquedas de servicios,
    login de administradores de servicio y registro de nuevos servicios por
    parte de los usuarios
    """
    html_captcha = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY)
    captcha_error = None

    if request.method == "POST":
        if "login" in request.POST:
            login_form = LoginForm(request.POST)
            if login_form.is_valid():
                user = authenticate(
                    username=login_form.cleaned_data['email'],
                    password=login_form.cleaned_data['contrasena'])
                if user is not None:
                    if user.is_active:
                        login(request, user)
                        admin = AdministradorServicio.objects.get(user=user)
                        request.session['django_language'] = admin.idioma
                        translation.activate(admin.idioma)

                        return HttpResponseRedirect(
                            reverse("ser_perfil_privado"))
                    else:
                        login_form.errors["email"] = [
                            _(u"Your user account has not been \
                                                        activated, check your e-mail"
                              )
                        ]
                else:
                    login_form.errors["email"] = [
                        _(u"Your username or password is incorrect")
                    ]
            busqueda_form = BusquedaForm()
            nuevo_servicio_form = ServicioPublicoForm()
            ubicacion_form = UbicacionForm()
            recuperar_form = RecuperarForm()

        elif "nuevo_servicio" in request.POST:
            check_captcha = captcha.submit(
                request.POST['recaptcha_challenge_field'],
                request.POST['recaptcha_response_field'],
                settings.RECAPTCHA_PRIVATE_KEY, request.META['REMOTE_ADDR'])
            if check_captcha.is_valid is False:
                captcha_error = _(u"Written words are incorrect")
            ###begin escape for django' tests
            if settings.DEBUG == False and 'appTest' in request.POST:
                captcha_error = None
            ###end escape for django' tests
            nuevo_servicio_form = ServicioPublicoForm(request.POST,
                                                      request.FILES)
            ubicacion_form = UbicacionForm(request.POST)
            if nuevo_servicio_form.is_valid() and ubicacion_form.is_valid(
            ) and not captcha_error:
                servicio = Servicio.save_form(nuevo_servicio_form,
                                              ubicacion_form,
                                              estado=u"A")

                Actividad.register(u"R", servicio)
                nuevo_servicio_form = ServicioPublicoForm()
                ubicacion_form = UbicacionForm()
            busqueda_form = BusquedaForm()
            login_form = LoginForm()
            recuperar_form = RecuperarForm()

        elif "recuperar" in request.POST:
            recuperar_form = RecuperarForm(request.POST)
            if recuperar_form.is_valid():
                try:
                    usuario = AdministradorServicio.objects.get(
                        user__email=recuperar_form.cleaned_data['email'])
                    sendHtmlMail("*****@*****.**",
                                 _(u"New password for Machu Picchu 100"),
                                 "ser_recuperar_mail_%s.html" % usuario.idioma,
                                 {
                                     "usuario": usuario,
                                     "password": make_password(),
                                     "sitio": Site.objects.get_current()
                                 },
                                 recuperar_form.cleaned_data['email'],
                                 path="servicios/email_templates/")
                except AdministradorServicio.DoesNotExist:
                    recuperar_form.errors["email"] = [
                        _(u"The e-mail account does not \
                                                      belong to any registered manager"
                          )
                    ]
            login_form = LoginForm()
            nuevo_servicio_form = ServicioPublicoForm()
            ubicacion_form = UbicacionForm()
            busqueda_form = BusquedaForm()
    else:
        busqueda_form = BusquedaForm()
        login_form = LoginForm()
        nuevo_servicio_form = ServicioPublicoForm()
        ubicacion_form = UbicacionForm()
        recuperar_form = RecuperarForm()

    return direct_response(
        request, "servicios/ser_inicio.html", {
            "busqueda_form": busqueda_form,
            "login_form": login_form,
            "nuevo_servicio_form": nuevo_servicio_form,
            "html_captcha": html_captcha,
            "captcha_error": captcha_error,
            "ubicacion_form": ubicacion_form,
            "recuperar_form": recuperar_form,
            "actividades": get_paginated(request, Actividad.objects.all(), 5),
            "destacados":
            Servicio.objects.filter(destacado=True).order_by('?')[:3],
            "valorados": Servicio.objects.all().order_by('-puntuacion')[:3],
            "ubicaciones_comunes": UbicacionComun.objects.all()
        })
Beispiel #6
0
def ser_registro(request):
    """
    Muestra el formulario de registro para un nuevo servicio, envía un email de
    confirmación al cliente para validar la cuenta
    """
    html_captcha = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY)
    ser_captcha_error = None

    if request.method == "POST":
        if request.POST['instance']:
            servicio_id = request.POST['instance']
            if AdministradorServicio.objects.filter(
                    servicio__id=servicio_id).exists():
                return HttpResponseRedirect(reverse('ser_registro'))
            else:
                servicio_instance = Servicio.accepted.get(id=servicio_id)
                form_registro = ServicioPrivadoForm(request.POST,
                                                    request.FILES,
                                                    instance=servicio_instance)
                form_ubicacion = UbicacionForm(
                    request.POST, instance=servicio_instance.ubicacion)
        else:
            form_registro = ServicioPrivadoForm(request.POST, request.FILES)
            form_ubicacion = UbicacionForm(request.POST)
        check_captcha = captcha.submit(
            request.POST['recaptcha_challenge_field'],
            request.POST['recaptcha_response_field'],
            settings.RECAPTCHA_PRIVATE_KEY, request.META['REMOTE_ADDR'])
        if check_captcha.is_valid is False:
            ser_captcha_error = _(u"Written words are incorrect")
        ###begin escape for django' tests
        if settings.DEBUG == False and 'appTest' in request.POST:
            ser_captcha_error = None
        ###end escape for django' tests
        if form_registro.is_valid() and form_ubicacion.is_valid(
        ) and not ser_captcha_error:
            servicio = Servicio.save_form(form_registro, form_ubicacion)
            admin = AdministradorServicio.save_form(form_registro, servicio)
            sendHtmlMail("*****@*****.**",
                         _(u"Manager registration in MP100"),
                         "ser_regadmin_mail_%s.html" % admin.idioma, {
                             "nombre": servicio.nombre,
                             "sitio": Site.objects.get_current(),
                             "email": form_registro.cleaned_data['email']
                         },
                         form_registro.cleaned_data['email'],
                         path="servicios/email_templates/")

            return direct_response(request, "servicios/ser_confirmacion.html")
    else:

        form_registro = ServicioPrivadoForm()
        form_ubicacion = UbicacionForm()

    return direct_response(
        request, "servicios/ser_registro.html", {
            "form_registro": form_registro,
            "form_ubicacion": form_ubicacion,
            "html_captcha": html_captcha,
            "ser_captcha_error": ser_captcha_error
        })
Beispiel #7
0
def misc(request):
    if 'action' in request.GET:
        action = request.GET['action']
        if action == 'markread':
            user = request.user
            PostTracking.objects.filter(user__id=user.id).update(
                last_read=datetime.now(), topics=None)
            return HttpResponseRedirect(reverse('djangobb:index'))

        elif action == 'report':
            if request.GET.get('post_id', ''):
                post_id = request.GET['post_id']
                post = get_object_or_404(Post, id=post_id)
                form = build_form(ReportForm,
                                  request,
                                  reported_by=request.user,
                                  post=post_id)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                    return HttpResponseRedirect(post.get_absolute_url())
                return {'form': form}

    elif 'submit' in request.POST and 'mail_to' in request.GET:
        form = MailToForm(request.POST)

        if form.is_valid():
            user = get_object_or_404(User, username=request.GET['mail_to'])
            subject = form.cleaned_data['subject']
            body = form.cleaned_data['body'] + '\n %s %s [%s]' % (
                Site.objects.get_current().domain, request.user.username,
                request.user.email)
            # user.email_user(subject, body, request.user.email)
            ###sending the email with postmark
            data = {
                'sender': request.user.get_full_name(),
                'recipient': user.get_full_name(),
                'subject': form.cleaned_data['subject'],
                'body': form.cleaned_data['body'],
                'email': user.email,
                'mydomain': Site.objects.get(id=1).domain,
                'encryptedUsername': urlsafe_b64encode(str(user.id)),
            }
            if user.get_profile().idioma == u'es':
                subject = u'Tienes un mensaje nuevo'
                template = 'foro-email_es.html'
            else:
                subject = u'You have a new message'
                template = 'foro-email_en.html'

            if user.get_profile().accept_email_updates:
                sendHtmlMail("*****@*****.**", subject, template,
                             data, user.email, form.cleaned_data['body'],
                             'forum/email-templates/')
            #################################
            #aumentando en 1 el puntaje del usuario que envio el mail
            request.user.get_profile().add_points(1)
            ##########################
            return HttpResponseRedirect(reverse('djangobb:index'))

    elif 'mail_to' in request.GET:
        mailto = get_object_or_404(User, username=request.GET['mail_to'])
        form = MailToForm()
        return {
            'form': form,
            'mailto': mailto,
            'TEMPLATE': 'forum/mail_to.html'
        }