def gallery_sheets_view(request, id_directory): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### directory = '' message = '' msg_error = '' form_sent = False today = datetime.now() if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) d = Directory.objects.get(pk=id_directory) points = PointByScore(request) pais_actual = Country.objects.all().get(id_country=country_id) # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) items = MultiuploaderImage.objects.all() #logger = logging.getLogger('my_app_name.my_new_module') #logger.debug('Hello logs!') ctx = { 'points': points, 'id_directory': id_directory, 'items': items, 'form_sent': form_sent, 'state': state_id, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, 'message': message, 'msg_error': msg_error, } return render_to_response('accounts/sheets/gallery.html', ctx, context_instance=RequestContext(request))
def view_dashboard_view(request): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 points = 0 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) category = Category.objects.all().filter(status=True, type=1).order_by('title') message = '' user = '' profile = '' if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) else: return HttpResponseRedirect('/') # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'list_user': user, 'list_profile': profile, 'message': message, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('accounts/dashboard.html', ctx, context_instance=RequestContext(request)) return response
def whois_set_view(request): content = '' if request.POST: form = WhoisForm(request.POST) if form.is_valid(): country = form.cleaned_data['Country'] language = form.cleaned_data['Language'] state = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90*24*60*60 # 3 meses (90 días) #max_age = 365*24*60*60 # 1 año #expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=max_age), "%a, %d-%b-%Y %H:%M:%S GMT") ''' response = HttpResponse() response.set_cookie("gm_state", state) response.set_cookie("gm_country", country.id_country) response.set_cookie("gm_language", language) response.set_cookie('gm_country', country.id_country, max_age=max_age, expires=today, path='/', domain=None, secure=None, httponly=False) response.set_cookie('gm_state', state, max_age=max_age, expires=today, path='/', domain=None, secure=None, httponly=False) response.set_cookie('gm_language', language, max_age=max_age, expires=today, path='/', domain=None, secure=None, httponly=False) ''' ctx = { 'content': 0, } response = render_to_response('functions/content.html', ctx, context_instance=RequestContext(request)) response.set_cookie("gm_state", state) response.set_cookie("gm_country", country.id_country) response.set_cookie("gm_language", language) return response '''
def affiliate_view(request): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 points = 0 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) state_id = profile.state_id country_id = profile.country_id language_id = profile.language_id today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) content = Content.objects.get(url_name='affiliate') # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) list_package = Package.objects.filter(status=True).order_by('order') ctx = { 'points': points, 'list_package': list_package, 'content': content, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('home/affiliate.html', ctx, context_instance=RequestContext(request)) return response
def faq_view(request): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 points = 0 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) state_id = profile.state_id country_id = profile.country_id language_id = profile.language_id today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('home/faq.html', ctx, context_instance=RequestContext(request)) return response
def directory_view(request, url_name): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 logged = False points = 0 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) logged = True points = PointByScore(request) today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) category = Category.objects.all().filter( status=True, type=1, directory__isnull=False, directory__country_id=country_id, directory__deleted=False, directory__status=True).order_by('title').distinct() try: directory_detail = Directory.objects.get(url_name=url_name, deleted=False) directory_service = directory_detail.service.all() directory_payment = directory_detail.payment.all() directory_style = directory_detail.style.all() directory_category = directory_detail.category.all() galery = MultiuploaderImage.objects.all().filter( directory_id=directory_detail.id_directory) try: stat = Stat.objects.get(directory_id=directory_detail.id_directory, date=datetime.now().replace(tzinfo=utc)) stat.count = int(stat.count) + int(1) except Stat.DoesNotExist: stat = Stat() stat.directory_id = directory_detail.id_directory stat.date = datetime.now().replace(tzinfo=utc) stat.count = 1 stat.save() form_reserve_sent = False form_comment_sent = False # crear una reservación if "reserve" in request.POST: form_reserve = ReserveForm(request.POST) if form_reserve.is_valid(): form_reserve_sent = True nombre = form_reserve.cleaned_data['name'] email_to_user = form_reserve.cleaned_data['email'] telefono = form_reserve.cleaned_data['phone'] fecha = form_reserve.cleaned_data['date'] hora = form_reserve.cleaned_data['time'] description = form_reserve.cleaned_data['description'] add_reserve = form_reserve.save(commit=False) add_reserve.directory = directory_detail if logged: add_reserve.user = user add_reserve.date_create = datetime.now().replace(tzinfo=utc) add_reserve.date_update = datetime.now().replace(tzinfo=utc) add_reserve.save() #enviar Email email_from = settings.EMAIL_FROM email_to = email_to_user subject = 'ZoneTable - Reserva en línea' page_url = 'reserve_online.html' content = '<p>Hola :</p>' content += '<p><strong>Le enviamos los detalles de la Reservación.</strong></p>' content += '<p></p>' content += '<p>Lugar: <strong>%s</strong> (<a href="%s">Ver Lugar</a>)</p>' % ( directory_detail.title, settings.URL_SITE + directory_detail.url_name) content += '<p>Nombre: %s</p>' % (nombre) content += '<p>Email: %s</p>' % (email_to_user) content += '<p>Teléfono: %s</p>' % (telefono) content += '<p>Fecha: %s</p>' % (fecha) content += '<p>Hora: %s</p>' % (hora) content += '<p>Descripción: %s</p>' % (description) content += '<br />' content += '<p>Te esperamos,</p>' send_mail(email_from, email_to, subject, content, page_url, headers=None) #enviar Email email_from = settings.EMAIL_FROM email_to = directory_detail.email subject = 'ZoneTable - Reserva en línea' page_url = 'reserve_online.html' content = '<p>Hola :</p>' content += '<p>Haz recibido una nueva reservación.</p>' content += '<p>Lugar: <strong>%s</strong> (<a href="%s">Ver Lugar</a>)</p>' % ( directory_detail.title, settings.URL_SITE + directory_detail.url_name) content += '<p></p>' content += '<p><strong>Detalles del comensal:</strong></p>' content += '<p>Nombre: %s</p>' % (nombre) content += '<p>Email: %s</p>' % (email_to_user) content += '<p>Teléfono: %s</p>' % (telefono) content += '<p>Fecha: %s</p>' % (fecha) content += '<p>Hora: %s</p>' % (hora) content += '<p>Descripción: %s</p>' % (description) content += '<br />' content += '<p>No olvides mantener actualizado tu establecimiento.</p>' send_mail(email_from, email_to, subject, content, page_url, headers=None) else: initial = '' if logged: initial = { 'name': user.first_name + ' ' + user.last_name, 'email': user.email, 'address': profile.address, 'phone': profile.phone, } form_reserve = ReserveForm(initial=initial) # crear un comentario if 'comment0' in request.POST: form_comment = CommentForm(request.POST) if form_comment.is_valid(): form_comment_sent = True add_comment = form_comment.save(commit=False) add_comment.directory = directory_detail if logged: add_comment.user = user add_comment.status = False add_comment.date_create = datetime.now().replace(tzinfo=utc) add_comment.save() else: initial = '' if logged: initial = { 'name': user.first_name + ' ' + user.last_name, 'email': user.email, } form_comment = CommentForm(initial=initial) # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) list_comment = Comment.objects.all().filter( status=True, directory=directory_detail).order_by('-pk')[:5] list_rate = Rate.objects.all().filter(directory=directory_detail) avg = Rate.objects.all().filter(directory=directory_detail).aggregate( Avg('value')) ctx = { 'points': points, 'directory_detail': directory_detail, 'directory_service': directory_service, 'directory_payment': directory_payment, 'directory_style': directory_style, 'logged': logged, 'galery': galery, 'form_reserve_sent': form_reserve_sent, 'form_comment_sent': form_comment_sent, 'form_reserve': form_reserve, 'form_comment': form_comment, 'formulario_whois': formulario_whois, 'list_category': category, 'list_comment': list_comment, 'list_rate': list_rate, 'avg': avg, 'pais_actual': pais_actual, 'URL_SITE': settings.URL_SITE, } response = render_to_response('directory/dir.html', ctx, context_instance=RequestContext(request)) return response except Directory.DoesNotExist: raise Http404 return HttpResponseRedirect('/')
def directory_category_view(request, url_name, page): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] # directorio directory = Directory.objects.filter( status=True, deleted=False, country_id=country_id, category__url_name__exact=url_name).order_by('-id_directory') except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 # directorio directory = Directory.objects.filter( status=True, deleted=False, category__url_name__exact=url_name).order_by('-id_directory') points = 0 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) state_id = profile.state_id country_id = profile.country_id language_id = profile.language_id today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### get_category = Category.objects.all().get(url_name=url_name) pais_actual = Country.objects.all().get(id_country=country_id) # paginar los resultados a '10' por pagina paginator = Paginator(directory, 10) try: num_page = int(page) except: num_page = 1 try: directory = paginator.page(num_page) except (EmptyPage, InvalidPage): directory = paginator.page(paginator.num_pages) if request.POST: formulario = SearchRestaurantForm(request.POST) else: #formulario = SearchRestaurantForm(initial={'Estado':'4'}) formulario = SearchRestaurantForm() formulario.fields['Estado'].queryset = State.objects.filter( country_id=country_id) # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) # categorias # type: (1: restaurantes, 2: proveedores) category = Category.objects.all().filter( status=True, type=1, directory__isnull=False, directory__country_id=country_id, directory__deleted=False, directory__status=True).order_by('title').distinct() #category = Directory.objects.values('category').annotate(Count('category')).order_by() #category = Category.objects.annotate(num_category=Count('directory')) #category = Directory.objects.annotate(review_count=Count('category')).order_by('review_count') #directorio1 = Directorio.objects.filter(status=True) ctx = { 'points': points, 'form_rest': formulario, 'list_directory': directory, 'list_category': category, 'get_category': get_category, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, 'url_name': url_name, } response = render_to_response('directory/directory_x_category.html', ctx, context_instance=RequestContext(request)) return response
def add_sheets_view(request): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### directory = message = msg_error = '' pay_count = 0 form_sent = False today = datetime.now() formulario = '' if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) #try: # pay_count = Pay.objects.filter(user=user, pay_status=3, directory__isnull=True).latest('pk') if request.method == "POST": formulario = addRestaurantForm(request.POST, request.FILES) if formulario.is_valid(): form_sent = True # Agregar restaurante add_directory = formulario.save(commit=False) add_directory.user = user add_directory.url_name = slugify( formulario.cleaned_data['title']) add_directory.date_create = datetime.now().replace(tzinfo=utc) add_directory.date_update = datetime.now().replace(tzinfo=utc) add_directory.save() formulario.save_m2m() #pay_count.directory = add_directory #pay_count.save() message = 'Su establecimiento se ha creado satisfactoriamente.' else: formulario = addRestaurantForm(initial={ 'country': country_id, 'state': state_id }) #except Pay.DoesNotExist: # return HttpResponseRedirect('/accounts/sheets/package/') pais_actual = Country.objects.all().get(id_country=country_id) # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'form_sent': form_sent, 'state': state_id, 'list_directory': directory, 'formulario_whois': formulario_whois, 'form': formulario, 'pais_actual': pais_actual, 'message': message, 'msg_error': msg_error, } response = render_to_response('accounts/sheets/add.html', ctx, context_instance=RequestContext(request)) return response
def list_package_view(request): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### message = '' msg_error = '' form_sent = '' last_id = 0 pay_months = 0 total_price = 0 concept = '' pais_actual = Country.objects.all().get(id_country=country_id) list_package = Package.objects.filter(status=True).order_by('order') total_package = Package.objects.all().aggregate(price=Sum('price')) if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) points = PointByScore(request) if request.method == "POST": form_package = PackageForm(request.POST) if form_package.is_valid(): fecha = datetime.now().replace(tzinfo=utc) form_sent = True package = form_package.save(commit=False) package.user = user package.pay_status = 1 package.subtotal = request.POST['subtotal'] package.date_create = fecha package.date_begin = fecha package.date_end = fecha package.save() # Guardamos el objeto form_package.save_m2m() last_id = package.pk pay_months = package.pay_months total_price = package.price concept = package.concept else: form_sent = False form_package = PackageForm() # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) paypal_email = settings.PAYPAL_EMAIL paypal_url = settings.PAYPAL_URL paypal_return_url = settings.PAYPAL_RETURN_URL paypal_cancel_url = settings.PAYPAL_RETURN_URL + '%s/cancel/' % (last_id) ctx = { 'points': points, 'pay_id': last_id, 'paypal_email': paypal_email, 'paypal_url': paypal_url, 'paypal_return_url': paypal_return_url, 'paypal_cancel_url': paypal_cancel_url, 'total_price': total_price, 'concept': concept, 'pay_months': pay_months, 'total_package': total_package, 'list_package': list_package, 'form_package': form_package, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, 'form_sent': form_sent, 'message': message, } response = render_to_response('accounts/sheets/package.html', ctx, context_instance=RequestContext(request)) return response
def contact_view(request): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 contact_sent = False # Definir si se envio la informacion correctamente o no nombre = '' email = '' telefono = '' como_conocio = '' asunto = '' comentarios = '' points = 0 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) nombre = user.first_name + ' ' + user.last_name email = user.email telefono = profile.phone today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) if request.method == "POST": formulario = ContactForm(request.POST) if formulario.is_valid(): contact_sent = True email = formulario.cleaned_data['Email'] nombre = formulario.cleaned_data['Nombre'] telefono = formulario.cleaned_data['Telefono'] como_conocio = formulario.cleaned_data['Como_conocio'] asunto = formulario.cleaned_data['Asunto'] comentarios = formulario.cleaned_data['Comentarios'] # Almacenar la info en la BD c = Contact() c.status = 1 c.name = nombre c.email = email c.phone = telefono c.language_id = language_id c.country_id = country_id c.how_know = como_conocio c.subject = asunto c.content = comentarios c.date_create = datetime.now().replace(tzinfo=utc) c.save() #enviar Email email_from = settings.EMAIL_FROM email_to = settings.EMAIL_TO subject = 'ZoneTable - Contacto' page_url = 'contact_admin.html' content = '<p>Hola :</p>' content += '<p>Ha recibido un nuevo mensaje de contacto.</p>' content += '<p>Nombre: %s</p>' % (nombre) content += '<p>Email: %s</p>' % (email) content += '<p>Teléfono: %s</p>' % (telefono) content += '<p>Comentarios: %s</p>' % (comentarios) send_mail(email_from, email_to, subject, content, page_url, headers=None) email_from = settings.EMAIL_FROM email_to = email subject = 'ZoneTable - Contacto' page_url = 'contact_admin.html' content = '<p>Hola %s:</p>' % (nombre) content += '<p>Le enviamos una copia de su mensaje de contacto a través del formulario:</p>' content += '<p>Nombre: %s</p>' % (nombre) content += '<p>Email: %s</p>' % (email) content += '<p>Teléfono: %s</p>' % (telefono) content += '<p>Comentarios: %s</p>' % (comentarios) send_mail(email_from, email_to, subject, content, page_url, headers=None) ##### message = 'Su mensaje ha sido enviado satisfactoriamente.' else: formulario = ContactForm(initial={ 'Nombre': nombre, 'Email': email, 'Telefono': telefono }) # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'form': formulario, 'contact_sent': contact_sent, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('home/contacto.html', ctx, context_instance=RequestContext(request)) return response
def list_sheets_view(request, page): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### directory = '' message = '' if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) directory = Directory.objects.filter( user=user, deleted=False).order_by('-id_directory') #TODO: Incluir en el listado las categorías de cada ficha # paginar los resultados a '10' por pagina paginator = Paginator(directory, 10) try: num_page = int(page) except: num_page = 1 try: directory = paginator.page(num_page) except (EmptyPage, InvalidPage): directory = paginator.page(paginator.num_pages) pais_actual = Country.objects.all().get(id_country=country_id) # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'num_page': num_page, 'list_directory': directory, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, 'message': message, } response = render_to_response('accounts/sheets/list.html', ctx, context_instance=RequestContext(request)) return response
def edit_sheets_view(request, id_directory): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### directory = '' message = '' msg_error = '' form_sent = False today = datetime.now() formulario = '' if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) try: directory = Directory.objects.get(pk=id_directory, user=user) ''' if request.method == "GET": # filtramos las categorias que son seleccionadas category_ids = [] for group in d.category.all(): category_ids.append(group.pk) formulario = CreateRestaurantForm(initial={ 'titulo': d.title, 'direccion': d.address, 'codigo_postal': d.postal_code, 'ciudad': d.city, 'estado': d.state, 'pais': d.country, 'categoria':category_ids, 'telefono': d.phone, 'celular': d.cell, 'email': d.email, 'sitio_web': d.website, 'twitter': d.twitter, 'facebook': d.facebook, 'google_plus': d.google_plus, 'contenido': d.content, 'comentarios': int(d.comment), 'ubicacion_gmap': d.geo_location, }) ''' if request.method == "POST": formulario = addRestaurantForm(request.POST, request.FILES, instance=directory) if formulario.is_valid(): # Agregar restaurante edit_directory = formulario.save(commit=False) formulario.save_m2m() edit_directory.date_update = datetime.now().replace( tzinfo=utc) edit_directory.save() # Guardamos el objeto ''' directory.title = formulario.cleaned_data['titulo'] directory.address = formulario.cleaned_data['direccion'] if formulario.cleaned_data['codigo_postal']: directory.postal_code = formulario.cleaned_data['codigo_postal'] if formulario.cleaned_data['ciudad']: directory.city = formulario.cleaned_data['ciudad'] directory.state = formulario.cleaned_data['estado'] directory.delete = False directory.country = formulario.cleaned_data['pais'] directory.language_id = request.COOKIES['gm_language'] #directory.hours = formulario.cleaned_data['horario'] directory.phone = formulario.cleaned_data['telefono'] if formulario.cleaned_data['celular']: directory.cell = formulario.cleaned_data['celular'] directory.email = formulario.cleaned_data['email'] if formulario.cleaned_data['sitio_web']: directory.website = formulario.cleaned_data['sitio_web'] directory.comment = int(formulario.cleaned_data['comentarios']) if formulario.cleaned_data['contenido']: directory.content = formulario.cleaned_data['contenido'] if formulario.cleaned_data['ubicacion_gmap']: directory.geo_location = formulario.cleaned_data['ubicacion_gmap'] if formulario.cleaned_data['twitter']: directory.twitter = formulario.cleaned_data['twitter'] if formulario.cleaned_data['facebook']: directory.facebook = formulario.cleaned_data['facebook'] if formulario.cleaned_data['google_plus']: directory.google_plus = formulario.cleaned_data['google_plus'] directory.url_name = slugify(formulario.cleaned_data['titulo']) directory.user = user directory.date_create = datetime.now().replace(tzinfo=utc) try: directory.save() directory.category.clear() category = request.POST.getlist('categoria') for i in category: directory.category.add(i) form_sent = True except: msg_error = 'Error: Se produjo un error al guardar los datos.' ''' form_sent = True message = 'Su ficha se ha editado satisfactoriamente.' else: formulario = addRestaurantForm(instance=directory) except: return HttpResponseRedirect('/accounts/sheets/1/') pais_actual = Country.objects.all().get(id_country=country_id) # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'form_sent': form_sent, 'state': state_id, 'list_directory': directory, 'formulario_whois': formulario_whois, 'form': formulario, 'pais_actual': pais_actual, 'message': message, 'msg_error': msg_error, } response = render_to_response('accounts/sheets/edit.html', ctx, context_instance=RequestContext(request)) return response
def add_reservation_view(request, id_sheets): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) points = 0 message = '' form_sent = False if request.user.is_authenticated(): #user = User.objects.get(pk=request.user.id) try: directory = Directory.objects.get(pk=id_sheets, status=True, user=request.user.id) points = PointByScore(request) if request.method == "POST": form_reserve = ReserveForm(request.POST) if form_reserve.is_valid(): id_user = request.POST.get('id_user') nombre = form_reserve.cleaned_data['name'] email_to_user = form_reserve.cleaned_data['email'] telefono = form_reserve.cleaned_data['phone'] fecha = form_reserve.cleaned_data['date'] hora = form_reserve.cleaned_data['time'] description = form_reserve.cleaned_data['description'] add_reserve = form_reserve.save(commit=False) if id_user: add_reserve.user_id = id_user add_reserve.directory = directory add_reserve.date_create = datetime.now().replace(tzinfo=utc) add_reserve.date_update = datetime.now().replace(tzinfo=utc) add_reserve.save() form_sent = True else: form_reserve = ReserveForm(initial={'type': 0}) except Directory.DoesNotExist: return HttpResponseRedirect('/accounts/my-reservations/1/') else: return HttpResponseRedirect('/') # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'form_sent': form_sent, 'form_reserve': form_reserve, 'directory': directory, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('accounts/reservation/add.html', ctx, context_instance=RequestContext(request)) return response
def list_reservation_view(request, id_sheets, id_page): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) points = 0 message = '' profile_sent = False if request.user.is_authenticated(): #user = User.objects.get(pk=request.user.id) try: directory = Directory.objects.get(pk=id_sheets, user=request.user.id) reservations = Reserve.objects.filter(directory=directory).order_by('status', 'date', 'time') points = PointByScore(request) # paginar los resultados a '10' por pagina paginator = Paginator(reservations, 10) try: num_page = int(id_page) except: num_page = 1 try: reservations = paginator.page(num_page) except (EmptyPage, InvalidPage): reservations = paginator.page(paginator.num_pages) except Directory.DoesNotExist: return HttpResponseRedirect('/accounts/sheets/1/') else: return HttpResponseRedirect('/') # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'directory': directory, 'list_reservations': reservations, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('accounts/reservation/list.html', ctx, context_instance=RequestContext(request)) return response
def home_view(request): #TODO: testing try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] # directorio directory = Directory.objects.all().filter(status=True, deleted=False, language_id=language_id, country_id=country_id).order_by('-id_directory')[:10] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 # directorio directory = Directory.objects.all().filter(status=True, deleted=False, language_id=language_id).order_by( '-id_directory')[:10] points = 0 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) estado_actual = State.objects.all().get(id_state=state_id) ''' login_sent = False # Definir si se envio la informacion correctamente o no email = '' password = '' if request.method == "POST": formulario = LoginForm(request.POST) if formulario.is_valid(): login_sent = True email = formulario.cleaned_data['Email'] else: formulario = LoginForm() ''' if request.POST: formulario = SearchRestaurantForm(request.POST) else: #formulario = SearchRestaurantForm(initial={'Estado':'4'}) formulario = SearchRestaurantForm(initial={'Estado': state_id}) formulario.fields['Estado'].queryset = State.objects.filter(country_id=country_id) # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) # categorias # type: (1: restaurantes, 2: proveedores) category = Category.objects.all().filter(status=True, type=1, directory__isnull=False, directory__country_id=country_id, directory__deleted=False, directory__status=True).order_by('title').distinct() #category = Directory.objects.values('category').annotate(Count('category')).order_by() #category = Category.objects.annotate(num_category=Count('directory')) #category = Directory.objects.annotate(review_count=Count('category')).order_by('review_count') #directorio1 = Directorio.objects.filter(status=True) #d = Directory.objects.filter(multiuploaderimage__filename='thumbnail-big.jpg') #m = MultiuploaderImage.objects.select_related('directory') #lista = d.multiuploaderimage.all() #lista = Directory.multiuploaderimage_set.all()[:0] ctx = { 'points': points, #'list':lista, 'form_rest': formulario, 'list_directory': directory, 'list_category': category, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, 'pais_actual1': 'img/flag/%s.gif' % pais_actual.iso2.lower(), } response = render_to_response('home/index.html', ctx, context_instance=RequestContext(request)) return response
def search_rest_view(request, page): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 points = 0 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) state_id = profile.state_id country_id = profile.country_id language_id = profile.language_id today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) category = Category.objects.all().filter( status=True, type=1, directory__isnull=False, directory__country_id=country_id, directory__deleted=False, directory__status=True).order_by('title').distinct() search_sent = False message = '' directory = '' if request.GET: search_sent = True formulario = SearchRestaurantForm(request.GET) formulario.fields['Estado'].queryset = State.objects.filter( country_id=country_id) if formulario.is_valid(): form_nombre = formulario.cleaned_data['Nombre'] form_category = formulario.cleaned_data['Categoria'] form_state = formulario.cleaned_data['Estado'] if form_category > 0: directory = Directory.objects.all().filter( status=True, title__contains=form_nombre, category__id_category__exact=form_category.id_category, state__id_state__exact=form_state.id_state).order_by( '-id_directory') else: directory = Directory.objects.all().filter( status=True, title__contains=form_nombre, state__id_state__exact=form_state.id_state).order_by( '-id_directory') # paginar los resultados a '10' por pagina paginator = Paginator(directory, 10) try: num_page = int(page) except: num_page = 1 try: directory = paginator.page(num_page) except (EmptyPage, InvalidPage): directory = paginator.page(paginator.num_pages) else: message = 'Por favor, seleccione un criterio de búsqueda.' else: formulario = SearchRestaurantForm() formulario.fields['Estado'].queryset = State.objects.filter( country_id=country_id) message = 'Por favor, seleccione un criterio de búsqueda.' # ?Nombre=&Fecha=2013-02-17&Hora=02%3A00+AM&Categoria=&Personas=1+Persona&Estado=59 # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'form_rest': formulario, 'formulario_whois': formulario_whois, 'list_category': category, 'list_directory': directory, 'pais_actual': pais_actual, 'message': message, #'nombre':formulario.cleaned_data['Nombre'], #'fecha':formulario.cleaned_data['Fecha'], #'hora':formulario.cleaned_data['Hora'], #'categoria':formulario.cleaned_data['Categoria'], #'personas':formulario.cleaned_data['Personas'], #'estado':formulario.cleaned_data['Estado'].id_state, } response = render_to_response('search/search_rest.html', ctx, context_instance=RequestContext(request)) response.set_cookie("gm_state", state_id) response.set_cookie("gm_country", country_id) response.set_cookie("gm_language", language_id) return response
def edit_user_profile_view(request): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) #max_age = 365*24*60*60 # 1 año ############################### msg_error = msg_ok = '' state = 1 country = 1 profile_sent = False if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) points = PointByScore(request) if request.POST: form_user = ProfileForm(request.POST, instance=user) form_profile = EditRegisterForm(request.POST, instance=profile) if form_user.is_valid(): if form_profile.is_valid(): password = form_user.cleaned_data['password'] repassword = form_user.cleaned_data['repassword'] state_id = form_profile.cleaned_data['state'].id_state country_id = form_profile.cleaned_data[ 'country'].id_country language_id = form_profile.cleaned_data[ 'language'].id_language ''' try: User.objects.get(email=email) message = 'Error: El Email ya se encuentra registrado.' #<a href="/forgot_pass/">¿Olvidó su contraseña?</a> except User.DoesNotExist: ''' addUser = form_user.save(commit=False) if password: if password == repassword: addUser.set_password(password) addUser.save() addProfile = form_profile.save(commit=False) addProfile.user = addUser addProfile.save() form_profile.save_m2m() msg_ok = 'Tu perfil ha sido actualizado.' profile_sent = True else: form_user = ProfileForm(instance=user) form_profile = EditRegisterForm(instance=profile) else: return HttpResponseRedirect('/') pais_actual = Country.objects.all().get(id_country=country_id) category = Category.objects.all().filter(status=True, type=1).order_by('title') # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'email': user.email, 'state': profile.state_id, 'profile_sent': profile_sent, 'msg_ok': msg_ok, 'msg_error': msg_error, 'profile': profile, 'form_user': form_user, 'form_profile': form_profile, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } ''' t = loader.get_template('accounts/profile.html') c = RequestContext(request, ctx) response = HttpResponse(t.render(c)) response.set_cookie('gm_country', country_id, max_age=max_age, expires=today, path='/', domain=None, secure=None, httponly=False) response.set_cookie('gm_state', state_id, max_age=max_age, expires=today, path='/', domain=None, secure=None, httponly=False) response.set_cookie('gm_language', language_id, max_age=max_age, expires=today, path='/', domain=None, secure=None, httponly=False) return response ''' response = render_to_response('accounts/profile.html', ctx, context_instance=RequestContext(request)) response.set_cookie("gm_state", state_id) response.set_cookie("gm_country", country_id) response.set_cookie("gm_language", language_id) return response
def confirm_view(request, random): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) state_id = profile.state_id country_id = profile.country_id language_id = profile.language_id today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) message_ok = '' message_error = '' points = 0 if request.user.is_authenticated(): points = PointByScore(request) try: user_profile = UserProfile.objects.get(random=random) #user = User.objects.get(pk=user_profile.user_id) #user.is_active = True #user.save() user_profile.user_status = '1' user_profile.save() message_ok = 'Felicidades, haz confirmado satisfactoriamente tu cuenta.' except UserProfile.DoesNotExist: message_error = 'Error: El código de confirmación es incorrecto. <br /> <br /> Por favor, <a href="/contact/">contáctanos aquí</a>.' # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'points': points, 'message_ok': message_ok, 'message_error': message_error, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('accounts/register_confirm.html', ctx, context_instance=RequestContext(request)) return response
def referer_view(request, id_user): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) state_id = profile.state_id country_id = profile.country_id language_id = profile.language_id today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) # Envia por email un codigo para confirmar la cuenta de email (la cuenta no se deshabilita, solo se guarda el valor en otro campo). register_sent = False # Definir si se envio la informacion correctamente o no message = '' first_name = '' last_name = '' phone = '' birth_day = '' birth_month = '' birth_year = '' state = '' country = '' email = '' password = '' repassword = '' if not request.user.is_authenticated(): if request.POST: form_user = UserForm(request.POST) form_profile = RegisterForm(request.POST) if form_user.is_valid(): if form_profile.is_valid(): email = form_user.cleaned_data['email'] password = form_user.cleaned_data['password'] repassword = form_user.cleaned_data['repassword'] try: User.objects.get(email=email) message = 'Error: El Email ya se encuentra registrado.' #<a href="/forgot_pass/">¿Olvidó su contraseña?</a> except User.DoesNotExist: if password == repassword: register_sent = True # Registro de usuario random_number = User.objects.make_random_password( length=10) addUser = form_user.save(commit=False) addUser.username = email addUser.set_password(password) addUser.is_active = True addUser.last_login = datetime.now().replace( tzinfo=utc) addUser.date_joined = datetime.now().replace( tzinfo=utc) addUser.save() addProfile = form_profile.save(commit=False) addProfile.user = addUser addProfile.random = random_number addProfile.user_status = False try: referer_user = User.objects.get(pk=id_user) addProfile.referer = referer_user.pk except User.DoesNotExist: pass addProfile.save() form_profile.save_m2m() url_confirm = settings.URL_SITE message = 'Su cuenta ha sido creada satisfactoriamente.' else: message = 'Las contraseñas no coinciden.' else: # enviamos el ID del pais de la cookie form_user = UserForm() form_profile = RegisterForm(initial={ 'country': country_id, 'state': state_id }) #formulario = RegisterForm() #formulario.fields['pais'].queryset = Country.objects.filter(id_country=country_id).order_by('title') # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'state': state_id, 'message': message, 'register_sent': register_sent, 'form_user': form_user, 'form_profile': form_profile, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('accounts/register.html', ctx, context_instance=RequestContext(request)) return response else: return HttpResponseRedirect('/')
def register_view(request): try: country_id = request.COOKIES['gm_country'] state_id = request.COOKIES['gm_state'] language_id = request.COOKIES['gm_language'] except: #remote_addr = request.META.get('HTTP_X_FORWARDED_FOR', "127.0.0.1") remote_addr = request.META['REMOTE_ADDR'] country_id = getUserCountry(remote_addr) state_id = 1 language_id = 1 if request.user.is_authenticated(): user = User.objects.get(pk=request.user.id) profile = UserProfile.objects.get(user=user) state_id = profile.state_id country_id = profile.country_id language_id = profile.language_id today = datetime.now() today = today.strftime("%a, %d-%b-%Y %H:%M:%S GMT") max_age = 90 * 24 * 60 * 60 # 3 meses (90 días) ############################### pais_actual = Country.objects.all().get(id_country=country_id) # Envia por email un codigo para confirmar la cuenta de email (la cuenta no se deshabilita, solo se guarda el valor en otro campo). register_sent = False # Definir si se envio la informacion correctamente o no message = '' first_name = '' last_name = '' phone = '' birth_day = '' birth_month = '' birth_year = '' state = '' country = '' email = '' password = '' repassword = '' if not request.user.is_authenticated(): if request.POST: form_user = UserForm(request.POST) form_profile = RegisterForm(request.POST) if form_user.is_valid(): if form_profile.is_valid(): email = form_user.cleaned_data['email'] password = form_user.cleaned_data['password'] repassword = form_user.cleaned_data['repassword'] """ nombre = form_user.cleaned_data['first_name'] apellidos = form_user.cleaned_data['last_name'] telefono = form_profile.cleaned_data['phone'] nac_dia = form_profile.cleaned_data['nac_dia'] nac_mes = form_profile.cleaned_data['nac_mes'] nac_anio = form_profile.cleaned_data['nac_anio'] estado = form_profile.cleaned_data['estado'] pais = form_profile.cleaned_data['pais'] language = language_id """ try: User.objects.get(email=email) message = 'Error: El Email ya se encuentra registrado.' #<a href="/forgot_pass/">¿Olvidó su contraseña?</a> except User.DoesNotExist: if password == repassword: register_sent = True # Registro de usuario """ crear_usuario = User.objects.create_user(username='******', email='a') crear_usuario.is_active = True crear_usuario.save() """ random_number = User.objects.make_random_password( length=10) addUser = form_user.save(commit=False) addUser.username = email addUser.set_password(password) addUser.is_active = True addUser.last_login = datetime.now().replace( tzinfo=utc) addUser.date_joined = datetime.now().replace( tzinfo=utc) addUser.save() addProfile = form_profile.save(commit=False) addProfile.user = addUser addProfile.random = random_number addProfile.user_status = False addProfile.save() form_profile.save_m2m() """ crear_profile = form_profile.save(commit=False) crear_profile.user = crear_usuario crear_profile.phone = phone crear_profile.birth_day = birth_day crear_profile.birth_month = birth_month crear_profile.birth_year = birth_year crear_profile.state = state crear_profile.country = country crear_profile.language_id = language_id crear_profile.random = random_number crear_profile.user_status = 0 crear_profile.save() form_profile.save_m2m() """ url_confirm = settings.URL_SITE message = 'Su cuenta ha sido creada satisfactoriamente.' else: message = 'Las contraseñas no coinciden.' """ nombre = formulario.cleaned_data['nombre'] apellidos = formulario.cleaned_data['apellidos'] telefono = formulario.cleaned_data['telefono'] nac_dia = formulario.cleaned_data['nac_dia'] nac_mes = formulario.cleaned_data['nac_mes'] nac_anio = formulario.cleaned_data['nac_anio'] estado = formulario.cleaned_data['estado'] pais = formulario.cleaned_data['pais'] language = language_id email = formulario.cleaned_data['email'] password = formulario.cleaned_data['password'] repassword = formulario.cleaned_data['repassword'] try: User.objects.get(email=email) message = 'Error: El Email ya se encuentra registrado.' #<a href="/forgot_pass/">¿Olvidó su contraseña?</a> except User.DoesNotExist: if password == repassword: register_sent = True crear_usuario = User.objects.create_user(username=email, email=email) crear_usuario.first_name = nombre crear_usuario.last_name = apellidos crear_usuario.set_password(password) crear_usuario.is_active = True crear_usuario.save() random_number = User.objects.make_random_password(length=10) perfil_usuario = UserProfile(user=crear_usuario) perfil_usuario.phone = telefono perfil_usuario.birth_day = nac_dia perfil_usuario.birth_month = nac_mes perfil_usuario.birth_year = nac_anio perfil_usuario.state = estado perfil_usuario.country = pais perfil_usuario.language_id = language perfil_usuario.random = random_number perfil_usuario.user_status = 0 perfil_usuario.save() url_confirm = settings.URL_SITE #enviar Email email_from = settings.EMAIL_FROM email_to = email subject = 'ZoneTable - Registro' page_url = 'register_confirm.html' content = '<p>Hola <strong>%s</strong>:</p><p>Muchas gracias por pertenecer a nuestro sitio.</p><p>Por favor, confirma tu email con el siguiente enlace : %sconfirm/%s/</p>' % (nombre, url_confirm, random_number) send_mail(email_from, email_to, subject, content, page_url, headers = None) ##### message = 'Su cuenta ha sido creada satisfactoriamente.' else: message = 'No coinciden.' """ else: # enviamos el ID del pais de la cookie form_user = UserForm() form_profile = RegisterForm(initial={ 'country': country_id, 'state': state_id }) #formulario = RegisterForm() #formulario.fields['pais'].queryset = Country.objects.filter(id_country=country_id).order_by('title') # enviamos el ID del pais de la cookie formulario_whois = WhoisForm(initial={'Country': country_id}) ctx = { 'state': state_id, 'message': message, 'register_sent': register_sent, 'form_user': form_user, 'form_profile': form_profile, 'formulario_whois': formulario_whois, 'pais_actual': pais_actual, } response = render_to_response('accounts/register.html', ctx, context_instance=RequestContext(request)) return response else: return HttpResponseRedirect('/')