def change_password(request): response = Epoxy(request) if request.method == 'POST': form = ChangePasswordForm(request.REQUEST) if form.is_valid(): uPass1 = form.cleaned_data['password1'] uPass2 = form.cleaned_data['password2'] if uPass1 == uPass2: user = User.objects.get(username=form.cleaned_data['username']) user.set_password(uPass1) user.save() else: return response.throw_error( error={ 'password1': 'the 2 pwd must be the same', 'password2': 'the 2 pwd must be the same' }, code=API_EXCEPTION_FORMERRORS).json() else: return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json() return response.json()
def subscribers(request): # logger.info("Welcome to GLUEBOX api") response = Epoxy( request ) if response.method=="POST": form = SubscriberForm( request.REQUEST ) if not form.is_valid(): return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() try: s = Subscriber( first_name = form.cleaned_data['first_name'], last_name = form.cleaned_data['last_name'], email = form.cleaned_data['email'], affiliation = form.cleaned_data['affiliation'], accepted_terms = form.cleaned_data['accepted_terms'], description = form.cleaned_data['description']) s.save() except IntegrityError, e: try: s = Subscriber.objects.get( email=form.cleaned_data['email'] ) except Subscriber.DoesNotExist, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_INTEGRITY).json()
def reinitialize_password(request): response = Epoxy(request) if request.method == 'POST': form = ReinitializePasswordForm(request.REQUEST) if form.is_valid(): try: #user = User.objects.get(username=form.cleaned_data['username'], email__iexact=form.cleaned_data['email']) user = User.objects.get( email__iexact=form.cleaned_data['email']) except MultipleObjectsReturned, e: user = User.objects.filter( email__iexact=form.cleaned_data['email']) user = user[0] except User.DoesNotExist, e: return response.throw_error( error=_('This user does not exist in our database'), code=API_EXCEPTION_DOESNOTEXIST).json() subscriber = get_object_or_404(Subscriber, user__id=user.id) send_confirmation_mail(subscriber, request, action='reinitialize_password')
def enquiries( request ): response = Epoxy( request ) if response.method =='POST': form = AddEnquiryForm( request.REQUEST ) if not form.is_valid(): return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() try: enquete = Enquete.objects.get(id=form.cleaned_data['enquete']) enquiry_en = Enquiry( title=form.cleaned_data['title_en'], language='EN', slug=form.cleaned_data['slug'], enquete = enquete ) enquiry_fr = Enquiry( title=form.cleaned_data['title_fr'], language='FR', slug=form.cleaned_data['slug'], enquete = enquete ) enquiry_en.save() enquiry_fr.save() #try: #e_en = Page( title=form.cleaned_data['title_en'], language='EN', slug=form.cleaned_data['slug']) #e_en.save() #p_fr = Page( title=form.cleaned_data['title_fr'], language='FR', slug=form.cleaned_data['slug']) #p_fr.save() except IntegrityError, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_INTEGRITY).json()
def subscribers(request): # logger.info("Welcome to GLUEBOX api") response = Epoxy(request) if response.method == "POST": form = SubscriberForm(request.REQUEST) if not form.is_valid(): return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json() else: if (form.cleaned_data['action'] == 'EDIT'): #GET subscriber id update = Subscriber.objects.filter( user=request.user.id).update( first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], email=form.cleaned_data['email'], affiliation=form.cleaned_data['affiliation'], status=form.cleaned_data['status'], accepted_terms=form.cleaned_data['accepted_terms'], description=form.cleaned_data['description']) elif (form.cleaned_data['action'] == 'ADD'): contacts(form) return response.queryset(Subscriber.objects.filter()).json()
def reinitialize_password(request): response = Epoxy( request ) if request.method == 'POST': form = ReinitializePasswordForm( request.REQUEST ) if form.is_valid(): try: #user = User.objects.get(username=form.cleaned_data['username'], email__iexact=form.cleaned_data['email']) user = User.objects.get(email__iexact=form.cleaned_data['email']) except MultipleObjectsReturned, e: user = User.objects.filter(email__iexact=form.cleaned_data['email']) user = user[0] except User.DoesNotExist, e : return response.throw_error( error=_('This user does not exist in our database'), code=API_EXCEPTION_DOESNOTEXIST).json() subscriber = get_object_or_404( Subscriber, user__id=user.id ) send_confirmation_mail(subscriber, request, action='reinitialize_password')
def subscribers(request): # logger.info("Welcome to GLUEBOX api") response = Epoxy( request ) if response.method=="POST": form = SubscriberForm( request.REQUEST ) if not form.is_valid(): return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() else: if( form.cleaned_data['action'] == 'EDIT'): #GET subscriber id update = Subscriber.objects.filter(user=request.user.id).update( first_name = form.cleaned_data['first_name'], last_name = form.cleaned_data['last_name'], email = form.cleaned_data['email'], affiliation = form.cleaned_data['affiliation'], status = form.cleaned_data['status'], accepted_terms = form.cleaned_data['accepted_terms'], description = form.cleaned_data['description']) elif( form.cleaned_data['action'] == 'ADD'): contacts( form ) return response.queryset( Subscriber.objects.filter() ).json()
def enquiries(request): response = Epoxy(request) if response.method == 'POST': form = AddEnquiryForm(request.REQUEST) if not form.is_valid(): return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json() try: enquete = Enquete.objects.get(id=form.cleaned_data['enquete']) enquiry_en = Enquiry(title=form.cleaned_data['title_en'], language='EN', slug=form.cleaned_data['slug'], enquete=enquete) enquiry_fr = Enquiry(title=form.cleaned_data['title_fr'], language='FR', slug=form.cleaned_data['slug'], enquete=enquete) enquiry_en.save() enquiry_fr.save() #try: #e_en = Page( title=form.cleaned_data['title_en'], language='EN', slug=form.cleaned_data['slug']) #e_en.save() #p_fr = Page( title=form.cleaned_data['title_fr'], language='FR', slug=form.cleaned_data['slug']) #p_fr.save() except IntegrityError, e: return response.throw_error(error="%s" % e, code=API_EXCEPTION_INTEGRITY).json()
def enquiry_upload_pin( request, enquiry_id ): response = Epoxy( request ) d = datetime.now() try: enquiry = Enquiry.objects.get(id=enquiry_id) enquiry_en = Enquiry.objects.get( language="EN", slug=enquiry.slug ) enquiry_fr = Enquiry.objects.get( language="FR", slug=enquiry.slug ) except Enquiry.DoesNotExist, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST ).json()
def enquete_data( request, enquete_id ): data = {} return render_to_response('outside/enquete_data.json', RequestContext(request, data ) ) response = Epoxy( request ) import random try: textes = Enquete.objects.get(id=enquete_id).texte_set except Enquete.DoesNotExist, e: return response.throw_error(error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
def enquiry_pins( request, enquiry_slug ): response = Epoxy( request ) # get both language enquiry objects try: enquiry_en = Enquiry.objects.get( slug=enquiry_slug,language='EN') enquiry_fr = Enquiry.objects.get( slug=enquiry_slug,language='FR') except Page.DoesNotExist, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST ).json()
def pin_upload( request ): response = Epoxy( request ) d = dt.datetime.now() form = UploadPinForm( request.REQUEST ) if not form.is_valid(): return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS) if len(form.cleaned_data['page_slug']) > 0: # attacch new pin to a selected page (both languages) response.add('page_slug',form.cleaned_data['page_slug']) try: page_en = Page.objects.get( slug=form.cleaned_data['page_slug'],language='EN') page_fr = Page.objects.get( slug=form.cleaned_data['page_slug'],language='FR') except Page.DoesNotExist: return response.throw_error( error=_("selected page does not exists"), code=API_EXCEPTION_FORMERRORS).json() response.add('page', [ page_en.json(), page_fr.json() ] ) pin_path = response.add('path', "pins/%s-%s" % ( d.year, ( d.month if d.month >10 else "0%s" % d.month ) ) ) absolute_pin_path = os.path.join( settings.MEDIA_ROOT, pin_path ) try: if not os.path.exists( absolute_pin_path ): os.makedirs( absolute_pin_path ) # throw an OS ERROR if exists... OR if it is not writable! except OSError, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_OSERROR ).json()
def enquiry_upload_pin(request, enquiry_id, pin_slug): response = Epoxy(request) d = datetime.now() try: enquiry = Enquiry.objects.get(id=enquiry_id) enquiry_en = Enquiry.objects.get(language="EN", slug=enquiry.slug) enquiry_fr = Enquiry.objects.get(language="FR", slug=enquiry.slug) except Enquiry.DoesNotExist, e: return response.throw_error(error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
def enquiry_pins(request, enquiry_slug): response = Epoxy(request) # get both language enquiry objects try: enquiry_en = Enquiry.objects.get(slug=enquiry_slug, language='EN') enquiry_fr = Enquiry.objects.get(slug=enquiry_slug, language='FR') except Page.DoesNotExist, e: return response.throw_error(error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
def enquete_data(request, enquete_id): data = {} # return render_to_response('outside/enquete_data.json', RequestContext(request, data ) ) response = Epoxy(request) try: textes = Enquete.objects.get(id=enquete_id).texte_set except Enquete.DoesNotExist, e: response.meta('enquete_id', enquete_id) return response.throw_error(error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
def auth_login(request): response = Epoxy(request) form = LoginForm(request.POST) try: if 'next' not in request.session: request.session['next'] = request.REQUEST['next'] except: pass if request.method == 'POST': if form.is_valid(): user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password']) if user is not None: if user.is_active: login(request, user) try: subscriber = Subscriber.objects.get( user=request.user.id) except Subscriber.DoesNotExist: return redirect( reverse('outside.views.create_profile')) next_url = request.session['next'] del request.session['next'] response.add('next', next_url) else: return response.throw_error( _("user has been disabled"), code=API_EXCEPTION_FORMERRORS).json() else: return response.throw_error( error={ 'username': '', 'password': '' }, code=API_EXCEPTION_FORMERRORS).json() return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() else: """login_message['error'] = _("invalid credentials") login_message['invalid_fields'] = form.errors""" #return HttpResponse('TEST') return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json() return response.json()
def login(request): logout(request) response = Epoxy(request) form = LoginForm( request.POST ) if form.is_valid(): user = authenticate(username=request.POST['username'], password=request.POST['password']) else: return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS ).json() if user is None: return response.throw_error(error="access denied" ).json() return response.json()
def publish_pin( request, pin_id ): response = Epoxy( request ) new_status = request.POST.get("new_status") try: if new_status in dict(Pin.PIN_STATUS_CHOICES): p=Pin.objects.get( id=pin_id ) p.status=new_status p.save() return response.json() else: return response.throw_error( error="status %s incorrect" % new_status).json() except Pin.DoesNotExist, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
def pin( request, pin_id ): # @todo: check pin permissions response = Epoxy( request ) if response.method == 'POST': form = EditPinForm( request.REQUEST ) if form.is_valid(): try: pin = Pin.objects.get( id=pin_id ) pin.title = form.cleaned_data['title'] pin.abstract = form.cleaned_data['abstract'] pin.content = form.cleaned_data['content'] pin.save() except Pin.DoesNotExist, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json() else: return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
def pages(request): # logger.info("Welcome to GLUEBOX api") response = Epoxy( request ) if response.method =='POST': form = AddPageForm( request.REQUEST ) if not form.is_valid(): return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() try: p_en = Page( title=form.cleaned_data['title_en'], language='EN', slug=form.cleaned_data['slug']) p_en.save() p_fr = Page( title=form.cleaned_data['title_fr'], language='FR', slug=form.cleaned_data['slug']) p_fr.save() except IntegrityError, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_INTEGRITY).json() response.add('object',[ p_en.json(), p_fr.json() ])
def publish_pin(request, pin_id): response = Epoxy(request) new_status = request.POST.get("new_status") try: if new_status in dict(Pin.PIN_STATUS_CHOICES): p = Pin.objects.get(id=pin_id) p.status = new_status p.save() return response.json() else: return response.throw_error(error="status %s incorrect" % new_status).json() except Pin.DoesNotExist, e: return response.throw_error(error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
def pin(request, pin_id): # @todo: check pin permissions response = Epoxy(request) if response.method == 'POST': form = EditPinForm(request.REQUEST) if form.is_valid(): try: pin = Pin.objects.get(id=pin_id) pin.title = form.cleaned_data['title'] pin.abstract = form.cleaned_data['abstract'] pin.content = form.cleaned_data['content'] pin.save() except Pin.DoesNotExist, e: return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json() else: return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
def change_password(request): response = Epoxy( request ) if request.method == 'POST': form = ChangePasswordForm( request.REQUEST ) if form.is_valid(): uPass1 = form.cleaned_data['password1'] uPass2 = form.cleaned_data['password2'] if uPass1 == uPass2: user = User.objects.get(username=form.cleaned_data['username']) user.set_password(uPass1) user.save() else: return response.throw_error( error={'password1':'the 2 pwd must be the same', 'password2':'the 2 pwd must be the same'}, code=API_EXCEPTION_FORMERRORS).json() else: return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() return response.json()
def test(request): response = Epoxy(request) response.add('full_path', request.get_host()) full_url = "%s://%s%s" % ( 'https' if request.is_secure() else 'http', request.get_host(), reverse('outside.views.confirm', args=("dsdsdsds", 12))) response.add('full_url', full_url) return response.json()
def pin_upload(request): response = Epoxy(request) d = dt.datetime.now() form = UploadPinForm(request.REQUEST) if not form.is_valid(): return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS) if len(form.cleaned_data['page_slug']) > 0: # attacch new pin to a selected page (both languages) response.add('page_slug', form.cleaned_data['page_slug']) try: page_en = Page.objects.get(slug=form.cleaned_data['page_slug'], language='EN') page_fr = Page.objects.get(slug=form.cleaned_data['page_slug'], language='FR') except Page.DoesNotExist: return response.throw_error( error=_("selected page does not exists"), code=API_EXCEPTION_FORMERRORS).json() response.add('page', [page_en.json(), page_fr.json()]) pin_path = response.add( 'path', "pins/%s-%s" % (d.year, (d.month if d.month > 10 else "0%s" % d.month))) absolute_pin_path = os.path.join(settings.MEDIA_ROOT, pin_path) try: if not os.path.exists(absolute_pin_path): os.makedirs( absolute_pin_path ) # throw an OS ERROR if exists... OR if it is not writable! except OSError, e: return response.throw_error(error="%s" % e, code=API_EXCEPTION_OSERROR).json()
def auth_login( request ): response = Epoxy( request ) form = LoginForm( request.POST ) try: if 'next' not in request.session: request.session['next'] = request.REQUEST['next'] except: pass if request.method == 'POST': if form.is_valid(): user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password']) if user is not None: if user.is_active: login(request, user) try: subscriber = Subscriber.objects.get(user=request.user.id) except Subscriber.DoesNotExist: return redirect( reverse('outside.views.create_profile') ) next_url = request.session['next'] del request.session['next'] response.add( 'next', next_url ) else: return response.throw_error( _("user has been disabled"), code=API_EXCEPTION_FORMERRORS).json() else: return response.throw_error( error={'username':'', 'password':''}, code=API_EXCEPTION_FORMERRORS).json() return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() else: """login_message['error'] = _("invalid credentials") login_message['invalid_fields'] = form.errors""" #return HttpResponse('TEST') return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() return response.json()
def test( request ): response = Epoxy( request ) response.add( 'full_path', request.get_host() ) full_url = "%s://%s%s"% ( 'https' if request.is_secure() else 'http', request.get_host(), reverse('outside.views.confirm', args=( "dsdsdsds", 12 ) ) ) response.add( 'full_url', full_url ) return response.json()
def pages(request): # logger.info("Welcome to GLUEBOX api") response = Epoxy(request) if response.method == 'POST': form = AddPageForm(request.REQUEST) if not form.is_valid(): return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json() try: p_en = Page(title=form.cleaned_data['title_en'], language='EN', slug=form.cleaned_data['slug']) p_en.save() p_fr = Page(title=form.cleaned_data['title_fr'], language='FR', slug=form.cleaned_data['slug']) p_fr.save() except IntegrityError, e: return response.throw_error(error="%s" % e, code=API_EXCEPTION_INTEGRITY).json() response.add('object', [p_en.json(), p_fr.json()])
def manage_single_object(request, model_name, pk): # logger.info("Welcome to GLUEBOX api") return Epoxy(request).single(Page, {'pk': pk}).json()
def page(request, page_id): return Epoxy(request).single(Page, {'id': page_id}).json()
def enquiry( request, enquiry_id ): response = Epoxy( request ) # check user permissions return response.single( Enquiry, {'pk':enquiry_id} ).json()
def page_by_slug(request, page_slug, page_language): return Epoxy(request).single(Page, { 'slug': page_slug, 'language': page_language }).json()
def index(request): # logger.info("Welcome to GLUEBOX api") return Epoxy(request).json()
def pins(request): response = Epoxy(request) if response.method == 'POST': form = AddPinForm(request.REQUEST) if not form.is_valid(): return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json() if len(form.cleaned_data['page_slug']) > 0: # attacch new pin to a selected page (both languages) response.add('page_slug', form.cleaned_data['page_slug']) try: page_en = Page.objects.get(slug=form.cleaned_data['page_slug'], language='EN') page_fr = Page.objects.get(slug=form.cleaned_data['page_slug'], language='FR') except Page.DoesNotExist: return response.throw_error( error=_("selected page does not exists"), code=API_EXCEPTION_FORMERRORS).json() response.add('page', [page_en.json(), page_fr.json()]) if len(form.cleaned_data['parent_pin_slug']) > 0: # attacch new pin to a selected pin (pin children, usually displayed on the right side, both languages) response.add('parent_pin_slug', form.cleaned_data['parent_pin_slug']) try: pin_en = Pin.objects.get( slug=form.cleaned_data['parent_pin_slug'], language='EN') pin_fr = Pin.objects.get( slug=form.cleaned_data['parent_pin_slug'], language='FR') except Pin.DoesNotExist, e: return response.throw_error( error=_("selected pin does not exists. Exception: %s" % e), code=API_EXCEPTION_FORMERRORS).json() response.add('pin', [pin_en.json(), pin_fr.json()]) #return response.queryset( Pin.objects.filter() ).json() try: p_en = Pin(title=form.cleaned_data['title_en'], language='EN', slug=form.cleaned_data['slug']) p_fr = Pin(title=form.cleaned_data['title_fr'], language='FR', slug=form.cleaned_data['slug']) if len(form.cleaned_data['parent_pin_slug']) > 0: p_en.parent = pin_en p_fr.parent = pin_fr p_en.save() p_fr.save() except IntegrityError, e: return response.throw_error(error={ 'slug': "Exception %s" % e }, code=API_EXCEPTION_INTEGRITY).json()
def manage_objects(request, model_name): # logger.info("Welcome to GLUEBOX api") return Epoxy(request).queryset(get_model("glue", model_name).objects.filter(), model_name=model_name).json()
def signups(request): # logger.info("Welcome to GLUEBOX api") response = Epoxy(request) if response.method == "POST": form = SignupForm(request.REQUEST) if not form.is_valid(): return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json() if (form.cleaned_data['password1'] != form.cleaned_data['password2']): return response.throw_error(error={ 'password1': 'Please enter and confirm your password', 'password2': 'Please enter and confirm your password' }, code=API_EXCEPTION_FORMERRORS).json() """else: if CheckPassword( form.cleaned_data['password1'] ) < 3 : return response.throw_error( error=_('The password stength is too weak.'), code=API_EXCEPTION_FORMERRORS, fields={'password1':'', 'password2':''} ).json() """ #Check email already exists in database if User.objects.filter(email=form.cleaned_data['email']).count() > 0: return response.throw_error( error=_('This email is already used in the database.'), code=API_EXCEPTION_FORMERRORS, fields={ 'email': '' }).json() try: created_user = User.objects.get( username=form.cleaned_data['username']) except User.DoesNotExist, e: # User creation created_user = User.objects.create( first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], username=form.cleaned_data['username'].lower(), email=form.cleaned_data['email'], is_active=False, ) created_user.set_password(str(form.cleaned_data['password2'])) created_user.save() else: #If the user already exists return response.throw_error( error=_('This username is already used'), code=API_EXCEPTION_INTEGRITY, fields={ "username": "" }).json() try: s = Subscriber.objects.get(user=created_user) except Subscriber.DoesNotExist, e: s = Subscriber(user=created_user, affiliation=form.cleaned_data['affiliation'], first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], status=form.cleaned_data['status'], accepted_terms=form.cleaned_data['accepted_terms'], description=form.cleaned_data['description'], email=form.cleaned_data['email'], email_confirmed=False) s.save() mail_send = send_confirmation_mail(subscriber=s, request=request, action="signup") if (mail_send == False): created_user.delete() return response.throw_error( error=_('This email does not exists'), code=API_EXCEPTION_INTEGRITY, fields={ "email": "" }).json()
def enquiry(request, enquiry_id): response = Epoxy(request) # check user permissions return response.single(Enquiry, {'pk': enquiry_id}).json()
def access_request(request): #return HttpResponse(translation.get_language(), 'text') response = Epoxy(request) if response.method == "POST": form = AccessRequestForm(request.REQUEST) if not form.is_valid(): return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS).json() try: AccessRequest.objects.get(user=request.user, enquete=form.cleaned_data['enquete']) except AccessRequest.DoesNotExist, e: # AccessRequest creation request_object = AccessRequest.objects.create( user=request.user, enquete=form.cleaned_data['enquete'], description=form.cleaned_data['description'], is_activated=False) path = '%s%s' % (django_settings.REANALYSEURL, reverse('admin:reanalyseapp_accessrequest_change', args=[request_object.id])) #Send mail to bequali admin : [email protected], guillaume.garcia, anne.both subject, from_email, to = _( 'bequali enquete request' ), '*****@*****.**', django_settings.EMAIL_ADMINS email_args = { 'prenom': form.cleaned_data['first_name'], 'nom': form.cleaned_data['last_name'], 'email': form.cleaned_data['email'], 'affiliation': form.cleaned_data['affiliation'], 'site': django_settings.OUTSIDE_SITE_NAME, 'description': form.cleaned_data['description'], 'enquete': form.cleaned_data['enquete'], 'url': path, 'REANALYSEURL': django_settings.REANALYSEURL + '/' + django_settings.OUTSIDE_SITE_NAME } email_args['action'] = 'ask_request' html_content = render_to_string('email/access_request.html', email_args) text_content = strip_tags( html_content ) # this strips the html, so people will have the text as well. msg = EmailMultiAlternatives(subject, text_content, from_email, to) msg.attach_alternative(html_content, "text/html") msg.send() to = form.cleaned_data['email'] subject = "beQuali demande d'acces notification" email_args['action'] = "ask_notification" html_content = render_to_string('email/access_request.html', email_args) text_content = strip_tags( html_content ) # this strips the html, so people will have the text as well. # create the email, and attach the HTML version as well. send_mail(subject, text_content, from_email, [to]) msg = EmailMultiAlternatives() msg.attach_alternative(html_content, "text/html") msg.send() except IntegrityError, e: return response.throw_error(error="%s" % e, code=API_EXCEPTION_INTEGRITY).json()
def signups(request): # logger.info("Welcome to GLUEBOX api") response = Epoxy( request ) if response.method=="POST": form = SignupForm( request.REQUEST ) if not form.is_valid(): return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() if(form.cleaned_data['password1'] != form.cleaned_data['password2']): return response.throw_error( error={'password1':'Please enter and confirm your password', 'password2':'Please enter and confirm your password'}, code=API_EXCEPTION_FORMERRORS).json() """else: if CheckPassword( form.cleaned_data['password1'] ) < 3 : return response.throw_error( error=_('The password stength is too weak.'), code=API_EXCEPTION_FORMERRORS, fields={'password1':'', 'password2':''} ).json() """ #Check email already exists in database if User.objects.filter( email = form.cleaned_data['email'] ).count() > 0 : return response.throw_error( error=_('This email is already used in the database.'), code=API_EXCEPTION_FORMERRORS, fields={'email':''}).json() try: created_user = User.objects.get( username = form.cleaned_data['username'] ) except User.DoesNotExist, e: # User creation created_user = User.objects.create( first_name = form.cleaned_data['first_name'], last_name = form.cleaned_data['last_name'], username = form.cleaned_data['username'].lower(), email = form.cleaned_data['email'], is_active = False, ) created_user.set_password(str(form.cleaned_data['password2'])) created_user.save() else: #If the user already exists return response.throw_error( error=_('This username is already used'), code=API_EXCEPTION_INTEGRITY, fields={"username":""}).json() try: s = Subscriber.objects.get( user=created_user ) except Subscriber.DoesNotExist, e: s = Subscriber( user = created_user, affiliation = form.cleaned_data['affiliation'], first_name = form.cleaned_data['first_name'], last_name = form.cleaned_data['last_name'], status = form.cleaned_data['status'], accepted_terms = form.cleaned_data['accepted_terms'], description = form.cleaned_data['description'], email = form.cleaned_data['email'], email_confirmed=False ) s.save() mail_send = send_confirmation_mail( subscriber=s, request=request, action="signup" ) if( mail_send == False ): created_user.delete() return response.throw_error( error=_('This email does not exists'), code=API_EXCEPTION_INTEGRITY, fields={"email":""}).json()
def access_request( request ): #return HttpResponse(translation.get_language(), 'text') response = Epoxy( request ) if response.method=="POST": form = AccessRequestForm( request.REQUEST ) if not form.is_valid(): return response.throw_error( error=form.errors,code=API_EXCEPTION_FORMERRORS).json() try: AccessRequest.objects.get( user = request.user, enquete=form.cleaned_data['enquete'] ) except AccessRequest.DoesNotExist, e: # AccessRequest creation request_object = AccessRequest.objects.create( user = request.user, enquete = form.cleaned_data['enquete'], description = form.cleaned_data['description'], is_activated = False ) path = '%s%s' % (django_settings.REANALYSEURL, reverse('admin:reanalyseapp_accessrequest_change', args=[request_object.id]) ) #Send mail to bequali admin : [email protected], guillaume.garcia, anne.both subject, from_email, to = _('bequali enquete request'),'*****@*****.**', django_settings.EMAIL_ADMINS email_args ={'prenom': form.cleaned_data['first_name'], 'nom': form.cleaned_data['last_name'], 'email': form.cleaned_data['email'], 'affiliation': form.cleaned_data['affiliation'], 'site': django_settings.OUTSIDE_SITE_NAME, 'description': form.cleaned_data['description'], 'enquete': form.cleaned_data['enquete'], 'url': path, 'REANALYSEURL': django_settings.REANALYSEURL+'/'+django_settings.OUTSIDE_SITE_NAME} email_args['action'] = 'ask_request' html_content = render_to_string('email/access_request.html', email_args) text_content = strip_tags(html_content) # this strips the html, so people will have the text as well. msg = EmailMultiAlternatives(subject, text_content, from_email, to) msg.attach_alternative(html_content, "text/html") msg.send() to = form.cleaned_data['email'] subject = "beQuali demande d'acces notification" email_args['action'] = "ask_notification" html_content = render_to_string('email/access_request.html', email_args) text_content = strip_tags(html_content) # this strips the html, so people will have the text as well. # create the email, and attach the HTML version as well. send_mail(subject, text_content, from_email, [to]) msg = EmailMultiAlternatives() msg.attach_alternative(html_content, "text/html") msg.send() except IntegrityError, e: return response.throw_error( error="%s"%e, code=API_EXCEPTION_INTEGRITY).json()
def signup(request, subscriber_id): return Epoxy(request).single(Signup, {'id': subscriber_id}).json()
def pins( request ): response = Epoxy( request ) if response.method =='POST': form = AddPinForm( request.REQUEST ) if not form.is_valid(): return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json() if len(form.cleaned_data['page_slug']) > 0: # attacch new pin to a selected page (both languages) response.add('page_slug',form.cleaned_data['page_slug']) try: page_en = Page.objects.get( slug=form.cleaned_data['page_slug'],language='EN') page_fr = Page.objects.get( slug=form.cleaned_data['page_slug'],language='FR') except Page.DoesNotExist: return response.throw_error( error=_("selected page does not exists"), code=API_EXCEPTION_FORMERRORS).json() response.add('page', [ page_en.json(), page_fr.json() ] ) if len(form.cleaned_data['parent_pin_slug']) > 0: # attacch new pin to a selected pin (pin children, usually displayed on the right side, both languages) response.add('parent_pin_slug',form.cleaned_data['parent_pin_slug']) try: pin_en = Pin.objects.get( slug=form.cleaned_data['parent_pin_slug'],language='EN') pin_fr = Pin.objects.get( slug=form.cleaned_data['parent_pin_slug'],language='FR') except Pin.DoesNotExist, e: return response.throw_error( error=_("selected pin does not exists. Exception: %s" % e), code=API_EXCEPTION_FORMERRORS).json() response.add('pin', [ pin_en.json(), pin_fr.json() ] ) #return response.queryset( Pin.objects.filter() ).json() try: p_en = Pin( title=form.cleaned_data['title_en'], language='EN', slug=form.cleaned_data['slug']) p_fr = Pin( title=form.cleaned_data['title_fr'], language='FR', slug=form.cleaned_data['slug']) if len(form.cleaned_data['parent_pin_slug']) > 0: p_en.parent = pin_en p_fr.parent = pin_fr p_en.save() p_fr.save() except IntegrityError, e: return response.throw_error( error={'slug':"Exception %s" % e}, code=API_EXCEPTION_INTEGRITY).json()
def test( request ): response = Epoxy( request ) return response.json()
def pin_by_slug(request, pin_slug, pin_language): return Epoxy(request).single(Pin, { 'slug': pin_slug, 'language': pin_language }).json()
def subscriber(request, subscriber_id): return Epoxy(request).single(Subscriber, {'id': subscriber_id}).json()