def sign_up(self, user_name, user_password, tech_interest): '''This is the function called when "sign up" is clicked''' # Check if all fields are filled if user_name == '' or user_password == '' or tech_interest == '': tk.messagebox.showerror("", "Please fill out all the fields!") return # Check if username already existed in pending applications if AccountsManager.is_pending(user_name): tk.messagebox.showerror("Error", "You application is still pending, please wait for approval!") return # Check if username already existed in accounts db if AccountsManager.username_exists(user_name): tk.messagebox.showerror("Error", "User name already existed, please re-enter!") return # Add account application to db AccountsManager.add_pending_user({ 'username': user_name, 'password': user_password, 'technical_interest': tech_interest }) tk.messagebox.showinfo("Information", "Registration is successful, please wait for approval.") self.controller.show_frame("MainPage")
def log_in(self, username_input, password_input): # Check if all fields are filled if username_input == '' or password_input == '': tk.messagebox.showerror("Error", "Please fill out all the fields!") return # Check if username is in pending applications db if AccountsManager.is_pending(username_input): tk.messagebox.showerror("Error", "Your application is still pending!") return # Check if username exists in db, if yes then check password if not AccountsManager.username_exists(username_input): tk.messagebox.showerror("Error", "Wrong username!") else: user = AccountsManager.validate_user(username_input, password_input) if user: # If password match (validates successfully), set user info into the system by calling the controller method username = username_input userid = user['userid'] usertype = user['usertype'] self.controller.log_in(username, userid, usertype) else: tk.messagebox.showerror("Error", "Wrong password!")
def get_locker(docid): '''This function returns a dictionary that contains the user id and user name of the locker of doc''' locker_db = pd.read_csv(path_to_locker_db, index_col=0) userid = locker_db.loc[docid]['locker_id'] locker = { 'id': userid, 'name': AccountsManager.get_user_info(userid)['username'] } return locker
def is_on_warning_list(self): bad_doc = AccountsManager.is_warned(self.__userid) if bad_doc: self.bad_docid = bad_doc['bad_docid'] self.bad_doc_title = bad_doc['bad_doc_title'] self.opened_docid = self.bad_docid self.is_warned = True if DocumentsManager.is_owner(self.__userid, self.bad_docid): self.create_doc_owner_page() self.show_frame("DocumentOwnerPage") else: self.create_doc_editor_page() self.show_frame("DocumentEditorPage") return True
def fetch_status(self): self.doc_info = DocumentsManager.get_doc_info(self.docid) # update lock status if self.doc_info['is_locked'] == False: self.lock_status_var.set("Document is unlocked") else: locker = DocumentsManager.get_locker(self.docid) self.lock_status_var.set( "Document is currently locked by {}".format(locker['name'])) # update scope self.scope_var.set("This is a {} document".format( self.doc_info['scope'])) # update last modifier and time self.last_modified_var.set("Last modified by {} at {}".format( AccountsManager.get_username(int(self.doc_info['modified_by'])), self.doc_info['modified_at']))
def refresh_doc_section(self, docs): '''Input docs should be a dataframe, this function refresh content in docs_section treeview''' for old_doc in self.docs_section.get_children(): self.docs_section.delete(old_doc) if not docs.empty: for docid, row in docs.iterrows(): doc_info_tuple = ( row['title'], AccountsManager.get_username(row['owner_id']), row['scope'], int( row['views_count'] ), # make sure it's integer (sometimes it becomes float idk why) row['modified_at']) self.docs_section.insert('', tk.END, iid=docid, values=doc_info_tuple)
def complain_to_su(self): selected_seq_id = '{}-{}'.format(self.docid, self.selected_version.split()[1]) complaint = tk.simpledialog.askstring( "Complain to Super User", "Please enter your complaint about this document: ") if complaint is not None: super_users = AccountsManager.get_all_super_users() for su in super_users: complaint_info = { 'receiver_id': su, 'complaint_type': 'to_su', 'complainee_id': DocumentsManager.get_doc_info(self.docid)['owner_id'], 'seq_id': selected_seq_id, 'content': complaint, } ComplaintsManager.add_complaint(self.userid, complaint_info) tk.messagebox.showinfo("", "Your complaint has been recorded!")
def version_selected(self, value): # retrieve selected version: self.version_var.set(value) self.selected_version = value selected_seq_id = '{}-{}'.format(self.docid, value.split()[1]) self.content.delete(1.0, tk.END) # if selected version is current version then display current content if selected_seq_id == self.doc_info['current_seq_id']: self.content.insert( tk.INSERT, self.filter_taboo_words(self.doc_info['content'], '\n')) self.fetch_status() else: old_version_content = DocumentsManager.retrieve_old_version( selected_seq_id) self.content.insert( tk.INSERT, self.filter_taboo_words(old_version_content, '\n')) old_version_info = DocumentsManager.get_old_version_info( selected_seq_id) modifier = AccountsManager.get_username( old_version_info['modified_by']) modified_time = old_version_info['modified_at'] self.last_modified_var.set("Last modified by {} at {}".format( modifier, modified_time))
def __init__(self, parent, controller): self.username = controller.get_username() self.userid = controller.get_userid() self.docid = controller.opened_docid self.controller = controller self.doc_info = DocumentsManager.get_doc_info(self.docid) self.doc_versions = DocumentsManager.get_doc_old_versions(self.docid) self.owner_name = AccountsManager.get_username( self.doc_info['owner_id']) tk.Frame.__init__(self, parent) self.lock_status_var = tk.StringVar(self) self.title_var = tk.StringVar(self) self.content_var = tk.StringVar(self) self.modified_time_var = tk.StringVar(self) self.modified_user_var = tk.StringVar(self) self.last_modified_var = tk.StringVar(self) self.scope_var = tk.StringVar(self) lock_status_label = tk.Label(self, textvariable=self.lock_status_var, fg="grey") last_modified_label = tk.Label(self, textvariable=self.last_modified_var, fg="grey") scope_label = tk.Label(self, textvariable=self.scope_var, fg="grey") owner_label = tk.Label(self, text="Owned by {}".format(self.owner_name), fg="green") label_type = tk.Label(self, text="® FourofUS 2018", fg="gray", font=controller.footer_font) label1 = tk.Label(self, text="ShareWithME") label1.config(font=("Courier", 35, 'bold')) label_title = tk.Label(self, text="Title") label_content = tk.Label(self, text="Content") self.title = tk.Text(self, height=1, width=30, highlightbackground="black", highlightcolor="black", highlightthickness=1, font=("Times New Roman", 18)) self.content = tk.Text( self, height=25, width=60, highlightbackground="black", highlightcolor="black", highlightthickness=1, ) # For version history drop down self.version_var = tk.StringVar(self) self.selected_version = '' self.doc_versions_list = [] self.versions_drop_down = tk.OptionMenu(self, self.version_var, None) complain_button = tk.Button( self, text="Complain", command=lambda: controller.show_warning() if controller.is_warned else self.complain_doc()) back_button = tk.Button(self, text="Back", command=lambda: controller.show_warning() if controller.is_warned else self.destroy()) download_button = tk.Button( self, text="Download", command=lambda: controller.show_warning() if controller.is_warned else self.download_file()) n = 150 m = 50 label_type.pack(side=tk.BOTTOM) label1.pack(side=tk.TOP, ipady=20) label_title.place(x=n - 120, y=m + 10) self.title.place(x=n - 120, y=m + 30) label_content.place(x=n - 120, y=m + 70) self.content.place(x=n - 120, y=m + 90) self.versions_drop_down.place(x=n + 325, y=m + 20) download_button.place(x=n + 325, y=m * 9) complain_button.place(x=n + 325, y=m * 7) back_button.place(x=n + 325, y=m * 8) lock_status_label.place(x=n + 70, y=m * 10 + 20) last_modified_label.place(x=n + 70, y=m * 10 + 40) scope_label.place(x=n - 40, y=m + 70) owner_label.place(x=n + 160, y=m + 70) # display doc info self.refresh_content()
def remove_warning(self): AccountsManager.remove_warning(self.__userid) self.is_warned = False self.bad_docid = 0 self.bad_doc_title = ''