def upload_new_packages(self, packages: np.ndarray) -> None: for i in range(0, packages.size): [name, repo] = self.get_package_info(packages[i]) item: Package = dbsession.query(Package).filter( Package.name_id == name).first() if item is None: dbsession.add(Package(name_id=name, repository=repo)) else: if item.repository != repo: item.repository = repo dbsession.commit()
def create_user(): """Creates a new user""" try: user = User(name='Robus', address='Shantinagar') dbsession.add(user) dbsession.commit() dbsession.flush() except Exception as e: print(e) return jsonify({'error': 'Yup'}) else: return jsonify({"status": "done"})
def delete_user(user_id): if 'user' not in login_session: return redirect(url_for('index')) user = dbsession.query(User).filter_by(id=user_id).one() if request.method == 'POST': dbsession.delete(user) dbsession.commit() # Does this make sense? logout(user.id) flash('User deleted successfully') return redirect(url_for('index')) return render_template('users/deleteprofile.html')
def register(): #if current_user.is_authenticated: # return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): user = User(wp_username=form.wp_username.data, wp_url=form.wp_url.data, wp_password=generate_password_hash(form.wp_password.data)) dbsession.add(user) dbsession.commit() flash('You have now registered') return redirect(url_for('login')) return render_template('users/register.html', title='Register', form=form)
def edit_user(user_id): if 'user' not in login_session: return redirect(url_for('index')) user = dbsession.query(User).filter_by(id=user_id).one() form = EditForm() if request.method == 'POST': user.id = user_id user.wp_username = form.wp_username.data user.wp_password = user.set_password_hash(form.wp_password.data) user.wp_url = form.wp_url.data dbsession.add(user) dbsession.commit() flash('User info edited successfully') return redirect(url_for('user_profile', user_id=user_id)) return render_template('users/editprofile.html')
def add_tag(self, id, name) -> bool: dbsession.add(Tag(name_id=id, nice_name=name)) dbsession.commit()
def delete_row(self, id) -> bool: tag = dbsession.query(Tag).filter(Tag.name_id == id).first() if (tag == None): return False dbsession.delete(tag) dbsession.commit()