def save(self, *args): instance = None if self.params.key: instance = Dolg.get(self.params.key) form=DolgForm(data=self.request.POST) if form.is_valid(): od = None na = None if form.cleaned_data['Type']=='1': na = Person.get(form.cleaned_data['Party']) od = self.User else: od = Person.get(form.cleaned_data['Party']) na = self.User if instance: instance.Note = form.cleaned_data["Note"] instance.Kolicina = float(form.cleaned_data["Ammount"]) instance.Od = od instance.Na = na instance.DodadenOd = self.User instance.put() else: instance = Dolg.CreateNew(od=od, na=na, kolicina= form.cleaned_data["Ammount"], note=form.cleaned_data["Note"], dodaden_od=self.User, _isAutoInsert=True) self.status = 'Dolg is saved' try: self.send_email(instance, self.get_edit_body(instance, nov=not self.params.key)) self.status+=' and message is sent' except Exception, ex: import logging logging.error(ex.message) self.status+=' but message is not sent. Probably the party does not have an email added in the profile' self.redirect(DolgController.get_url())
def JanrainAuth(self, *args): token = self.params.token url = 'https://rpxnow.com/api/v2/auth_info' args = { 'format': 'json', 'apiKey': '4a593fc2715670ab6a03b40653054858ffdc34a2', 'token': token } r = urlfetch.fetch( url=url, payload=urllib.urlencode(args), method=urlfetch.POST, headers={'Content-Type': 'application/x-www-form-urlencoded'}) json = simplejson.loads(r.content) if json['stat'] == 'ok': person = Person.gql( "WHERE UserName= :u AND AuthenticationType= :auth", u=json['profile']['preferredUsername'], auth=json['profile']['providerName']).get() if not person: name = json['profile'].has_key( 'givenName') and json['profile']['givenName'] or '' surname = json['profile'].has_key('familyName') and json[ 'profile']['name']['familyName'] or '' display = json['profile'].has_key( 'displayName') and json['profile']['displayName'] or '' email = json['profile'].has_key( 'email') and json['profile']['email'] or None photo = json['profile'].has_key( 'photo') and json['profile']['photo'] or None if not name and not surname and display: arr = display.split(' ') name = arr[0] surname = len(arr) > 1 and arr[1] or '' person = Person.CreateNew( uname=json['profile']['preferredUsername'], name=name, surname=surname, email=email, password='******', public=True, notify=True, authType=json['profile']['providerName'], photoUrl=photo, _autoSave=True) self.login_user2(person) self.status = 'Welcome ' + person.UserName if self.params.redirect_url: self.redirect(self.params.redirect_url) else: self.redirect('/') else: self.status = 'Not Valid Login' self.respond()
def post(self): self.SetTemplate(templateName='Thanks.html') try: user = Person(UserName=self.g('UserName'), Email=self.g('Email'), Name=self.g('Name'), Surname=self.g('Surname'), Password=self.g('Password'), Public=self.g('Public') == 'on' and True or False, Notify=self.g('Notify') == 'on' and True or False) if (self.request.get('Notify') == None and self.request.get('Notify') == 'on'): user.Notify = True else: user.Notify = False if (self.request.get('Public') == None and self.request.get('Public') == 'on'): user.Public = True else: user.Public = False user.put() self.respond(locals()) except Exception, ex: self.status = ex self.redirect(AddUserController.get_url())
def base_params(self): financialCard = None refUser = None allUsers = Person.all().fetch(100) if self.g('UserKey'): refUser = Person.get(self.request.get('UserKey')) if refUser: financialCard = am.FinancialCard.GetByOwnerByUser(self.User, refUser) #if there is no initial balance or recalculation is asked , run recalculate if financialCard and (financialCard.Balance == None or (self.g('op') and self.g('op') == 'recalc')): financialCard.Recalculate(True) else: self.status = 'There is not transaction card for this User' else: self.status = 'Invalid Data' return {"financialCard":financialCard, "refUser":refUser, "allUsers":allUsers}
def get(self): if self.User: userKey = self.g('key') if self.g('op')=='src' and self.g('searchWord'): self.SetTemplate(handlerType, 'SearchUsers.html') pass elif userKey: user = Person.get(userKey) if user: profile = user.owner_profiles.get() if not profile: profile = pm.Profile.CreateNew(owner=user, userName=user.Email, _isAutoInsert=True) self.respond({'profile':profile, 'profileImages': self.getImageKeys(profile)}) #self.response.out.write(user.Name+'<br/>'+user.Surname) else: self.status = 'Such User does not exists' self.respond() else: profile = self.User.owner_profiles.get() if not profile: profile = pm.Profile.CreateNew(owner=self.User, userName=self.User.Email, _isAutoInsert=True) self.respond({'profile':profile, 'profileImages': self.getImageKeys(profile)}) else: self.status = "Must be loged in order to view someones profile" self.redirect('/Login')
def login_user_local(self, uname, passwd): self.logout_user() user = Person.GetUser(uname, passwd, 'local') if user: self.session['user']= user; return True else: return False
def index(self, *args): self.SetTemplate(templateName="Dolg_index.html") result ={} index = 0; count=20 try: index = int(self.params.index) count = int(self.params.count) except: pass if self.params.key: p=Person.get(self.params.key) d1 = Dolg.gql("WHERE Od = :me and Na = :on AND Deleted=False", me=self.User, on = p).fetch(limit=100, offset=0) d2 = Dolg.gql("WHERE Od = :on and Na = :me AND Deleted=False", me=self.User, on = p).fetch(limit=100, offset=0) result['DolgList']= d1+d2 result['Party']=p else: result['DolgList'] = Dolg.gql('WHERE Od = :k AND Deleted=False', k=self.User).fetch(limit=count, offset=index)+Dolg.gql('WHERE Na = :k AND Deleted=False', k=self.User).fetch(limit=count, offset=index) result['Totals'] = Totals(result['DolgList'], self.User) result['DolgForm']= DolgForm();result['op']= 'update'; result['DolgList'] = sorted(result['DolgList'], key=lambda x:x.Datum, reverse=True) nextIndex = index+count; previousIndex = index<=0 and -1 or (index-count>0 and 0 or index-count) from Forms.BaseForms import InvitationForm result['InvitationFormK'] = InvitationForm() result.update(locals()) return result
def post( self ): self.SetTemplate(templateName='Thanks.html') try: user = Person( UserName = self.g('UserName'), Email=self.g( 'Email' ), Name=self.g( 'Name' ), Surname=self.g( 'Surname' ), Password=self.g( 'Password' ), Public=self.g( 'Public' ) == 'on' and True or False, Notify=self.g( 'Notify' ) == 'on' and True or False ) if ( self.request.get( 'Notify' ) == None and self.request.get( 'Notify' ) == 'on' ): user.Notify = True else: user.Notify = False if ( self.request.get( 'Public' ) == None and self.request.get( 'Public' ) == 'on' ): user.Public = True else: user.Public = False user.put() self.respond( locals() ) except Exception, ex: self.status = ex self.redirect(AddUserController.get_url())
def post(self): self.SetTemplate(templateName="Thanks.html") try: user = Person( UserName=self.g("UserName"), Email=self.g("Email"), Name=self.g("Name"), Surname=self.g("Surname"), Password=self.g("Password"), Public=self.g("Public") == "on" and True or False, Notify=self.g("Notify") == "on" and True or False, ) if self.request.get("Notify") == None and self.request.get("Notify") == "on": user.Notify = True else: user.Notify = False if self.request.get("Public") == None and self.request.get("Public") == "on": user.Public = True else: user.Public = False user.put() self.respond(locals()) except Exception, ex: self.status = ex self.redirect(AddUserController.get_url())
def get( self ): self.SetTemplate(handlerType, 'admin_ListUsers.html') if self.User and self.User.IsAdmin: offset = self.request.get( 'Offset' ) or 0 result = Person.all().fetch( limit=30, offset=offset ) self.respond( locals() ) else: self.status = 'You Must be Loged in as administrator in order to list the users' self.redirect( LoginHandler.get_url() )
def get(self): self.SetTemplate(handlerType,'admin_ListUsers.html') if(self.User and self.User.IsAdmin): querry = Person.gql("WHERE IsAdmin =:v", v=True) result=querry.fetch(1000) self.respond({'result':result}) else: self.status(messages.not_allowed_to_access) self.redirect(LoginHandler.get_url())
def get(self, *args): allUsers = Person.all() ownerAccount = None isCash = False if self.g('OwnerAccount'): if self.g('op') == 'new': ownerAccount = am.Account.get(self.g('OwnerAccount')) if str(ownerAccount.Owner.key()) != str(self.User.key()): ownerAccount = None elif self.g('op') == 'search': allUsers = Person.all() self.respond(locals()) elif self.g('op') == 'cash': IsCash=True self.respond(locals()) else: self.status = message.invalid_data_passed self.redirect(AccountHandler.get_url())
def get(self): result = None if self.User: if self.User.owner_accounts.get(): transaction_results = self.User.owner_accounts.get().owner_account_transactions.fetch(limit=10) allUsers = Person.all() self.respond(locals()) else: self.status = 'You Must be LogedIn in order to see your Balance' self.redirect(LoginHandler.get_url())
def post(self, *args): d = self.base_params() if self.request.get('UserKey'): if self.request.get('From') and self.request.get('From'): zd = Person.get(self.request.get('UserKey')) #search_result = am.Dolg.gql( 'WHERE (zel = :zd OR dal = :zd) AND owner:ow', zd=zd, ow=self.User ).fetch( limit=100 ) transaction_results = am.Transaction.all().filter('OwnerAccouny=', self.User).filter('ReferentAccouny=', zd).fetch(limit=100) #search_result = db.GqlQuery("SELECT * FROM Dolg WHERE owner= :1 AND (zel= :2 OR dal= :2)", self.User, zd) d['transaction_results'] = transaction_results self.respond(d)
def get(self): if(self.User and self.User.IsAdmin): g = self.request.get if(g('search')): query = Person.all() #query.filter('Name=', g('search')) self.respond({'result':query.fetch(limit=100)}) #self.response.out.write(str(query.fetch(limit=20))) else: self.respond() else: self.redirect(LoginHandler.get_url())
def get(self): if(self.User and self.User.IsAdmin): if(self.g('search')): query = Person.all() #query.filter('Name=', g('search')) self.respond({'result':query.fetch(limit=100)}) #self.response.out.write(str(query.fetch(limit=20))) else: self.respond() else: self.status = messages.not_allowed_to_access self.redirect(LoginHandler.get_url())
def get(self): if(self.User and self.User.IsAdmin): g = self.request.get if(g('search')): query = Person.all() query.filter('Name=', g('search')) persons = query.fetch(limit=100) self.respond({'result':persons}) else: self.respond() else: self.redirect(LoginHandler.get_url())
def post(self): if self.User: d = self.base_params() if self.request.get('UserKey'): if self.request.get('From') and self.request.get('From'): zd = Person.get(self.request.get('UserKey')) #search_result = am.Dolg.gql( 'WHERE (zel = :zd OR dal = :zd) AND owner:ow', zd=zd, ow=self.User ).fetch( limit=100 ) transaction_results = am.Transaction.all().filter('OwnerAccouny=', self.User).filter('ReferentAccouny=', zd).fetch(limit=100) #search_result = db.GqlQuery("SELECT * FROM Dolg WHERE owner= :1 AND (zel= :2 OR dal= :2)", self.User, zd) d['transaction_results'] = transaction_results self.respond(d) else: self.status = 'You must be loged in in order to use the Accounting Service' self.redirect(LoginHandler.get_url())
def JanrainAuth(self, *args): token = self.params.token url = 'https://rpxnow.com/api/v2/auth_info' args = { 'format': 'json', 'apiKey': '4a593fc2715670ab6a03b40653054858ffdc34a2', 'token': token } r = urlfetch.fetch(url=url, payload=urllib.urlencode(args), method=urlfetch.POST, headers={'Content-Type':'application/x-www-form-urlencoded'} ) json = simplejson.loads(r.content) if json['stat'] == 'ok': person = Person.gql("WHERE UserName= :u AND AuthenticationType= :auth", u=json['profile']['preferredUsername'], auth=json['profile']['providerName']).get() if not person: name = json['profile'].has_key('givenName') and json['profile']['givenName'] or '' surname = json['profile'].has_key('familyName') and json['profile']['name']['familyName'] or '' display = json['profile'].has_key('displayName') and json['profile']['displayName'] or '' email = json['profile'].has_key('email') and json['profile']['email'] or None photo = json['profile'].has_key('photo') and json['profile']['photo'] or None if not name and not surname and display: arr = display.split(' ') name = arr[0]; surname = len(arr)>1 and arr[1] or '' person = Person.CreateNew(uname=json['profile']['preferredUsername'], name=name, surname=surname, email = email, password='******', public=True, notify=True, authType=json['profile']['providerName'], photoUrl=photo, _autoSave=True) self.login_user2(person) self.status = 'Welcome '+person.UserName if self.params.redirect_url: self.redirect(self.params.redirect_url) else: self.redirect('/') else: self.status = 'Not Valid Login' self.respond()
def get(self, *args): result = None if self.User.owner_accounts.get(): transaction_results = self.User.owner_accounts.get().owner_account_transactions.fetch(limit=10) allUsers = Person.all() self.respond(locals())
def JanrainAuth(self, *args): token = self.params.token url = "https://rpxnow.com/api/v2/auth_info" args = {"format": "json", "apiKey": "4a593fc2715670ab6a03b40653054858ffdc34a2", "token": token} r = urlfetch.fetch( url=url, payload=urllib.urlencode(args), method=urlfetch.POST, headers={"Content-Type": "application/x-www-form-urlencoded"}, ) json = simplejson.loads(r.content) if json["stat"] == "ok": person = Person.gql( "WHERE UserName= :u AND AuthenticationType= :auth", u=json["profile"]["preferredUsername"], auth=json["profile"]["providerName"], ).get() if not person: name = json["profile"].has_key("givenName") and json["profile"]["givenName"] or "" surname = json["profile"].has_key("familyName") and json["profile"]["name"]["familyName"] or "" display = json["profile"].has_key("displayName") and json["profile"]["displayName"] or "" email = json["profile"].has_key("email") and json["profile"]["email"] or None photo = json["profile"].has_key("photo") and json["profile"]["photo"] or None if not name and not surname and display: arr = display.split(" ") name = arr[0] surname = len(arr) > 1 and arr[1] or "" if len(args) == 1: person = Person.get(args[0]) person.UserName = (json["profile"]["preferredUsername"],) person.Name = (name,) person.Surname = (surname,) person.Email = (email,) person.Password = ("openid",) person.Public = (True,) person.Notify = (True,) person.AuthenticationType = (json["profile"]["providerName"],) person.PhotoUrl = (photo,) person.put() else: person = Person.CreateNew2( uname=json["profile"]["preferredUsername"], name=name, surname=surname, email=email, password="******", public=True, notify=True, authType=json["profile"]["providerName"], photoUrl=photo, _autoSave=True, ) self.login_user2(person) self.status = "Welcome " + person.UserName if self.params.redirect_url: self.redirect(self.params.redirect_url) else: self.redirect("/") else: self.status = "Not Valid Login" self.respond()