Beispiel #1
0
def add_logo():
	if request.method == 'POST' and request.files.getlist('docs'):
		if request.files['docs'].filename == '':
			flash('Файл не приложен')
			return redirect(url_for('site.administration', displayNewPhoto='block'))
		else:
			try:
				for file in request.files.getlist('docs'):
					if file and allowed_file(file.filename):
						if not isinstance(file, FileStorage): # Validate that what we have been supplied with is infact a file
							raise TypeError("storage must be a werkzeug.FileStorage")
							flash('Левый файл')
							return redirect(url_for('site.administration', displayNewPhoto='block'))

						file.filename = translit(file.filename,'ru', reversed=True)
						if len(file.filename)>34:
							file.filename = file.filename[0:20]+ os.path.splitext(file.filename)[1]
						imgName = images.save(file)
						imgURL = images.url(imgName)
						
						photo = Logo(
							imgName = imgName, 
							imgURL = imgURL, 
							status = '')
						db.session.add(photo)
				db.session.commit()
				flash('Логотип добавлен')
				return redirect(url_for('site.administration'))
			except:
				flash('Какой-то некорректный файл :(')
				return redirect(url_for('site.administration', displayNewPhoto='block'))
	flash('Упс, что-то не сработало :(')
	return redirect(url_for('site.administration'))	
def new_post():
    postForm = PostForm()
    if current_user.can(
            Permission.WRITE_ARTICLES) and postForm.validate_on_submit():
        post = Post(body=postForm.body.data,
                    header=postForm.header.data,
                    author=current_user._get_current_object())
        db.session.add(post)
        db.session.commit()
        postID = Post.query.order_by(Post.id.desc()).first().id

        if request.method == 'POST' and request.files.getlist('docs'):

            if request.files['docs'].filename == '':
                return redirect(url_for('main.index'))
            else:
                try:
                    for file in request.files.getlist('docs'):
                        if file and allowed_file(file.filename):
                            if not isinstance(
                                    file, FileStorage
                            ):  # Validate that what we have been supplied with is infact a file
                                raise TypeError(
                                    "storage must be a werkzeug.FileStorage")
                                flash('Левый файл')
                                return render_template('/news/newpost.html',
                                                       NewsForm=postForm)

                            file.filename = translit(file.filename,
                                                     'ru',
                                                     reversed=True)
                            if len(file.filename) > 34:
                                file.filename = file.filename[
                                    0:20] + os.path.splitext(file.filename)[1]
                            imgName = images.save(file)
                            imgURL = images.url(imgName)

                            gallery = PostGallery(
                                imgName=imgName,
                                imgURL=imgURL,
                                postID=postID,
                            )
                            db.session.add(gallery)
                    db.session.commit()
                    return redirect(url_for('main.index'))

                except:
                    flash('Некорректный файл')
                    return render_template('/news/newpost.html',
                                           NewsForm=postForm)

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

    return render_template('/news/newpost.html', NewsForm=postForm)
def add_gallery():
    if request.method == 'POST' and request.files.getlist('docs'):
        if request.files['docs'].filename == '':
            flash('Файл не приложен')
            return redirect(url_for('media.photo', displayNewGallery='block'))
        else:
            try:
                if Photo.query.order_by(
                        Photo.galleryID.desc()).first() is None:
                    galleryID = 1
                else:
                    galleryID = int(
                        Photo.query.order_by(
                            Photo.galleryID.desc()).first().galleryID) + 1
                for file in request.files.getlist('docs'):
                    if file and allowed_file(file.filename):
                        if not isinstance(
                                file, FileStorage
                        ):  # Validate that what we have been supplied with is infact a file
                            raise TypeError(
                                "storage must be a werkzeug.FileStorage")
                            flash('Левый файл')
                            return redirect(
                                url_for('media.photo',
                                        displayNewGallery='block'))

                        file.filename = translit(file.filename,
                                                 'ru',
                                                 reversed=True)
                        if len(file.filename) > 34:
                            file.filename = file.filename[
                                0:20] + os.path.splitext(file.filename)[1]
                        imgName = images.save(file)
                        imgURL = images.url(imgName)

                        gallery = Photo(imgName=imgName,
                                        imgURL=imgURL,
                                        galleryURL=bleach.clean(
                                            request.form['galleryURL']),
                                        galleryName=bleach.clean(
                                            request.form['galleryName']),
                                        galleryID=galleryID,
                                        authorName=current_user.teamName)
                        db.session.add(gallery)
                db.session.commit()
                flash('Альбом "%s" добавлен!' % (request.form['galleryName']))
                return redirect(url_for('media.photo'))
            except:
                flash('Вы не залогинены или некорректный файл')
                return redirect(
                    url_for('media.photo', displayNewGallery='block'))
    flash('Упс, что-то не сработало :(')
    return redirect(url_for('media.photo'))
def add_contact():
    if request.method == 'POST' and request.files.getlist('docs'):
        if request.files['docs'].filename == '':
            flash('Файл не приложен')
            return redirect(url_for('main.contacts',
                                    displayNewContact='block'))
        else:
            try:
                for file in request.files.getlist('docs'):
                    if file and allowed_file(file.filename):
                        if not isinstance(
                                file, FileStorage
                        ):  # Validate that what we have been supplied with is infact a file
                            raise TypeError(
                                "storage must be a werkzeug.FileStorage")
                            flash('Левый файл')
                            return redirect(
                                url_for('main.contacts',
                                        displayNewContact='block'))

                        file.filename = translit(file.filename,
                                                 'ru',
                                                 reversed=True)
                        if len(file.filename) > 64:
                            file.filename = file.filename[
                                0:20] + os.path.splitext(file.filename)[1]
                        filename = images.save(file)
                        url = images.url(filename)

                        contact = Contacts(
                            fileName=filename,
                            url=url,
                            fullName=bleach.clean(request.form['fullName']),
                            jobDescription=bleach.clean(
                                request.form['jobDescription']),
                            email=bleach.clean(request.form['email']),
                            vkURL=bleach.clean(request.form['vkURL']),
                            fbURL=bleach.clean(request.form['fbURL']))
                        db.session.add(contact)

                db.session.commit()
                flash('%s добавлен в контакты' %
                      (bleach.clean(request.form['fullName'])))
                return redirect(url_for('main.contacts'))
            except:
                flash('Некорректный файл')
                return redirect(
                    url_for('main.contacts', displayNewContact='block'))

    return redirect(url_for('main.contacts'))
Beispiel #5
0
def routes_add():
    routeForm = RoutesForm()
    competition = Competition.query.first()
    RouteCounter = Competition.query.first()
    if routeForm.validate_on_submit():
        if Routes.query.filter_by(
                routeNuber=routeForm.routeNuber.data).filter_by(
                    competition=competition.competitionName).first() is None:
            if request.files['img'].filename == '':
                filename = 'logo_route.jpg'
                url = current_app.config['UPLOADED_IMAGES_URL'] + filename
            else:
                try:
                    request.files['img'].filename = translit(
                        request.files['img'].filename, 'ru', reversed=True)
                    if len(request.files['img'].filename) > 64:
                        request.files['img'].filename = request.files[
                            'img'].filename[0:20] + os.path.splitext(
                                request.files['img'].filename)[1]
                    filename = images.save(request.files['img'])
                    url = images.url(filename)
                except:
                    flash('Некорректное имя файла')
                    return redirect(
                        url_for('competition.routes',
                                displayAddNewRoute='block'))
            route = Routes(competition=competition.competitionName,
                           routeNuber=routeForm.routeNuber.data,
                           score=routeForm.routeScore.data,
                           controlTimeSec=routeForm.routeTime.data,
                           teamsPassTrough=0,
                           picName=filename,
                           picURL=url,
                           name=routeForm.routeName.data)

            RouteCounter.numberOfRoutes = RouteCounter.numberOfRoutes + 1
            db.session.add(route)
            db.session.add(RouteCounter)
            db.session.commit()
            flash('Трасса №%s добавлена' % (routeForm.routeNuber.data))
            return redirect(url_for('competition.routes'))
        else:
            flash('Трасса №%s уже существует' % (routeForm.routeNuber.data))
            return redirect(
                url_for('competition.routes', displayAddNewRoute='block'))

    flash('Ошибка при заполнении')
    return redirect(url_for('competition.routes', displayAddNewRoute='block'))
Beispiel #6
0
def add_sponsor():
    if request.method == 'POST' and request.files.getlist('docs'):
        if request.files['docs'].filename == '':
            flash('Файл не приложен')
            return redirect(url_for('info.sponsors',
                                    displayNewSponsor='block'))
        else:
            try:
                for file in request.files.getlist('docs'):
                    if file and allowed_file(file.filename):
                        if not isinstance(
                                file, FileStorage
                        ):  # Validate that what we have been supplied with is infact a file
                            raise TypeError(
                                "storage must be a werkzeug.FileStorage")
                            flash('Левый файл')
                            return redirect(
                                url_for('info.sponsors',
                                        displayNewSponsor='block'))

                        file.filename = translit(file.filename,
                                                 'ru',
                                                 reversed=True)
                        if len(file.filename) > 21:
                            file.filename = file.filename[
                                0:20] + os.path.splitext(file.filename)[1]
                        imgName = images.save(file)
                        imgURL = images.url(imgName)
                        sponsor = Sponsors(imgName=imgName,
                                           imgURL=imgURL,
                                           linkToSponsor=bleach.clean(
                                               request.form['linkToSponsor']),
                                           sponsorName=bleach.clean(
                                               request.form['sponsorName']),
                                           sponsorType=bleach.clean(
                                               request.form['sponsorType']))
                        db.session.add(sponsor)
                db.session.commit()
                flash(
                    '%s добавлен в %s' %
                    (request.form['sponsorName'], request.form['sponsorType']))
                return redirect(url_for('info.sponsors'))
            except:
                flash('Некорректный файл')
                return redirect(
                    url_for('info.sponsors', displayNewSponsor='block'))
    flash('Упс, что-то не сработало :(')
    return redirect(url_for('info.sponsors'))
def add_post_photo():
    postID = request.form['postID']
    if request.method == 'POST' and request.files.getlist('docs'):
        if request.files['docs'].filename == '':
            flash('Файл не приложен')
            return redirect(
                url_for('news.edit_post', id=postID, displayNewPhoto='block'))
        else:
            try:
                for file in request.files.getlist('docs'):
                    if file and allowed_file(file.filename):
                        if not isinstance(
                                file, FileStorage
                        ):  # Validate that what we have been supplied with is infact a file
                            raise TypeError(
                                "storage must be a werkzeug.FileStorage")
                            flash('Левый файл')
                            return redirect(
                                url_for('media.photo_gallery',
                                        displayNewPhoto='block'))

                        file.filename = translit(file.filename,
                                                 'ru',
                                                 reversed=True)
                        if len(file.filename) > 34:
                            file.filename = file.filename[
                                0:20] + os.path.splitext(file.filename)[1]
                        imgName = images.save(file)
                        imgURL = images.url(imgName)

                        gallery = PostGallery(imgName=imgName,
                                              imgURL=imgURL,
                                              postID=bleach.clean(postID))
                        db.session.add(gallery)
                db.session.commit()
                flash('Фото добавлены!')
                return redirect(url_for('news.edit_post', id=postID))
            except:
                flash('Некорректный файл')
                return redirect(
                    url_for('news.edit_post',
                            id=postID,
                            displayNewPhoto='block'))
    flash('Упс, что-то не сработало :(')
    return redirect(
        url_for('news.edit_post', id=postID, displayNewPhoto='block'))