def __init__(self, *args, **kwargs): print MailingList.query.all() Form.__init__(self, *args, **kwargs) subscribed = MailingList.query.filter(or_( MailingList.restricted==False, MailingList.users.contains(g.user))) self.lists.query = subscribed
def __init__(self, user, topic, attachments=None, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.user = user self.topic = topic if not attachments: attachments = [] self.attachments = attachments
def __init__(self, user, project, attachments=None, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.user = user self.project = project if not attachments: attachments = [] self.attachments = attachments
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) DEFAULT_RED = kwargs.get('red', 0) DEFAULT_GREEN = kwargs.get('green', 0) DEFAULT_BLUE = kwargs.get('blue', 0) # DEFAULT_COLOR = Color(rgb=(DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE)) print("RGBForm: color:%s,%s,%s" % (DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE))
def user_delete(username): title = "Delete user" if not ldap_user_exists(username=username): abort(404) form = Form(request.form) if form.validate_on_submit(): try: user = ldap_get_user(username=username) ldap_delete_entry(user['distinguishedName']) flash("User successfuly deleted.", "success") return redirect(url_for('core_index')) except ldap.LDAPError as e: error = e.message['info'].split(":", 2)[-1].strip() error = str(error[0].upper() + error[1:]) flash(error, "error") elif form.errors: flash("Some fields failed validation.", "error") return render_template("pages/user_delete.html", title=title, action="Delete user", form=form, username=username, parent=url_for('user_overview', username=username))
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.mess.choices = db.session.query(Kontrol.mes_id.distinct(), Kontrol.message).order_by(Kontrol.message).all() self.objs.choices = db.session.query(Kontrol.obj_id.distinct(), Kontrol.object).order_by(Kontrol.object).all() # self.category.choices = db.session.query(Kontrol.category.distinct(), Kontrol.category).order_by( # Kontrol.category).all() self.mess.choices.insert(0, (0, u'Все')) self.objs.choices.insert(0, (0, u'Все'))
def __init__(self, *args, **kwargs): """ Retrieve a user object from a User class using a YubiKey token @param args: Arguments, in order of definition in class @param kwargs: Keyword based Arguments, in any order """ Form.__init__(self, *args, **kwargs) self.user = None
def __init__(self, post, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.title.data = post.title self.body.data = post.body self.image_url.data = post.image_url self.slug.data = post.slug self.category_id.data = post.category_id self.category_id.choices = Category.get_list()
def __init__(self, *args, **kwargs): """ Change the password of a user object via a User class helper @param args: Arguments, in order of definition in class @param kwargs: Keyword based Arguments, in any order """ Form.__init__(self, *args, **kwargs) self.user = None
def __init__(self, *args, **kwargs): """ Register a new a Chat object via a Chat class helper @param args: Arguments, in order of definition in class @param kwargs: Keyword based Arguments, in any order """ Form.__init__(self, *args, **kwargs) self.channel = None
def __init__(self, original_nickname, *args, **kwargs): """ Constructor Args: original_nickname: the original nickname which is to be shown """ Form.__init__(self, *args, **kwargs) self.original_nickname = original_nickname
def __init__(self, user=None, author=None, feed_id=None, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.feeds.choices = [(f.id, f.name ) for f in user.feeds] if feed_id is not None: self.feeds.data = [feed_id] self.similar_authors.choices = [(a.id, a.__repr__()) for a in author.similar_authors()] self.similar_authors.choices.insert(0, (author.id, str(author)))
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) if 'subscription' in kwargs: self.subscription = kwargs['subscription'] # if self.subscription is not None: # self.enable_email.data = self.subscription.enable_email # self.email_frequency.data = self.subscription.email_frequency else: self.subscription = None
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) DEFAULT_RED = kwargs.get('red', 0) DEFAULT_GREEN = kwargs.get('green', 0) DEFAULT_BLUE = kwargs.get('blue', 0) DEFAULT_PERIOD = kwargs.get('period', 100) DEFAULT_MODE = kwargs.get('colormode', 0) print("SnakeForm: bgcolor:%s,%s,%s period:%s mode:%s" % (DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE, DEFAULT_PERIOD, DEFAULT_MODE))
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.project.query = Project.query.order_by(Project.name) if 'obj' in kwargs: self.id.data = kwargs['obj'].id self.subject.query = Subject.query.filter(Subject.project==kwargs['obj'].project) else: self.subject.query = Subject.query self.subject.query = self.subject.query.order_by(Subject.name)
def __init__(self, *args, **kwargs): images = [] try: album = kwargs['obj'] images = album.images except KeyError: pass Form.__init__(self, *args, **kwargs) self.coverImageId.choices = [(image.id, image.id) for image in images]
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.container.choices = [("0", "None")] self.container.choices.extend( [(str(item['Id']), item['Name']) for item in lsmsd_api.get_items()] ) self.usage.choices.extend( [i.value for i in list(UsagePolicy)] )
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) # Set hidden data if not self.originator_type.data and originator_type is not None: self.originator_type.data = originator_type if not self.originator_id.data and originator_id is not None: self.originator_id.data = originator_id if not self.next.data: self.next.data = get_redirect_target() or ''
def __init__(self, user, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.email.data = user.email self.name.data = user.name self.nickname.data = user.nickname self.role.data = unicode(user.role) self.address.data = user.address self.phone.data = user.phone self.timezone.data = user.timezone self.lang.data = user.lang
def delete(shelter_id): shelter = Shelter.query.filter_by(id=shelter_id).one() form = Form() if form.validate_on_submit(): db.session.delete(shelter) db.session.commit() flash(shelter.name + " was deleted from the database.") return redirect(url_for("shelters.list_all")) return render_template("shelters/delete.jinja2", form=form, shelter=shelter)
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.choice_list1.choices = self.choice_list2.choices = self.choice_list3.choices = [ (u'', u'---------'), (u'本系推研', u'本系推研'), (u'本系直博', u'本系直博'), (u'出国', u'出国'), (u'深研院', u'深研院'), (u'外系推研', u'外系推研'), (u'外校推研', u'外校推研'), (u'其它', u'其它')]
def delete(puppy_id): puppy = Puppy.query.filter_by(id=puppy_id).one() # we can use a generic form, since there are no fields form = Form() if form.validate_on_submit(): db.session.delete(puppy) db.session.commit() flash(puppy.name + " was put to sleep.") return redirect(url_for("puppies.list_all")) return render_template("puppies/delete.jinja2", form=form, puppy=puppy)
def logout(): form = Form() if form.validate_on_submit(): logout_user() if 'redirect_to' in session: redirect_to = session['redirect_to'] session.pop('redirect_to', None) flash(gettext('Signed out successfully.')) else: flash(gettext('Invalid Action'), 'error') return redirect(url_for('index'))
def delete(adopter_id): adopter = Adopter.query.filter_by(id=adopter_id).one() # we can use a generic form, since there are no fields form = Form() if form.validate_on_submit(): db.session.delete(adopter) db.session.commit() flash(adopter.name + " was deleted from the database.") return redirect(url_for("adopters.list_all")) return render_template("adopters/delete.jinja2", form=form, adopter=adopter)
def __init__(self, user, todo, attachments=None, *args, **kwargs): """ class init :param user: :param todo: :param attachment: :param args: :param kwargs: """ if not attachments: attachments = [] Form.__init__(self, *args, **kwargs) self.user = user self.todo = todo self.attachments = attachments
def validate(self): """ Validaion of the form, checking user password hash with stored one. :return: True if the form is correct and the user as given correct credentials, False otherwise """ cust_logger.info("Trying to validate form") rv = Form.validate(self) if not rv: return False user = User.objects(username=self.username.data.lower()).first() if user is None: cust_logger.info("Invalid username entered") self.password.errors.append('Unknown username or password') return False if not user.check_password(self.password.data): cust_logger.info("Invalid password entered") self.password.errors.append('Unknown username or password') return False self.user = user return True
def validate(self): rv = Form.validate(self) if not rv: print 'not OK' return False return True
def validate(self, regCode): rv = Form.validate(self) if not rv: return False # check if user has given valid lol id summonerid = self.bslol.getSummonerId(self.summonername.data) if summonerid == None: self.summonername.errors.append("You've entered and invalid summoner id") return False # check if user has givne a valid twitter id # FIX: we must send reg_code to the dm twtRetCode = self.bstwt.sendDM(self.twtid.data, regCode) if twtRetCode != 0: if twtRetCode == 34: # error code 34: twitter user does not exist self.twtid.errors.append("You've entered an invalid Twitter ID!") return False elif twtRetCode == 150: # error code 150: not following us self.twtid.errors.append('To verify your Twitter account, we need to send you a direct message. Follow @bsbot_lol now!') return False else: self.twtid.errors.append('Error connecting to Twitter :(') return False return True
def validate(self): rv = Form.validate(self) username = self.username.data password = self.password.data if not rv: # invalid information self.username.errors.append('Something gone wrong') return False if not User.check_username(username): # user does NOT exist self.username.errors.append('Invalid username and/or password') return False if not User.check_password(username, password): # incorrect password self.password.errors.append('Invalid username and/or password') return False user = User(username=username) if user is None: # user could not create for some reason self.username.errors.append('Invalid username and/or password') return False self.user = user return True
def validate(self): if not Form.validate(self): return False valid=True #assume success email = mongo.db.users.find({'email':self.email.data.lower()}).count() username = mongo.db.users.find({'username':self.username.data.lower()}).count() if email>0: self.email.errors.append("That email is already taken") valid=False if username>0: self.username.errors.append("That username is already taken") valid=False if(len(self.password.data)<8): self.password.errors.append("Passwords must be at least 8 characters long") self.password1.errors.append("") valid=False else: self.salt = uuid.uuid4().bytes self.password.data = hashlib.sha512(self.password.data.encode('utf-8') + self.salt).digest() self.password1.data = hashlib.sha512(self.password1.data.encode('utf-8') + self.salt).digest() if(self.password.data!=self.password1.data): self.password.errors.append("The passwords do not match") self.password1.errors.append("") valid=False return valid
def validate(self): outcome = True rv = Form.validate(self) if not rv: outcome = False if self.name.data == '': self.name.errors.append('Campo obbligatorio') outcome = False if self.surname.data == '': self.surname.errors.append('Campo obbligatorio') outcome = False if self.mail.data == '': self.mail.errors.append('Campo obbligatorio') outcome = False else: mail = User.query.filter_by(email=self.mail.data).first() if mail is not None: self.mail.errors.append( 'E-Mail presente in database, inserirne una differente') outcome = False found = False for v, _ in self.goal.choices: if self.goal.data == v: found = True break if found == False: del self.goal.errors[:] self.goal.errors.append('Seleziona una destinazione') return outcome
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.project = None
def validate(self): rs = Form.validate(self) return rs
def __init__(self, original_role, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.the_original_id = "" print ' . . . . . . . . . . . . . . .' + str(original_role.id) if original_role.id is not None: self.the_original_id = original_role.id.upper()
def validate(self): if not Form.validate(self): return False return True
def __init__(self, *args, **kwargs): kwargs['csrf_enabled'] = False Form.__init__(self, *args, **kwargs)
def validate(self): rv = Form.validate(self) if not rv: return False validate_email = True validate_name = True validate_twitter = True if self.twitter.data and '@' in self.twitter.data: self.twitter.data = self.twitter.data.replace('@', '') name = self.name.data email = self.email.data twitter = self.twitter.data current_name = current_user.name current_email = current_user.email current_twitter = current_user.twitter_handle if email == current_email: validate_email = False if name == current_name: validate_name = False if twitter == current_twitter: validate_twitter = False if not re.match("^[a-zA-Z0-9_-]+$", name): self.name.errors.append('Only letters, digits, dashes, underscores allowed') return False if not re.search("[a-zA-Z0-9]", name): self.name.errors.append('Must have at least one letter or number') return False if not NAME_LEN_MIN < len(name) + 1 < NAME_LEN_MAX: self.name.errors.append('Must be between %s and %s characters'% (NAME_LEN_MIN,NAME_LEN_MAX)) return False if name.lower() in ILLEGAL_NAMES: self.name.errors.append('Name not allowed. Please try another.') self.name.data = '' return False user = User.find_user_by_name(name).first() if validate_name and user is not None: name = User.make_unique_name(name) self.name.errors.append('Name already taken, perhaps %s suits you?' % name) self.name.data = name return False if validate_email and self.email.data and self.email.validate(self.email.data): user = User.find_user_by_email(self.email.data).first() if user is not None: self.email.errors.append('Email address already used') return False if validate_twitter and self.twitter.data: user = User.find_user_by_twitter(self.twitter.data).first() if user is not None: self.twitter.errors.append('Twitter username already used') return False return True
def userlist(page=1, pending=False, sponsored=False, rolloffs=False): # We need to make sure sponsors without admin/labstaff permissions don't go # browsing through all the users data domains = g.user.get_domains() if ((sponsored and 'sponsor' not in domains) or (not sponsored and (not g.user_is_labstaff) and (not g.user_is_admin)) or (rolloffs and (not g.user_is_labstaff) and (not g.user_is_admin))): flash("Unauthorized.") return redirect('index') if (pending or rolloffs) and request.method == "POST": form = Form(request.form) if not form.validate(): flash("There was an error with your submission.") redirect(request.url) users = [ user for user, value in request.form.iteritems() if value == 'approve' ] if rolloffs: users = [user for user, value in request.form.iteritems()] users = [User.username == user for user in users] if len(users) > 0: query = User.query.filter(or_(*users)) if sponsored: # Filter and make sure we only get this sponsors users, for security query = query.filter(User.sponsor == g.user.username) users = query.all() for user in users: if sponsored: user.status = 'pending_labstaff' elif rolloffs: user.status = 'pending_rolloff' else: user.status = 'pending_create' db.session.add(user) db.session.commit() # here we handle denying accounts: users = [ user for user, value in request.form.iteritems() if value == 'deny' ] users = [User.username == user for user in users] if len(users) > 0: query = User.query.filter(or_(*users)) if sponsored: query = query.filter(User.sponsor == g.user.username) users = query.all() for user in users: # send rejection emails, silent reject if comments are empty if sponsored: mail.sponsor_reject(user) elif g.user_is_admin: mail.admin_reject(user) # drop rejected users db.session.delete(user) db.session.commit() query = User.query sort = 'username' sort_col = User.username sort_dir = asc cols = { 'username': User.username, 'uid': User._uid, 'sponsor': User.sponsor, 'email': User.email, 'name': User.last_name, 'last_name': User.last_name, 'first_name': User.first_name, 'status': User.status, 'grad_date': User._grad_date } # Let's make the filter form class FilterForm(Form): pass for field, col in cols.iteritems(): setattr(FilterForm, field, TextField()) filter_form = FilterForm(request.args) if 'sort' in request.args: if request.args['sort'] in cols: sort = request.args['sort'] sort_col = cols[request.args['sort']] if 'dir' in request.args and request.args['dir'] == 'desc': sort_dir = desc if sponsored: query = query.filter(User.sponsor == g.user.username) if pending: query = query.filter(User.status == 'pending_sponsor') else: query = query.filter(User.status != 'pending_sponsor') elif rolloffs: now = date.today() query = query.filter(User._grad_date <= now) query = query.filter(User.status != 'pending_sponsor') query = query.filter(User.status != 'pending_labstaff') query = query.filter(User.status != 'pending_rolloff') else: if pending: query = query.filter(User.status == 'pending_labstaff') # else: # query = query.filter(User.status != 'pending_labstaff') # query = query.filter(User.status != 'pending_sponsor') for field, col in cols.iteritems(): if field in request.args: if request.args[field].strip() == "": continue query = query.filter(col.like(request.args[field].strip())) query = query.order_by(sort_dir(sort_col)) page = query.paginate(page) if pending: # Patch a Form. This allows us to keep our CSRF protection class F(Form): pass for user in page.items: setattr( F, user.username, RadioField(choices=[('approve', 'Approve'), ('postpone', 'Postpone'), ('deny', 'Deny')], validators=[validators.Required()])) # Flask-WTForms likes to pull data from request.form. Force it not to. form = F(ImmutableMultiDict()) # We do this after the fact so WTForms can do some of its binding for user in page.items: user.radio = getattr(form, user.username) user.radio.data = 'postpone' if sponsored: template = 'sponsorship_requests.html' else: template = 'list_pending_users.html' elif rolloffs: class rolloffCheckbox(Form): pass for user in page.items: setattr(rolloffCheckbox, user.username, BooleanField()) form = rolloffCheckbox(ImmutableMultiDict()) for user in page.items: user.checkbox = getattr(form, user.username) template = 'list_upcoming_rolloffs.html' else: form = Form() if sponsored: template = 'sponsored_users.html' else: template = 'userlist.html' return render_template(template, page=page, sort=sort, sort_dir='asc' if sort_dir == asc else 'desc', form=form, filter_form=filter_form)
def validate(self): if not Form.validate(self): return False if not self.by_title.data and not self.by_author.data: return False return True
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.container.choices = [("0", "None")] self.container.choices.extend([(str(item['Id']), item['Name']) for item in lsmsd_api.get_items()])
def __init__(self, lease, *args, **kwargs): Form.__init__(self, *args, **kwargs) if lease is not None: self.the_official_id = lease.official_id
def __init__(self, user, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.original_username = user.username self.original_email = user.email
def validate(self): return Form.validate(self)
def __init__(self, **kwargs): self.edit = kwargs.get("edit", False) Form.__init__(self, **kwargs)
def validate(self): if Form.validate(self): if not User.query.filter_by( username=self.username.data.lower()).count(): return True return False
def __init__(self, stored_file, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.stored_file = stored_file
def validate(self): if Form.validate(self): username = self.username.data password = self.password.data self.user = User.check_auth(username, password) return self.user is not None
def __init__(self, user, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.original_nickname = user.nickname
def __init__(self, suggest=True, *args, **kwargs): Form.__init__(self, *args, **kwargs) if suggest: self.addSuggestions()
def get_csrf_headers(): form = Form() return {'X-CSRF-Token': form.csrf_token._value()}
def validate(self): rv = Form.validate(self) if not rv: return False return True
def __init__(self, *args, **kwargs): self._form_name = type(self).__name__ Form.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.user = None
def is_submitted(self): return Form.is_submitted(self) and request.form.get( "form_name") == self._form_name
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) if not self.next.data: self.next.data = get_redirect_target() or ''
def hidden_tag(self, *args, **kwargs): self.form_name.data = self._form_name return Form.hidden_tag(self, *args, **kwargs)
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.item = None
def __init__(self, original_nickname, *args, **kwargs): Form.__init__(self, *args, **kwargs) self.original_nickname = original_nickname
def __init__(self, *args, **kwargs): Form.__init__(self) self.metas.choices = [(meta.meta_id, meta.meta_name) for meta in Meta.query.order_by('meta_name')]