def seed_static_data(self): self.event1 = self.add_event(key='event1') self.event2 = self.add_event(key='event2') self.user1 = self.add_user('*****@*****.**') self.user2 = self.add_user('*****@*****.**') self.user3 = self.add_user('*****@*****.**') self.event1.add_event_role('admin', self.user1.id) self.event2.add_event_role('admin', self.user2.id) db.session.commit() self.tags = [ Tag(self.event1.id), Tag(self.event1.id), Tag(self.event2.id) ] db.session.add_all(self.tags) db.session.commit() tag_translations = [ TagTranslation(self.tags[0].id, 'en', 'English Tag 1 Event 1'), TagTranslation(self.tags[0].id, 'fr', 'French Tag 1 Event 1'), TagTranslation(self.tags[1].id, 'en', 'English Tag 2 Event 1'), TagTranslation(self.tags[1].id, 'fr', 'French Tag 2 Event 1'), TagTranslation(self.tags[2].id, 'en', 'English Tag 1 Event 2') ] db.session.add_all(tag_translations) db.session.commit() self.user1_headers = self.get_auth_header_for('*****@*****.**') self.user2_headers = self.get_auth_header_for('*****@*****.**') self.user3_headers = self.get_auth_header_for('*****@*****.**')
def index(): return render_template('database/index.html', title="Database", users=User.all(User()), pages=Page.get_all_pages(Page()), comments=Comment.get_all_comments(Comment()), tags=Tag.get_all_tags(Tag()))
def run(self, count): int_count = count if type(count) == int else int(count) for _ in range(int_count): tag = Tag(fake.sentence()) db.session.add(tag) db.session.commit() print('done')
def add_tag(self, event_id=1, names={'en': 'Tag 1 en', 'fr': 'Tag 1 fr'}): tag = Tag(event_id) db.session.add(tag) db.session.commit() translations = [ TagTranslation(tag.id, k, name) for k, name in names.items() ] db.session.add_all(translations) db.session.commit() return tag
def post(self, event_id): req_parser = reqparse.RequestParser() req_parser.add_argument('name', type=dict, required=True) args = req_parser.parse_args() name_translations = args['name'] tag = Tag(event_id) for language, name in name_translations.iteritems(): tag.translations.append(TagTranslation(tag.id, language, name)) tag_repository.add_tag(tag) return _serialize_tag_detail(tag), 201
def edit(tag_id): tag = Tag.get_tag(Tag(), tag_id) form = EditForm(secret_key=app.config['SECRET_KEY'], obj=tag) if form.validate_on_submit(): form.populate_obj(tag) tag.save_tag(tag) flash('Tag edited successfully.', 'success') return redirect('/tags') elif form.is_submitted(): flash('Can\'t submit empty tag!', 'warning') return render_template('tags/edit.html', title="Edit Tag", form=form)
def new(): tag = Tag(('', '')) form = NewForm(secret_key=app.config['SECRET_KEY'], obj=tag) if form.validate_on_submit(): form.populate_obj(tag) Tag.new_tag(tag, tag) flash('New tag created successfully!', 'success') return redirect('/tags') elif form.is_submitted(): flash('The new tag can\'t be empty!', 'warning') return render_template('tags/new.html', title="New Tag", form=form)
def post(self, id): args = parser.parse_args() web_component = WebComponent.query.filter_by(id=id).first_or_404() # Get or create name = args['name'] tag = Tag.query.filter_by(name=name).first() if not tag: tag = Tag(name=name) web_component.tags.append(tag) db.session.commit() return dict(web_component)
def index(): return render_template('dashboard/index.html', title="Dashboard", pages=Page.get_recent(Page(), 5), comments=Comment.recent_comments(Comment(), 5), tags=Tag.popular_tags(Tag(), 5))
def delete(tag_id): print(tag_id) Tag.delete_tag(Tag(), Tag((tag_id, ''))) flash('Tag deleted successfully!', 'success') return redirect('/tags')
def index(): return render_template('tags/index.html', title="Tags", tags=Tag.get_all_tags(Tag()), form=Form(secret_key=app.config['SECRET_KEY']))
def get_tags(self): return Tag.get_by_page_id(Tag(), self.page_id)