コード例 #1
0
ファイル: fileadmin.py プロジェクト: hellwen/pyservice
    def rename(self):
        """
            Rename view method
        """
        path = request.args.get('path')

        if not path:
            return redirect(url_for('.index'))

        base_path, full_path, path = self._normalize_path(path)

        return_url = self._get_dir_url('.index', op.dirname(path))

        if not self.can_rename:
            flash(gettext('Renaming is disabled.'))
            return redirect(return_url)

        if not op.exists(full_path):
            flash(gettext('Path does not exist.'))
            return redirect(return_url)

        form = NameForm(request.form, name=op.basename(path))
        if form.validate_on_submit():
            try:
                dir_base = op.dirname(full_path)
                filename = secure_filename(form.name.data)

                os.rename(full_path, op.join(dir_base, filename))
                flash(gettext('Successfully renamed "%(src)s" to "%(dst)s"',
                      src=op.basename(path),
                      dst=filename))
            except Exception, ex:
                flash(gettext('Failed to rename: %(error)s', error=ex), 'error')

            return redirect(return_url)
コード例 #2
0
ファイル: fileadmin.py プロジェクト: hellwen/pyservice
    def upload(self, path=None):
        """
            Upload view method

            :param path:
                Optional directory path. If not provided, will use the base directory
        """
        # Get path and verify if it is valid
        base_path, directory, path = self._normalize_path(path)

        if not self.can_upload:
            flash(gettext('File uploading is disabled.'), 'error')
            return redirect(self._get_dir_url('.index', path))

        form = UploadForm(self)
        if form.validate_on_submit():
            filename = op.join(directory,
                               secure_filename(form.upload.data.filename))

            if op.exists(filename):
                flash(gettext('File "%(name)s" already exists.', name=form.upload.data.filename),
                      'error')
            else:
                try:
                    self.save_file(filename, form.upload.data)
                    return redirect(self._get_dir_url('.index', path))
                except Exception, ex:
                    flash(gettext('Failed to save file: %(error)s', error=ex))
コード例 #3
0
ファイル: admin.py プロジェクト: nemish/legoband
 def login(self):
     form = LoginForm()
     if form.validate_on_submit():
         user = form.get_user()
         login.login_user(user)
         if login.current_user.is_authenticated():
             return redirect(url_for('.index'))
     return render_template('login.html', form=form, errors=form.errors)
コード例 #4
0
 def register(self):
     form = CanellaRegisterForm()
     if form.validate_on_submit():
         should_confirm = form.send_confirmation.data
         del form.send_confirmation
         register_user(should_confirm=should_confirm, **form.to_dict())
         return redirect(url_for('.index_view'))
     return self.render('admin/model/create.html', form=form)
コード例 #5
0
ファイル: views.py プロジェクト: OSPK/kef
def login():
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            flash('Logged in successfully.')

            return redirect('/admin')
        else:
            flash('Unsuccessful.', 'warning')

    return render_template('login.html', form=form)
コード例 #6
0
 def change_password(self, pk):
     user = self.get_one(str(pk))
     form = CanellaChangePasswordForm(user=user)
     if form.validate_on_submit():
         change_password(user, form.password.data)
         db.session.commit()
         if user.email == current_user.email:
             logout_user()
         flash(gettext('Password changed successfully'))
         return redirect(url_for('.index_view'))
     return self.render('admin/model/create.html', form=form)
コード例 #7
0
ファイル: manage.py プロジェクト: cachalot1984/hexblog
def login():
    password = None
    form = LoginForm()
    if form.validate_on_submit():
        user = User()
        password = form.password.data
        form.password.data = ''
        if password is not None and password == user.password:
            login_user(user, form.remember_me.data)
            flash('Logged in')
            return redirect(request.args.get('next') or url_for('index'))
        flash('Invalid password')
    return render_template('login.html', form=form)
コード例 #8
0
def admin_login():
    form = AdminLoginForm(request.form)
    if form.validate_on_submit():
        user = db.session.query(User).filter_by(
            login=form.username.data).first()
        if user is None or not user.verify_hash(form.password.data):
            flash('Invalid username or password')
            return render_template('admin/login.html', form=form)

        login_user(user, remember=form.remember_me)
        return redirect(url_for('admin.index'))

    return render_template('admin/login.html', form=form)
コード例 #9
0
def login():
    if current_user.is_authenticated:
        return redirect('/admin')
    else:
        form = LoginForm()
        if form.validate_on_submit():
            admin = Admins.query.filter_by(name=form.username.data).first()
            if admin:
                if admin.password == form.password.data:
                    login_user(admin)
                    return redirect('/admin')
            return '<h1>Invalid username or password</h1>'

        return render_template('login.html', form=form)
コード例 #10
0
	def message(self):
		form = ContactForm()
		if form.validate_on_submit():
			contact = Contact(
					fullname=form.fullname.data,
					email= form.email.data,
					message= form.message.data,
				)

			db.session.add(contact)
			db.session.commit()
			flash("Successfuly Send ")

			return redirect(url_for('contactme.index'))

		flash(str(form.errors),'error')
		return redirect(url_for('contactme.index'))
コード例 #11
0
 def index(self):
     form = SendMailForm()
     if form.validate_on_submit():
         result = MailingList.query.filter_by(confirmed=True)
         addresslist = [item.email for item in result]
         for address in addresslist:
             msg = Message(str(form.title.data), recipients=[address])
             message = {
                 'title': form.title.data,
                 'subtitle': form.subtitle.data,
                 'content': form.content.data
             }
             msg.html = render_template('email/email_base.html',
                                        message=message)
             mail.send(msg)
         flash('Email %s sent' % (form.title.data), 'info')
         return redirect('/admin')
     return self.render('email_index.html', form=form)
コード例 #12
0
def handle_sale():
    form = SaleForm()
    if form.validate_on_submit():
        try:
            sale = int(form.sale.data)
            god = Good.objects()

            for i in god:
                saleFinal = i.sale
                i.sale = sale
                i.saleSecond = saleFinal
                i.PriceWithSale = str(
                    int(int(i.price) - (int(i.price) * (int(sale) / 100))))
                i.save()
            flash('Скидка применилась для всех ботов', category='success')
        except Exception as e:
            flash('Введены не правильные данные', category='danger')
    return render_template('sale.html', form=form)
コード例 #13
0
ファイル: fileadmin.py プロジェクト: hellwen/pyservice
    def mkdir(self, path=None):
        """
            Directory creation view method

            :param path:
                Optional directory path. If not provided, will use the base directory
        """
        # Get path and verify if it is valid
        base_path, directory, path = self._normalize_path(path)

        dir_url = self._get_dir_url('.index', path)

        if not self.can_mkdir:
            flash(gettext('Directory creation is disabled.'), 'error')
            return redirect(dir_url)

        form = NameForm(request.form)

        if form.validate_on_submit():
            try:
                os.mkdir(op.join(directory, form.name.data))
                return redirect(dir_url)
            except Exception, ex:
                flash(gettext('Failed to create directory: %(error)s', ex), 'error')
コード例 #14
0
ファイル: views.py プロジェクト: papaspiro/jail-manager
def add_next_of_kin():
	form = NextOfKinForm()
	if request.method == "POST":
		if form.validate_on_submit():
			return redirect(url_for(add_next_of_kin,form=form))
	return render_template('/inmates/nextofkin.html',form=form)
コード例 #15
0
ファイル: views.py プロジェクト: papaspiro/jail-manager
def discharge():
	form = DischargeForm()
	if request.method == "POST":
		if form.validate_on_submit():
			return redirect(url_for(discharge,form=form))
	return render_template('/inmates/discharge.html',form=form)
コード例 #16
0
ファイル: views.py プロジェクト: papaspiro/jail-manager
def transfer():
	form = TransferForm()
	if request.method == "POST":
		if form.validate_on_submit():
			return redirect(url_for(transfer,form=form))
	return render_template('/inmates/transfers.html',form=form)
コード例 #17
0
ファイル: views.py プロジェクト: papaspiro/jail-manager
def property():
	form = DischargeForm()
	if request.method == "POST":
		if form.validate_on_submit():
			return redirect(url_for('.property',form=form))
	return render_template('/inmates/property.html',form=form)
コード例 #18
0
ファイル: views.py プロジェクト: papaspiro/jail-manager
def add_inmate():
	form = InmateForm()
	if form.validate_on_submit():
		
		#to do set a default avartar 
		#fname = ''
		#try :
		file = request.files['picture']

		if file:    # and allowed_file(file.filename):
			filename = secure_filename(file.filename)
			extension = os.path.splitext(file.filename)[1]

			f_name = str(uuid.uuid4()) + extension

			#todo find means to verify if upload was a success
			file.save(os.path.join(UPLOAD_FOLDER,f_name))


		inmate = Inmate(
		serial_number = form.serial_number.data,
		first_name = form.first_name.data ,
		last_name = form.last_name.data,
		middle_name = form.middle_name.data,
		alias = form.alias.data,
		date_of_birth = form.date_of_birth.data,
		gender = form.gender.data,
		distinctive_marks = form.distinctive_marks.data ,
		picture = f_name ,#form.picture.data,
		place_of_birth_country = form.place_of_birth_country.data,
		place_of_birth_region = form.place_of_birth_region.data,
		place_of_birth_locality = form.place_of_birth_locality.data,

	 	language = form.language.data,
		education = form.education.data,

		place_of_offence_country = form.place_of_offence_country.data,
		place_of_offence_region = form.place_of_offence_region.data,
		place_of_offence_locality = form.place_of_offence_locality.data,

		place_of_conviction = form.place_of_conviction.data,
		date_of_sentence = form.date_of_sentence.data,
		date_of_admission = form.date_of_admission.data, #datetime.strptime(form.date_of_admission.data,'%Y-%m-%d'),

		sentence_years = form.sentence_years.data,
		sentence_months = form.sentence_months.data,
		sentence_days = form.sentence_days.data,

		block_cell = form.block_cell.data )

		db.session.add(inmate)
		db.session.commit()

		flash(" inmate successfully added ")
		#postal_address
		#residential_address
		#address on release
		#mext of kin
		
		#return render_template('/inmates/search.html',fname=first_name)
		return redirect(url_for('.add_inmate'))
	return render_template("/inmates/new.html",form=form)
コード例 #19
0
ファイル: manage.py プロジェクト: cachalot1984/hexblog
def edit(opid):
    form = EditForm()
    if form.validate_on_submit():
        # new or edit post received
        now = datetime.now()
        if form.id.data == 'new':
            article = Article(title='', content='', content_size=0, 
                            time_created=now, time_modified=now, read_count=0)
        else:
            article = Article.query.filter_by(id=int(form.id.data)).first_or_404()
            article.time_modified = now

        article.title = form.title.data
        article.content = form.content.data
        article.content_size = len(form.content.data)
        article.private = form.private.data

        if form.category.data == 'new':
            category = Category(name=form.category_new.data)
            db.session.add(category)
        else:
            category = Category.query.filter_by(id=int(form.category.data)).first_or_404()
        article.category = category

        if form.series.data == 'new':
            series = Series(name=form.series_new.data)
            db.session.add(series)
        elif form.series.data == 'none':
            series = None
        else:
            series = Series.query.filter_by(id=int(form.series.data)).first_or_404()
        article.series = series

        article.tags = form.tags.data

        db.session.add(article)
        try:
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            flash('Failed to commit to DB')
            return internal_server_error(e)
        return redirect(url_for('article', id=article.id))
    else:
        # display new or edit page
        categories = Category.query.order_by(Category.name).all()
        form.category.choices = [(str(c.id), c.name) for c in categories]
        form.category.choices.append(('new', u'--新建分类--'))    # special category hint

        all_series = Series.query.order_by(Series.name).all()
        form.series.choices = [(str(s.id), s.name) for s in all_series]
        form.series.choices.insert(0, ('none', u'--无--'))  # default choice, not belongs to any series
        form.series.choices.append(('new', u'--新建系列--'))    # special serial hint

        if opid == 'new':
            new = True
            form.id.data = 'new'
            form.category.data = '1'    # default category
            form.series.data = 'none'    # default series
            return render_template('edit.html', form=form, new=True, 
                        help_article_id=app.config['HEXBLOG_MARKDOWN_ARTICLE_NUM'])
        else:
            id = int(opid)
            article = Article.query.filter_by(id=id).first_or_404()
            form.id.data = id
            form.title.data = article.title
            form.content.data = article.content
            form.private.data = article.private
            form.category.data = str(article.category.id)
            if article.series:
                form.series.data = str(article.series.id)
            form.tags.data = article.tags
            return render_template('edit.html', form=form, new=False, 
                        help_article_id=app.config['HEXBLOG_MARKDOWN_ARTICLE_NUM'])
コード例 #20
0
ファイル: views.py プロジェクト: papaspiro/jail-manager
def penal_record():
	form = PenalRecordForm()
	if request.method == "POST":
		if form.validate_on_submit():
			return redirect(url_for(penal_record,form=form))
	return render_template('/inmates/penalrecords.html',form=form)
コード例 #21
0
	def login(self):
		form = forms.LoginForm(request.form)
		if form.validate_on_submit():
			login_user(form.user, remember=form.remember.data)
			return redirect("/")
		return self.render("login.html",login_user_form=form)