def registerGroup(): form = RegisterFormGroup() if form.validate_on_submit(): group = Group(name=form.name.data) if group.save(): return redirect(url_for("users.group_management")) return render_template("register_group.html", form=form)
async def get(self, group_id=-1, student_id=-1, teacher_id=-1): """Gets all groups from the database. If the GroupID is not provided then it will return all groups.""" if student_id != -1: # Get students groups data = await self.db.fetch( """SELECT group_tbl.id, group_tbl.teacher_id, group_tbl.name, group_tbl.subject FROM student_group INNER JOIN group_tbl ON student_group.group_id = group_tbl.id WHERE student_group.student_id = $1;""", student_id) return [Group.create_from(x) for x in data] if data else False if teacher_id != -1: # Get teachers groups data = await self.db.fetch( "SELECT * FROM group_tbl WHERE teacher_id = $1;", teacher_id) return [Group.create_from(x) for x in data] if data else False if group_id == -1: # Get all groups to_return = [] data = await self.db.fetch("SELECT * FROM group_tbl;") if not data: return False for group in data: to_return.append(Group.create_from(group)) return to_return else: if group_id < 1: return None group = await self.db.fetchrow( "SELECT * FROM group_tbl WHERE id = $1;", group_id) if not group: return False return Group.create_from(group)
def insert_group_mention(self, chat_id, reply, mention, user_id): if reply: if mention == "o": insert = ["pm", "off"] elif mention == "m": insert = ["off", "admins"] else: group = self.db["groups"].find_one_and_update( {"id": chat_id}, {"$addToSet": { "pm": user_id }}, {"_id": 0}, return_document=ReturnDocument.AFTER) return Group(**group) else: if mention == "o": insert = ["pm", "off"] else: insert = ["off", "pm"] group = self.db["groups"].find_one_and_update( {"id": chat_id}, { "$pull": { insert[0]: user_id }, "$addToSet": { insert[1]: user_id } }, {"_id": 0}, return_document=ReturnDocument.AFTER) return Group(**group)
def __init__(self, scene): # Title self.text_y = 101 self.text = "KAbaLYN" self.font = FontManager.load_font('blade.ttf', 72) # Buttons self.buttons = Group((ButtonPlay(scene), ButtonMultiplayer(scene), ButtonOptions(scene), ButtonExit(scene)))
def __init__(self, scene): # Title self.text_y = 101 self.text = LanguageManager.load_text("uiPause") self.font = FontManager.load_font('blade.ttf', 72) # Buttons self.buttons = Group( (ButtonContinue(scene), ButtonOptions(scene), ButtonQuit(scene)))
def query_info_to_group(self, query_info, group = None): if (group == None): group = Group(self.get_lsa_string(query_info.name), self.get_lsa_string(query_info.description), 0) else: group.name = self.get_lsa_string(query_info.name) group.description = self.get_lsa_string(query_info.description) return group
def __init__(self, scene): # Title self.text_y = 101 self.text = LanguageManager.load_text("uiOptions") self.font = FontManager.load_font('blade.ttf', 72) # Buttons self.buttons = Group( (ButtonLanguage(scene), ButtonMasterVolume(scene), ButtonSoundVolume(scene), ButtonMusicVolume(scene), ButtonCancel(scene), ButtonConfirm(scene)))
def my_chat_member_update(update, _): if update.effective_chat.type not in ["group", "supergroup"]: # we only care if we were added or removed from a group return status_change = update.my_chat_member.difference().get("status") if status_change is None: return old_status, new_status = status_change if new_status in [ ChatMember.LEFT, ChatMember.KICKED, ]: database.remove_group(update.effective_chat.id) elif new_status in [ChatMember.ADMINISTRATOR, ChatMember.MEMBER]: chat = update.effective_chat database.add_group( Group( chat.id, html.escape(chat.title), [x.user.id for x in chat.get_administrators()], ))
def insert_group_reply(self, chat_id, reply): # if reply is false, it means reply is true. Since reply is actually the people from the former mention group if isinstance(reply, list): group = self.db["groups"].find_one_and_update( {"id": chat_id}, { "$set": { "reply": False }, "$addToSet": { "pm": { "$each": reply } } }, {"_id": 0}, return_document=ReturnDocument.AFTER, ) else: group = self.db["groups"].find_one_and_update( {"id": chat_id}, {"$set": { "reply": True }}, {"_id": 0}, return_document=ReturnDocument.AFTER, ) return Group(**group)
def remove_group_link(self, chat_id, to_link_id): group = self.db["groups"].find_one_and_update( {"id": chat_id}, {"$pull": { "linked_groups": to_link_id }}, {"_id": 0}, return_document=ReturnDocument.AFTER, ) group2 = self.db["groups"].find_one_and_update( {"id": to_link_id}, {"$pull": { "linked_groups": chat_id }}, {"_id": 0}, return_document=ReturnDocument.AFTER, ) return Group(**group), Group(**group2)
def register_conference(): form = VideoConferenceForm() if form.submit.data and form.validate_on_submit(): groups = request.form.getlist('add_groups') VideoConference(groups=groups, users=[], name=form.name.data).save() return redirect(url_for('users.manageConferences')) return render_template("register_conference.html", form=form, groups=Group.load_current_groups())
def insert_group_administration(self, chat_id, value): group = self.db["groups"].find_one_and_update( {"id": chat_id}, {"$set": { "administration": value }}, {"_id": 0}, return_document=ReturnDocument.AFTER, ) return Group(**group)
def added(update, context): if context.bot.id not in [ x.id for x in update.effective_message.new_chat_members ]: return update.effective_message.reply_text(strings.ADDED) chat = update.effective_chat database.add_group( Group(chat.id, chat.title, [x.user.id for x in chat.get_administrators()]))
def __show_group(self, group, path, errors = []): assert group is not None assert group.is_group() assert path is not None # Make sure that current_user has "view" permissions on it. current_user = self.api.get_current_user() if group.get_id() is not None: view = self.guard.get_action(handle = 'view', type = UserAction) assert view is not None if not self.guard.has_permission(current_user, view, group): group = Group(group.get_name()) errors = [_("You do not have permission to view " + "this group.")] # Collect information for the browser. users = [] groups = [] if group.get_id() is not None: acls = self.userdb.get_permission_list(group) parents = self.guard.get_resource_parents(group) children = self.guard.get_resource_children(group) for child in children: if child.is_group(): groups.append(child) else: users.append(child) else: parent_id = path.crop().get_current_id() parent = self.guard.get_resource(id = parent_id) parents = [parent] acls = [] # Render the template. self.api.render('group_editor.tmpl', path = path, parents = parents, group = group, users = users, groups = groups, acls = acls, get_resource = self.guard.get_resource, errors = errors)
def __init__(self, entities, balls=[]): # Calculate sprite corners spr_corner = SpriteManager.load_sprite('spr_corner.png') width = spr_corner.get_width() height = spr_corner.get_height() spr_corner_top_left = swap_color(spr_corner, Colors.WHITE, Colors.GREY) spr_corner_top_right = pygame.transform.flip(spr_corner_top_left, True, False) spr_corner_bottom_left = pygame.transform.flip(spr_corner_top_left, False, True) spr_corner_bottom_right = pygame.transform.flip( spr_corner_top_right, False, True) # Generate sprite panel self.spr_panel = pygame.Surface((width * 2, height * 2)) self.spr_panel.fill(Colors.BLACK) self.spr_panel.blit(spr_corner_top_left, (0, 0)) self.spr_panel.blit(spr_corner_top_right, (width, 0)) self.spr_panel.blit(spr_corner_bottom_left, (0, height)) self.spr_panel.blit(spr_corner_bottom_right, (width, height)) self.spr_panel.set_colorkey(Colors.BLACK) # Surface for objects that are going to have a shadow self.display = pygame.Surface((250, 350)) # Entities group self.entities = Group(entities) # Projectiles group self.projectiles = Group() # Balls group self.balls = Group() for x, y, radius in balls: self.balls.add(Ball(x, y, radius)) # Particles groups self.top_particles = Group() self.bottom_particles = Group()
class ScreenMenu(object): def __init__(self, scene): # Title self.text_y = 101 self.text = "KAbaLYN" self.font = FontManager.load_font('blade.ttf', 72) # Buttons self.buttons = Group((ButtonPlay(scene), ButtonMultiplayer(scene), ButtonOptions(scene), ButtonExit(scene))) def pre_update(self, events, scene): # Pre update the buttons self.buttons.pre_update(events, scene) def update(self, delta_time): # Update the buttons self.buttons.update(delta_time) def draw(self, screen): # Draw text shadow text_surface = self.font.render(self.text, False, Colors.DARK_GREY) screen.blit(text_surface, (halign_center(text_surface, screen) + 5, self.text_y)) # Draw text text_surface = self.font.render(self.text, False, Colors.LIGHT_WHITE) screen.blit(text_surface, (halign_center(text_surface, screen), self.text_y)) # Draw the buttons self.buttons.draw(screen)
class ScreenPause(object): def __init__(self, scene): # Title self.text_y = 101 self.text = LanguageManager.load_text("uiPause") self.font = FontManager.load_font('blade.ttf', 72) # Buttons self.buttons = Group( (ButtonContinue(scene), ButtonOptions(scene), ButtonQuit(scene))) def pre_update(self, events, scene): # Pre update the buttons self.buttons.pre_update(events, scene) def update(self, delta_time): # Update the buttons self.buttons.update(delta_time) # Update text self.text = LanguageManager.load_text("uiPause") def draw(self, screen): # Draw text sahdow text_surface = self.font.render(self.text, False, Colors.DARK_GREY) screen.blit(text_surface, (halign_center(text_surface, screen) + 5, self.text_y + 5)) # Draw text text_surface = self.font.render(self.text, False, Colors.LIGHT_WHITE) screen.blit(text_surface, (halign_center(text_surface, screen), self.text_y)) # Draw the buttons self.buttons.draw(screen)
def insert_group_report(self, chat_id, new_report): if new_report == "b": insert = [True, True] elif new_report == "a": insert = [True, False] else: insert = [False, True] group = self.db["groups"].find_one_and_update( {"id": chat_id}, {"$set": { "admin": insert[0], "report": insert[1] }}, {"_id": 0}, return_document=ReturnDocument.AFTER) return Group(**group)
class SceneFade(Scene): is_fading = False function = None arguments = None executed = False counter = 0 fades = Group() def fade(self, function, *args): SceneFade.is_fading = True SceneFade.function = function SceneFade.arguments = args SceneFade.executed = False Fade.reverse = False def pre_update(self, events): pass def update(self, delta_time): # Check is the scene is fading if SceneFade.is_fading: # Add fade animation if SceneFade.counter < 16: SceneFade.fades.add(Fade(SceneFade.counter)) SceneFade.counter += 1 # Check if the fade is over elif len(SceneFade.fades) == 0: SceneFade.is_fading = False SceneFade.counter = 0 # Execute the function asociated if not SceneFade.executed and Fade.reverse: SceneFade.executed = True SceneFade.function(*SceneFade.arguments) # Update the fade SceneFade.fades.update(delta_time) def draw(self, screen): # Draw the fade SceneFade.fades.draw(screen)
def show_groups(self, userid): self.connect() cursor = self.cnx.cursor() query = ("SELECT groupname.gid, groupname.groupname " "FROM persongroup " "join groupname on persongroup.gid = groupname.gid " "WHERE id = %s") cursor.execute(query, (userid, )) groups = [] for (row) in cursor: group = Group(gid=row[0], groupname=row[1]) groups.append(group) cursor.close() self.cnx.commit() self.disconnect() return groups
def get_unjoined_groups(self, userid): self.connect() cursor = self.cnx.cursor() query = ( "select distinct groupname.gid, groupname.groupname from groupname " "join persongroup on groupname.gid = persongroup.gid " "where groupname.gid not in (select gid from persongroup where id = %s)" ) cursor.execute(query, (userid, )) groups = [] for (row) in cursor: group = Group(gid=row[0], groupname=row[1]) groups.append(group) cursor.close() self.cnx.commit() self.disconnect() return groups
def get_groups_admin(self, admin_id): groups = self.db["groups"].find({"admins": admin_id}, {"_id": 0}) return [Group(**group) for group in groups]
def get_groups(self): groups = self.db["groups"].find({}, {"_id": 0}) return [Group(**group) for group in groups]
def index(self, **kwargs): # Find out which item was requested. path_str = self.api.get_data().get_str('path_str') if path_str is None: resource = self.guard.get_resource(handle = 'everybody', type = Group) path = SpiffGuard.ResourcePath([resource.get_id()]) else: path = SpiffGuard.ResourcePath(path_str) # Fetch the requested user or group info. errors = [] id = path.get_current_id() if self.api.post_data().get_bool('group_add'): resource = Group('') path = path.append(0) elif self.api.post_data().get_bool('user_add'): resource = User('') path = path.append(0) elif self.api.post_data().get_bool('group_save') and id == 0: resource = Group('') errors = self.__save_resource(resource) if not errors: path = path.crop().append(resource.get_id()) elif self.api.post_data().get_bool('group_save'): resource = self.guard.get_resource(id = id) errors = self.__save_resource(resource) path = path.crop().append(resource.get_id()) elif self.api.post_data().get_bool('user_save') and id == 0: resource = User('') errors = self.__save_resource(resource) if not errors: path = path.crop().append(resource.get_id()) elif self.api.post_data().get_bool('user_save'): resource = self.guard.get_resource(id = id) errors = self.__save_resource(resource) path = path.crop().append(resource.get_id()) elif (self.api.post_data().get_bool('group_delete') and self.api.post_data().get_str('group_delete_really') == 'yes'): resource = self.guard.get_resource(id = id) # Check if the group still has users in it. children = self.guard.get_resource_children(resource) if len(children) > 0: #FIXME: Rather ask what to do with the children. errors = [_("Group can not be deleted because " + "it still has users in it.")] else: errors = self.__delete_resource(resource) path = path.crop() id = path.get_current_id() resource = self.guard.get_resource(id = id) elif (self.api.post_data().get_bool('user_delete') and self.api.post_data().get_str('user_delete_really') == 'yes'): resource = self.guard.get_resource(id = id) errors = self.__delete_resource(resource) path = path.crop() id = path.get_current_id() resource = self.guard.get_resource(id = id) elif path_str is not None: resource = self.guard.get_resource(id = id) # Display the editor. if resource.is_group(): self.__show_group(resource, path, errors) else: self.__show_user(resource, path, errors)
class ScreenBackground(object): def __init__(self, entities, balls=[]): # Calculate sprite corners spr_corner = SpriteManager.load_sprite('spr_corner.png') width = spr_corner.get_width() height = spr_corner.get_height() spr_corner_top_left = swap_color(spr_corner, Colors.WHITE, Colors.GREY) spr_corner_top_right = pygame.transform.flip(spr_corner_top_left, True, False) spr_corner_bottom_left = pygame.transform.flip(spr_corner_top_left, False, True) spr_corner_bottom_right = pygame.transform.flip( spr_corner_top_right, False, True) # Generate sprite panel self.spr_panel = pygame.Surface((width * 2, height * 2)) self.spr_panel.fill(Colors.BLACK) self.spr_panel.blit(spr_corner_top_left, (0, 0)) self.spr_panel.blit(spr_corner_top_right, (width, 0)) self.spr_panel.blit(spr_corner_bottom_left, (0, height)) self.spr_panel.blit(spr_corner_bottom_right, (width, height)) self.spr_panel.set_colorkey(Colors.BLACK) # Surface for objects that are going to have a shadow self.display = pygame.Surface((250, 350)) # Entities group self.entities = Group(entities) # Projectiles group self.projectiles = Group() # Balls group self.balls = Group() for x, y, radius in balls: self.balls.add(Ball(x, y, radius)) # Particles groups self.top_particles = Group() self.bottom_particles = Group() def screen_shake(self, screen): # Screen shake shake = random.randint(-6, 6) width = 500 + shake height = 700 + shake screen.blit(pygame.transform.scale(screen, (width, height)), (-shake, -shake)) # Screen distortion for _ in range(random.randint(5, 25)): x = random.randint(0, 500) y = random.randint(0, 700) width = random.randint(20, 200) height = random.randint(5, 25) surface = clip(screen, x, y, width, height) screen.blit( surface, (x + random.randint(-20, 20), y + random.randint(-20, 20))) def screen_distorsion(self, screen): # Screen shake shake = random.randint(-6, 6) width = 500 + shake height = 700 + shake screen.blit(pygame.transform.scale(screen, (width, height)), (-shake, -shake)) # Screen distortion for _ in range(random.randint(5, 25)): x = random.randint(0, 500) y = random.randint(0, 700) width = random.randint(20, 200) height = random.randint(5, 25) surface = clip(screen, x - width, y - height, width, height) screen.blit( surface, (x + random.randint(-20, 20), y + random.randint(-20, 20))) def draw(self, screen): # Screen background color screen.fill(Colors.BLACK) # Display background color self.display.fill(Colors.BLACK) # Draw the entities entities_display = self.display.copy() self.entities.draw(entities_display) # Draw the bottom particles bottom_particles_display = self.display.copy() self.bottom_particles.draw(bottom_particles_display) # Draw the projectiles projectiles_display = self.display.copy() self.projectiles.draw(projectiles_display) # Draw the balls balls_display = self.display.copy() self.balls.draw(balls_display) # Draw the top particles top_particles_display = self.display.copy() self.top_particles.draw(top_particles_display) # Draw the shadow display = self.display.copy() display.fill(Colors.DARK_GREY) display.blits( ((entities_display, (0, 0)), (top_particles_display, (0, 0)), (balls_display, (0, 0)), (projectiles_display, (0, 0)), (bottom_particles_display, (0, 0)))) shadow = self.display.copy() shadow.fill(Colors.LIGHT_GREY) shadow.blit(display, (0, 0), special_flags=BLEND_MULT) screen.blit(pygame.transform.scale(shadow, (450, 650)), (24, 24)) # Draw the panel screen.blit(self.spr_panel, (0, 0)) # Draw the display self.display.blits( ((bottom_particles_display, (0, 0)), (projectiles_display, (0, 0)), (balls_display, (0, 0)), (top_particles_display, (0, 0)), (entities_display, (0, 0)))) self.display.set_colorkey(Colors.BLACK) screen.blit(pygame.transform.scale(self.display, (500, 700)), (0, 0))
def group_management(): groups = Group.load_current_groups() return render_template("group_management.html", groups=groups)
def deleteGroup(id): Group.load_group_from_id(id=id).deleteGroup() return redirect(url_for("users.group_management"))