def test_edit_group_header(app): if app.object.count_group() == 0: app.object.create_group_form(Group(name="test")) old_groups = app.object.get_group_list() app.object.edit_first_group(Group(header="new header", )) new_groups = app.object.get_group_list() assert len(old_groups) == app.object.count_group()
def _post_new_group(self, par): ut = Utils() key = ut.cleanUserName(self._req.par('cid')) group = Group(key_name=key) group.title = self._req.par('ctitle') group.put() return self._req.redirect(path=self._conf.BLOG + '/' + key)
def test_edit_group_name(app): if app.object.count_group() == 0: app.object.create_group_form(Group(name="test")) old_groups = app.object.get_group_list() index = randrange(len(old_groups)) group = Group(name="new test progon") group.id = old_groups[index].id app.object.edit_group_by_index(index, group) new_groups = app.object.get_group_list() assert len(old_groups) == app.object.count_group() old_groups[index] = group assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
def _get_default(self, par): obj = {} obj['images'] = Image.all().order("-date").fetch(20) obj['groups'] = Group.all() self._respond(par, obj)
def get(self, par): # all blog and static pages are cacheable if self._check_get_from_cache(): return True self.widgets = Widgets(self, self._conf) # get the groups self._obj['groups'] = Group.all() routes = [ # {"r": self._conf.BLOG + "/widget/(.*)", "f": self._get_widget}, {"r": "/rssfeed(.*)", "f": self._force_rss}, {"r": self._conf.BLOG + "/search\?q=(.*)", "f": self._get_blog_search}, {"r": self._conf.BLOG + "/(.*)/(.*)\?", "f": self._get_blog_single}, {"r": self._conf.BLOG + "/(.*)/(.*)", "f": self._get_blog_single}, {"r": self._conf.BLOG + "/(.*)\?", "f": self._get_blog_group}, {"r": self._conf.BLOG + "/(.*)", "f": self._get_blog_group}, {"r": self._conf.BLOG + ".*", "f": self._get_blog}, {"r": "/(.*)\?", "f": self._get_static}, {"r": "/(.*)", "f": self._get_static} ] if self._req.route(routes): # cache the return url self._req.sesh().set_return_url(self._req.spath()) self._req.sesh().save(); return True return False
def inactive_users(): connect(S) print('Scheduler working') present_time = datetime.now() groups = Group.objects() for group in groups: temp_role_dict = {} temp_role_dict.update(group.role_dict) temp_last_active_dict = {} temp_last_active_dict.update(group.last_active_dict) message_list = [] for user_id, last_active in group.last_active_dict.items(): if last_active < present_time - timedelta( minutes=1) and group.role_dict[ user_id] != A and group.role_dict[user_id] != MD: message = "{name} got deleted due to inactivity".format( name=user_id) message_list.append(message) for key in list(group.role_dict): if key == user_id: del temp_role_dict[user_id] break for key in list(group.last_active_dict): if key == user_id: del temp_last_active_dict[user_id] break group.update(set__last_active_dict=temp_last_active_dict) group.update(set__role_dict=temp_role_dict) SaveLogs(group_id=group, message=message_list).save()
def post(self): body = request.get_json() user = request.authorization # this gives dict uid = User.objects.get(username=user['username']) # this gives user object user_id = str(uid.id) # this gives the user id in string format try: name = body['name'] if body['visibility']: visibility = body['visibility'] else: visibility = P group = Group(name=name, visibility=visibility) group.role_dict[user_id] = A group.save() return {'group_id': str(group.id)}, 200 except: return "Name already exists"
def create_group(n): for i in range(n): accessibility = ['private', 'public'] name = ''.join( [random.choice(string.ascii_letters) for k in range(10)]) # first member is the admin Group(name=name, visibility=random.choice( accessibility)).save() # role_dict={str(user_id):'ADMIN'}
def test_delete_some_group(app): if app.object.count_group() == 0: app.object.create_group_form(Group(name="test")) old_groups = app.object.get_group_list() index = randrange(len(old_groups)) app.object.delete_group_by_index(index) new_groups = app.object.get_group_list() assert len(old_groups) - 1 == app.object.count_group() old_groups[index:index + 1] = [] assert old_groups == new_groups
def _get_blog_group(self, par): """ all blog articles in the group """ group = Group.get_by_key_name(par[0]) if group: q = group.content_set self._obj['title'] = group.title self._get_blog_list(q) else: return self._req.notfound()
def get_group_list(self): if self.group_cache is None: wd = self.app.wd self.open_group_page() self.group_cache = [] for element in wd.find_elements_by_css_selector("span.group"): text = element.text id = element.find_element_by_name("selected[]").get_attribute( "value") self.group_cache.append(Group(name=text, id=id)) return list(self.group_cache)
def get(self, gid): user = request.authorization uid = User.objects.get(username=user['username']) uid = str(uid.id) try: group = Group.objects.get(id=gid) if uid in group.role_dict: group = Group.objects(id=gid).to_json() return Response(group, mimetype="application/json", status=200) else: return "You are not member of the group", 500 except Exception as exception: return exception
def group_object(target_object): """Return a single Group object.""" return Group( name="RVXXX1-G1", targets=[ target_object, Target( first_name="Jane", last_name="Smith", email="*****@*****.**", position="HR", ), ], )
def test_add_group(app): old_groups = app.object.get_group_list() group = Group( name="test progon", header="jhvgvhgv", footer="khgcvkvv", ) app.object.create_group_form(group) new_groups = app.object.get_group_list() assert len(old_groups) + 1 == app.object.count_group() old_groups.append(group) assert sorted(old_groups, key=Group.id_or_max) == sorted(new_groups, key=Group.id_or_max)
def build_groups(id, target_domains): """Build groups.""" logging.info("Getting Group Metadata") groups = list() # Looks through to get the number of groups as a number with error checking num_groups = get_number(" How many groups do you need?") if num_groups > 1: logging.warning("NOTE: Please load each group as a different CSV") labels = yes_no_prompt(" Are there customer labels?") for group_num in range(int(num_groups)): logging.info(f"Building Group {group_num + 1}") new_group = Group(name=f"{id}-G{str(group_num + 1)}") new_group.targets = build_emails(target_domains, labels) logging.info(f"Group Ready: {new_group.name}") groups.append(new_group) return groups
def put(self, gid): # body contains dict of person whose role is changed { "change_role" : {"user id":"new role"}} user = request.authorization uid = User.objects.get(username=user['username']) uid = str(uid.id) body = request.get_json() group = Group.objects(id=gid).get() try: if group.role_dict[uid] == A or group.role_dict[uid] == MD: role_dict = group.role_dict role_dict.update(body['change_role']) group.update(set__role_dict=role_dict) return "Role changed successfully", 200 else: return "You are not an admin", 200 except: return "You are not member of the group", 200
def dailyfeed(): # time now is given such that its mid night connect(S) print("working") time_now = datetime.now() last_day = time_now - timedelta(hours=24) groups = Group.objects() for group in groups: posts = Post.objects( Q(group_id=group.id) & Q(date_created__lte=time_now) & Q(date_created__gte=last_day)) if posts: total = len(posts) content = '{total} posts were put today'.format(total=total) recipients = [] for user_id, access in group.role_dict.items(): if access == A or access == MD: user = User.objects.get(id=user_id) recipients.append(user.email) sch_queue.enqueue(send_mail, recipients, content)
def _post_new_content(self, par): user = User(self._req.sesh()) person = user.get_sesh_person() ut = Utils() key = ut.cleanUserName(self._req.par('cid')) # create the content record, by unique key - !important - replaces existing key - warn user? content = Content(key_name=key) content.status = 'draft' groupname = self._req.par('cgroup') content.group = Group.get_by_key_name(groupname) # create a new version contentver = ContentVersion() # some defaults contentver.title = self._req.par('ctitle') contentver.content = '<p>Placeholder for the body of your Article</p>' contentver.summary = '<p>Placeholder for the article summary</p>' contentver.person = person # have to put to get a reference contentver.put() # upate versions on this content content.current = contentver content.editing = contentver content.put() # link to my parent - in fact shouldnt I have used parents (but then sharding wont be an issue for a few, even 100's of, articles) contentver.mycontent = content contentver.put() # and redirect to the new content return self._req.redirect(path=self._conf.BLOG + '/' + groupname + '/' + key)
def get(self, par): # all blog and static pages are cacheable if self._check_get_from_cache(): return True self.widgets = Widgets(self, self._conf) # TODO filterise this some umbraco url specific tidying # if self._req.ext() == 'aspx': # return self._aspx_redirect() # self._req.remove_par("c") # self._req.remove_par("C") # get the groups self._obj['groups'] = Group.all() routes = [ # {"r": self._conf.BLOG + "/widget/(.*)", "f": self._get_widget}, {"r": "/rssfeed(.*)", "f": self._force_rss}, {"r": self._conf.BLOG + "/(.*)/(.*)\?", "f": self._get_blog_single}, {"r": self._conf.BLOG + "/(.*)/(.*)", "f": self._get_blog_single}, {"r": self._conf.BLOG + "/(.*)\?", "f": self._get_blog_group}, {"r": self._conf.BLOG + "/(.*)", "f": self._get_blog_group}, {"r": self._conf.BLOG + ".*", "f": self._get_blog}, {"r": "/(.*)\?", "f": self._get_static}, {"r": "/(.*)", "f": self._get_static} ] if self._req.route(routes): # cache the return url self._req.sesh().set_return_url(self._req.spath()) self._req.sesh().save(); return True return False
def add(self, name): group = Group() group.name = name self.session.add(group)
def test_group_parse(self, group_object, group_json): """Test parsing of group JSON.""" assert group_object.as_dict() == Group.parse(group_json).as_dict()
def Process(self, section): if section == 'new': order = Order() storages = Storage.select() suppliers = Supplier.select() groups = Group.select() order.id = 0 self.RenderFile( 'purchase/order.htm', { '_': config.i18n, 'order': order, 'storages': storages, 'suppliers': suppliers, 'group-list': groups }) elif section == 'edit': order = Order.get(Order.id == self.IntReq('id')) storages = Storage.select() suppliers = Supplier.select() groups = Group.select() products = order.details for sup in suppliers: if sup == order.supplier: sup.selected = True for stg in storages: if stg == order.storage: stg.selected = True self.RenderFile( 'purchase/order.htm', { '_': config.i18n, 'order': order, 'storages': storages, 'suppliers': suppliers, 'group-list': groups, 'products': products }) elif section == 'save': id = self.IntReq('id') storageId = self.IntReq('storageId') supplierId = self.IntReq('supplierId') try: order = Order.get(Order.id == id) except: order = Order() order.date = getDate() order.time = getTime() order.verified = False supplier = Supplier.get(Supplier.id == supplierId) storage = Storage.get(Storage.id == storageId) order.supplier = supplier order.storage = storage order.user = self.authentication.SessionObject.user order.save() form = self.getForm() row_ids = [] for key in form.keys(): if key[0] == 'g': id = self.ToInt(key[(key.find('[') + 1):key.find(']')]) row_ids.append(id) row_ids.sort() keep_rows = [] pids = [] # order.clearDetails() for row_id in row_ids: x = str(row_id) group_id = self.IntReq('g[' + x + ']') product_id = self.IntReq('i[' + x + ']') group = Group.get(Group.id == group_id) p = Product() if product_id > 0: p = Product.get(Product.id == product_id) p.order = order p.group = group p.name = self.StringReq('n[' + x + ']') p.purchase = self.FloatReq('p[' + x + ']') p.sale = self.FloatReq('s[' + x + ']') p.quantity = self.FloatReq('q[' + x + ']') p.save() pids.append(p.id) order.clearDetails(pids) self.RenderJSON({'Id': order.id}) elif section == 'manage': orders = Order.select() self.RenderFile('purchase/manage.htm', { '_': config.i18n, 'purchases': orders })
def add_from_csv(self, columns, values): group = Group() group.from_csv(columns, values) self.session.add(group)
def Process(self, section): # Open a form in order to save or update if section == 'person.new': person = Person() person.id = 0 self.RenderFile('person/person.htm', { '_': config.i18n, 'person': person }) elif section == 'supplier.new': supplier = Supplier() supplier.id = 0 self.RenderFile('supplier/supplier.htm', { '_': config.i18n, 'supplier': supplier }) elif section == 'group.new': group = Group() group.id = 0 self.RenderFile('group/group.htm', { '_': config.i18n, 'group': group }) elif section == 'storage.new': storage = Storage() storage.id = 0 self.RenderFile('storage/storage.htm', { '_': config.i18n, 'storage': storage }) elif section == 'cost.new': cost = Cost() cost.id = 0 self.RenderFile('cost/cost.htm', {'_': config.i18n, 'cost': cost}) # Open a form with fields filled with data to update elif section == 'person.edit': id = self.IntReq('id') person = Person.get(Person.id == id) self.RenderFile('person/person.htm', { '_': config.i18n, 'person': person }) elif section == 'supplier.edit': id = self.IntReq('id') supplier = Supplier.get(Supplier.id == id) self.RenderFile('supplier/supplier.htm', { '_': config.i18n, 'supplier': supplier }) elif section == 'group.edit': id = self.IntReq('id') group = Group().get(Group.id == id) self.RenderFile('group/group.htm', { '_': config.i18n, 'group': group }) elif section == 'storage.edit': id = self.IntReq('id') storage = Storage().get(Storage.id == id) self.RenderFile('storage/storage.htm', { '_': config.i18n, 'storage': storage }) elif section == 'cost.edit': id = self.IntReq('id') cost = Cost().get(Cost.id == id) self.RenderFile('cost/cost.htm', {'_': config.i18n, 'cost': cost}) # Send save operation to the controler elif section == 'person.save': id = self.IntReq('id') try: p = Person.get(Person.id == id) except: p = Person() p.name = self.StringReq('name') p.city = self.StringReq('city') p.phone = self.StringReq('phone') p.email = self.StringReq('email') p.address = self.StringReq('address') p.save() self.RenderJSON({ 'Result': 'success', 'id': p.id }) elif section == 'supplier.save': id = self.IntReq('id') try: s = Supplier.get(Supplier.id == id) except: s = Supplier() s.name = self.StringReq('name') s.manager = self.StringReq('manager') s.tell = self.StringReq('tell') s.field = self.StringReq('field') s.save() self.RenderJSON({ 'Result': 'success', 'id': s.id }) elif section == 'group.save': id = self.IntReq('id') try: g = Group.get(Group.id == id) except: g = Group() g.name = self.StringReq('name') g.unit = self.StringReq('unit') g.save() self.RenderJSON({'Result': 'success', 'id': g.id}) elif section == 'storage.save': id = self.IntReq('id') try: st = Storage.get(Storage.id == id) except: st = Storage() st.name = self.StringReq('name') st.tell = self.StringReq('tell') st.address = self.StringReq('address') st.save() self.RenderJSON({'Result': 'success', 'id': st.id}) elif section == 'cost.save': id = self.IntReq('id') try: ct = Cost.get(Cost.id == id) except: ct = Cost() ct.regdate = self.StringReq('regdate') ct.regtime = self.StringReq('regtime') ct.title = self.StringReq('title') ct.invoiceno = self.StringReq('invoiceno') ct.amount = self.FloatReq('amount') ct.save() self.RenderJSON({'Result': 'success', 'id': ct.id}) elif section == 'person.check': self.output = '' elif section == 'person.filter': list = Person.select() args = {'data': list, '_': config.i18n} self.RenderFile('person/list.htm', args) # Delete section for each item elif section == 'group.delete': id = self.IntReq('id') group = Group.get(Group.id == id) group.delete_instance() self.RenderJSON({'result': 'OK'}) elif section == 'supplier.delete': id = self.IntReq('id') supplier = Supplier.get(Supplier.id == id) supplier.delete_instance() self.RenderJSON({'result': 'OK'}) elif section == 'storage.delete': id = self.IntReq('id') storage = Storage.get(Storage.id == id) storage.delete_instance() self.RenderJSON({'result': 'OK'}) elif section == 'person.delete': id = self.IntReq('id') person = Person.get(Person.id == id) person.delete_instance() self.RenderJSON({'result': 'OK'}) elif section == 'cost.delete': id = self.IntReq('id') cost = Cost.get(Cost.id == id) cost.delete_instance() self.RenderJSON({'result': 'OK'}) # Manage section for items elif section == 'person.manage': self.RenderFile('person/manage.htm', { '_': config.i18n, 'persons': Person.select() }) elif section == 'supplier.manage': args = {'_': config.i18n, 'suppliers': Supplier.select()} self.RenderFile('supplier/manage.htm', args) elif section == 'group.manage': list = Group.select() args = {'groups': list, '_': config.i18n} self.RenderFile('group/manage.htm', args) elif section == 'storage.manage': list = Storage.select() args = {'storages': list, '_': config.i18n} self.RenderFile('storage/manage.htm', args) elif section == 'cost.manage': list = Cost.select() args = {'costs': list, '_': config.i18n} self.RenderFile('cost/manage.htm', args) elif section == 'person.history': id = self.IntReq('id') person = Person.get(Person.id == id) sales = Sale.select().where(Sale.customer == person) i = 1 for sale in sales: sale.index = i i += 1 args = {'person': person, 'sales': sales, '_': config.i18n} self.RenderFile('person/history.htm', args) elif section == 'group.goodlist': id = self.IntReq('id') g = Group.get(Group.id == id) args = { 'group': g, 'products': g.products.group_by(Product.name), '_': config.i18n } self.RenderFile('group/goodlist.htm', args) elif section == 'storage.goodlist': id = self.IntReq('id') is_JSON = (self.IntReq('json') != 0) s = Storage.get(Storage.id == id) args = {'_': config.i18n, 'storage': s, 'products': s.goodlist()} if is_JSON: ps = [] for p in s.goodlist(): pr = p.purchase_string() sl = p.sell_string() ps.append({ 'id': p.product.id, 'name': p.product.name, 'qty': p.storage_current(s), 'purchase': pr, 'sale': sl }) self.RenderJSON(ps) else: self.RenderFile('storage/goodlist.htm', args) elif section == 'supplier.purchaselist': id = self.IntReq('id') s = Supplier.get(Supplier.id == id) products = Product.select().join(Order).where(Order.supplier == s) i = 1 for p in products: p.index = i i = i + 1 args = {'supplier': s, 'products': products, '_': config.i18n} self.RenderFile('supplier/purchaselist.htm', args) elif section == 'person.instullment': id = self.IntReq('id') inst = SaleInstallment.get(SaleInstallment.id == id) inst.currentdate = getDate() args = {'inst': inst, '_': config.i18n} self.RenderFile('person/instullment.htm', args) elif section == 'person.instullment.save': id = self.IntReq('id') try: si = SaleInstallment.get(SaleInstallment.id == id) except: si = SaleInstallment() si.dateback = self.StringReq('dateback') si.amount = self.FloatReq('amount') si.save() sale = Sale.get(Sale.id == si.sale.id) sale.payment = float(sale.payment) + float(si.amount) sale.save() self.RenderJSON({ 'result': 'ok', 'id': si.id, 'amount': si.amount, 'dateback': si.dateback }) else: self.NotImplemented(section)