def create_new_user(self, user_keyname, password, set_user=True, **kwargs): logging.info('creating user with keyname %s' % user_keyname) user_entity = User(key_name=user_keyname, username=user_keyname) if password: user_entity.password = password if '@passtiche.appspot.com' not in user_keyname and not user_keyname.startswith('auto_gen'): deferred.defer(send_admin_email, subject='New %s User: %s' % ( self._settings['title'], user_keyname), message='User %s just signed up for an account' % user_keyname, user=user_keyname, user_agent=gae_utils.GetUserAgent(), url=gae_utils.GetUrl()) if '@' in user_keyname: user_entity.email = user_keyname #send_welcome_email(user_entity.email, 'Welcome to %s!' % self._settings['title']) deferred.defer(send_welcome_email, user_entity, 'Welcome to %s!' % self._settings['title'], _countdown=10) # 1300 22 minutes # optional args for k in ['first_name', 'last_name','phone','organization']: if kwargs.get(k): v = kwargs.get(k) setattr(user_entity, k, v) from utils import string as str_utils code = str_utils.genkey(length=7) user_entity.short_code = code user_entity.put() if set_user: self.set_current_user(user_entity) return user_entity
def pass_file(self, url): if self.user: user_keyname = self.user.key().name() else: user_keyname = '_no_user' safe_url = url key_name = "%s_%s" % (user_keyname, safe_url) pass_template = PassTemplate.get_by_key_name(key_name) if pass_template: new = False else: new = True pass_template = PassTemplate(key_name=key_name, url=url) if self.user: pass_template.owner = self.user from utils import string as str_utils code = str_utils.genkey(length=4) pass_template.short_code = code pass_template.put() # TODO: download and parse file to update it # TODO: check last modified, only update if not modified in over x hours if new or pass_template.modified < (datetime.datetime.now() - datetime.timedelta(hours=1)): logging.info('deferring update from passfile') deferred.defer(update_from_passfile, key_name) else: logging.info('this pass was modified too recently') return pass_template
def create(self): from model.passes import UserPass, PassTemplate self.pass_code = self.get_argument('pass_template') pass_template = PassTemplate.all().filter('short_code',self.pass_code).get() if not pass_template: raise ValueError('pass_template') self.pass_template = pass_template code = str_utils.genkey(length=5) self.user_pass = UserPass(key_name=code, code=code,owner=self.user, template=self.pass_template, pass_name=self.pass_template.name, pass_code=self.pass_template.short_code, action=self.action.lower()) if self.get_argument('owner_name',''): self.user_pass.owner_name = self.get_argument('owner_name') if self.get_argument('theme',''): self.user_pass.theme = self.get_argument('theme')
def create(self): from model.passes import UserPass, PassTemplate self.pass_code = self.get_argument('pass_template') pass_template = PassTemplate.all().filter('short_code', self.pass_code).get() if not pass_template: raise ValueError('pass_template') self.pass_template = pass_template code = str_utils.genkey(length=5) self.user_pass = UserPass(key_name=code, code=code, owner=self.user, template=self.pass_template, pass_name=self.pass_template.name, pass_code=self.pass_template.short_code, action=self.action.lower()) if self.get_argument('owner_name', ''): self.user_pass.owner_name = self.get_argument('owner_name') if self.get_argument('theme', ''): self.user_pass.theme = self.get_argument('theme')
def create_new_user(self, user_keyname, password, set_user=True, **kwargs): logging.info('creating user with keyname %s' % user_keyname) user_entity = User(key_name=user_keyname, username=user_keyname) if password: user_entity.password = password if '@passtiche.appspot.com' not in user_keyname and not user_keyname.startswith( 'auto_gen'): deferred.defer(send_admin_email, subject='New %s User: %s' % (self._settings['title'], user_keyname), message='User %s just signed up for an account' % user_keyname, user=user_keyname, user_agent=gae_utils.GetUserAgent(), url=gae_utils.GetUrl()) if '@' in user_keyname: user_entity.email = user_keyname #send_welcome_email(user_entity.email, 'Welcome to %s!' % self._settings['title']) deferred.defer(send_welcome_email, user_entity, 'Welcome to %s!' % self._settings['title'], _countdown=10) # 1300 22 minutes # optional args for k in ['first_name', 'last_name', 'phone', 'organization']: if kwargs.get(k): v = kwargs.get(k) setattr(user_entity, k, v) from utils import string as str_utils code = str_utils.genkey(length=7) user_entity.short_code = code user_entity.put() if set_user: self.set_current_user(user_entity) return user_entity
def create_or_update(self, name=None, slug=None, description=None, price=None, schedule=None, neighborhood_name=None, location=None, location_code=None, price_rating=None, api=False, image_url=None, url=None, user=None, organizationName=None, organizationUrl=None, **kwargs): self.user = user if url: # this does not allow file-based passes to have updated listings on Passtiche return self.pass_file(url) if not slug: slug = PassTemplate.get_slug(name) or 'event' keyname = slug if location_code: keyname += "-%s" % location_code if self.user: keyname += "~%s" % self.user.short_code logging.info(kwargs) if kwargs.get('new'): pass_template = None else: logging.info('getting pass template %s' % keyname) pass_template = PassTemplate.get_by_key_name(keyname) if pass_template: logging.info('found pass template %s' % keyname) if not pass_template: logging.info('creating new pass template') pass_template = PassTemplate(key_name=keyname, name=name, slug=slug) from utils import string as str_utils code = str_utils.genkey(length=4) pass_template.short_code = code if self.user and not self.user.is_admin(): pass_template.owner = self.user if not location and location_code: from model.activity import Location location = Location.get_by_key_name(location_code) if location: location_name = location.name else: location_name = '' searchFields = [search.TextField(name='name', value=name), search.TextField(name='code', value=code), search.TextField(name='keyname', value=keyname), search.TextField(name='loc', value=(location_code or '')), search.TextField(name='location_name', value=location_name), search.DateField(name='date', value=datetime.datetime.now().date())] if self.user: searchFields.append(search.TextField(name='owner', value=self.user.short_code)) pass_doc = search.Document(fields=searchFields) logging.info('adding pass doc to index') search.Index(name=_INDEX_NAME).put(pass_doc) elif name: pass_template.name = name if description: pass_template.description = description if price: pass_template.price = int(price) if price_rating is not None: pass_template.price_rating = price_rating if organizationName: pass_template.organizationName = organizationName if organizationUrl: if not organizationUrl.startswith('http://'): organizationUrl = 'http://%s' % organizationUrl pass_template.organizationUrl = organizationUrl if image_url: pass_template.image_url = image_url if schedule: pass_template.schedule = schedule pass_template = set_time_format(pass_template) # TODO: starts time if neighborhood_name: pass_template.neighborhood_name = neighborhood_name if location_code: if location: loc = location else: from model.activity import Location loc = Location.get_by_key_name(location_code) pass_template.location_code = loc.code pass_template.location_name = loc.name pass_template.get_location(reset=True) return pass_template
def create_or_update(self, name=None, slug=None, description=None, price=None, schedule=None, neighborhood_name=None, location=None, location_code=None, price_rating=None, api=False, image_url=None, url=None, user=None, organizationName=None, organizationUrl=None, **kwargs): self.user = user if url: # this does not allow file-based passes to have updated listings on Passtiche return self.pass_file(url) if not slug: slug = PassTemplate.get_slug(name) or 'event' keyname = slug if location_code: keyname += "-%s" % location_code if self.user: keyname += "~%s" % self.user.short_code logging.info(kwargs) if kwargs.get('new'): pass_template = None else: logging.info('getting pass template %s' % keyname) pass_template = PassTemplate.get_by_key_name(keyname) if pass_template: logging.info('found pass template %s' % keyname) if not pass_template: logging.info('creating new pass template') pass_template = PassTemplate(key_name=keyname, name=name, slug=slug) from utils import string as str_utils code = str_utils.genkey(length=4) pass_template.short_code = code if self.user and not self.user.is_admin(): pass_template.owner = self.user if not location and location_code: from model.activity import Location location = Location.get_by_key_name(location_code) if location: location_name = location.name else: location_name = '' searchFields = [ search.TextField(name='name', value=name), search.TextField(name='code', value=code), search.TextField(name='keyname', value=keyname), search.TextField(name='loc', value=(location_code or '')), search.TextField(name='location_name', value=location_name), search.DateField(name='date', value=datetime.datetime.now().date()) ] if self.user: searchFields.append( search.TextField(name='owner', value=self.user.short_code)) pass_doc = search.Document(fields=searchFields) logging.info('adding pass doc to index') search.Index(name=_INDEX_NAME).put(pass_doc) elif name: pass_template.name = name if description: pass_template.description = description if price: pass_template.price = int(price) if price_rating is not None: pass_template.price_rating = price_rating if organizationName: pass_template.organizationName = organizationName if organizationUrl: if not organizationUrl.startswith('http://'): organizationUrl = 'http://%s' % organizationUrl pass_template.organizationUrl = organizationUrl if image_url: pass_template.image_url = image_url if schedule: pass_template.schedule = schedule pass_template = set_time_format(pass_template) # TODO: starts time if neighborhood_name: pass_template.neighborhood_name = neighborhood_name if location_code: if location: loc = location else: from model.activity import Location loc = Location.get_by_key_name(location_code) pass_template.location_code = loc.code pass_template.location_name = loc.name pass_template.get_location(reset=True) return pass_template