Пример #1
0
def memacheGroup(groupid):
    group=memcache.get('groupbyid'+str(groupid))
    if not group:
        if '0000'==groupid:
            group=Group()
            group.name=u'大厅'
            return group
        groupid=int(groupid)
        if groupid:
            group=Group.get_by_id(int(groupid))
            memcache.set('groupbyid'+str(groupid),group,36000)
        else:
            return None
    return group
Пример #2
0
    def post(self):
        """

        """
        username=get_current_user(self)
        if '000'==username:
            type=self.request.get('type','')
            value=self.request.get('value',0)
            list=[]
            if type=='username':
                list=Note.all().filter('author =',str(value))
            if type=='groupid':
                list=Note.all().filter('group =',int(value)).order('-isTop').order('-updateTime')
            if type=='noteid':
                list=Note.get_by_id([int(value)])
        else:
            type=self.request.get('type','')
            value=self.request.get('value',0)
            list=[]
            if type=='username':
                list=Note.all().filter('author =',str(value))
            if type=='groupid':
                list=Note.all().filter('group =',int(value)).order('-isTop').order('-updateTime')
            if not type and not value:
                groupids=[]
                for g in Group.all().filter('author =',username):
                    groupids.append(g.key().id())
                list=Note.all().filter('group in',groupids).filter('isDelete =',False).order('-updateTime')
        notelist=[]
        for note in list:
            note.groupobj=getGroup(note.group)
            notelist.append(note)
        self.render('templates/noteList.html',{'list':notelist,'isadmin':('000'==username and [True] or [False])[0]})
Пример #3
0
def getGroup(groupid):
    group=memcache.get('groupbyid'+str(groupid))
    if group:
        return group
    else:
        group=Group.get_by_id(groupid)
        memcache.set('groupbyid'+str(groupid),group,3600)
        return group
Пример #4
0
 def post(self):
     tagmap={}
     for tag in Tag.all():
         tagmap[str(tag.key().id())]=tag.name
     username=get_current_user(self)
     if '000'==username:
         type=self.request.get('type','')
         value=self.request.get('value',0)
         list=[]
         if type=='username':
             list=Group.all().filter('author =',str(value))
         if type=='groupid':
             list=Group.get_by_id([int(value)])
     else:
         list=Group.all().filter('author =',username)
     listgroup=[]
     for group in list:
         group.tagname=tagmap.get(str(group.tag),'')
         listgroup.append(group)
     self.render('templates/groupList.html',{'list':listgroup,'tagmap':tagmap,'isadmin':('000'==username and [True] or [False])[0]})
 def get_group_list(self):
     if self.group_cache is None:
         wd = self.app.wd
         self.open_groups_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 test_delete_some_group(app, db, check_ui):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test"))
    old_groups = db.get_group_list()
    group = random.choice(old_groups)
    app.group.delete_group_by_id(group.id)
    new_groups = db.get_group_list()
    old_groups.remove(group)
    assert old_groups == new_groups
    if check_ui:
        assert sorted(new_groups, key=Group.id_or_max) == sorted(
            app.group.get_group_list(), key=Group.id_or_max)
 def get_group_list(self):
     list = []
     cursor = self.connection.cursor()
     try:
         cursor.execute(
             "select group_id, group_name, group_header, group_footer from group_list"
         )
         for row in cursor:
             (id, name, header, footer) = row
             list.append(
                 Group(id=str(id), name=name, header=header, footer=footer))
     finally:
         cursor.close()
     return list
 def get_groups_with_contacts(self):
     list = []
     cursor = self.connection.cursor()
     try:
         cursor.execute(
             "select group_id, group_name, group_header, group_footer from group_list "
             "where group_id in (select group_id from address_in_groups)")
         for row in cursor:
             (id, name, header, footer) = row
             list.append(
                 Group(id=str(id), name=name, header=header, footer=footer))
     finally:
         cursor.close()
     return list
Пример #9
0
def group_new():
    """create group"""
    raw_dict = request.get_json(force=True)
    try:
        group_schema.validate(raw_dict)
        group_dict = raw_dict['data']['attributes']
        group = Group(group_dict['name'])
        group.add(group)
        query = Group.query.filter_by(name=group_dict['name']).first()
        results = group_schema.dump(query).data
        print results
        return jsonify({"id": query.id})

    except ValidationError as err:

        resp = jsonify({"error": err.messages})
        resp.status_code = 403
        return resp

    except SQLAlchemyError as e:
        db.session.rollback()
        resp = jsonify({"error": str(e)})
        resp.status_code = 403
        return resp
Пример #10
0
    def get(self):
        groupid=self.request.get('groupid')
        tagmap={}
        for tag in Tag.all():
            tagmap[str(tag.key().id())]=tag.name

        username=get_current_user(self)
        user=getorAddUser(username)
        if groupid:
            groupid=int(groupid)
#            group=Group.get_by_id(groupid)
            group=getGroup(groupid)
            if group.author==username:
                group.delete()
                nlist=[]
                rnlist=[]
                for n in Note.all().filter('group =',groupid):
                    nlist.append(n)
                    rnlist.append('r'+str(n.key().id()))
                db.delete(Replay.get_by_key_name(rnlist))
                db.delete(nlist)
                if groupid in user.createGroup:
                    user.createGroup.remove(groupid)
                    user.put()
                if groupid in user.createGroupAdd:
                    user.createGroupAdd.remove(groupid)
                    user.put()


        groupidlist=user.createGroup+user.createGroupAdd
        list=Group.get_by_id(groupidlist)
#        list=Group.all().filter('author =',username)
        listgroup=[]
        ischange=False
        for i,group in enumerate(list):
            if not group:
                if groupidlist[i] in user.createGroup:
                    user.createGroup.remove(groupidlist[i])
                    ischange=True
                if groupidlist[i] in user.createGroupAdd:
                    user.createGroupAdd.remove(groupidlist[i])
                    ischange=True
            else:
                group.tagname=tagmap.get(str(group.tag),'')
                listgroup.append(group)
        if ischange:
            user.put()
        self.render('templates/removegroupList.html',{'list':listgroup})
def test_del_contact_in_group(app, db):
    if len(db.get_contact_list()) == 0:
        app.contact.create(Contact(firstname="Vlad", lastname="hater"))
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test"))
    groups = db.get_groups_with_contacts()
    group = random.choice(groups)
    group_id = group.id
    contacts = db.get_contacts_in_group()
    contact = random.choice(contacts)
    contact_id = contact.id
    if len(db.get_contacts_in_group()) == 0:
        app.contact.add_contact_to_group(contact_id, group_id)
    old_contacts = db.get_contacts_in_group()
    app.contact.del_contact_in_group(contact_id, group_id)
    new_contacts = db.get_contacts_in_group()
    assert len(old_contacts) - 1 == len(new_contacts)
Пример #12
0
 def get(self):
     msgid=self.request.get('msg')
     msg=None
     if msgid:
         msg=memcache.get(msgid)
     newrsslist=getNewRssList()
     if newrsslist==None:
         newrsslist=NewRSSList(key_name='newrsslist')
         newrsslist.put()
         memcache.set('newrsslist',newrsslist,360000)
     groupids=newrsslist.groupids
     groupids.reverse()
     if groupids:
         grouplist=Group.get_by_id(groupids)
     else:
         grouplist=[]
     self.render('templates/newrss.html',{'list':grouplist,'msg':msg})
Пример #13
0
    def post(self):
        groupid=self.request.get('groupid')
        if groupid:
            groupid=int(groupid)
            newrsslist=getNewRssList()

            if not  newrsslist or not Group.get_by_id(groupid) :
                msg=u'添加失败,群不存在。'
            elif newrsslist and groupid not in newrsslist.groupids:
                newrsslist.groupids.append(groupid)
                newrsslist.put()
                memcache.set('newrsslist',newrsslist,360000)
                msg=u'添加成功。'
            else:
                msg=u'添加失败,已经存在。'
        else:
            msg=u'添加失败,没有群号'

        msgid=str(uuid.uuid4())
        memcache.set(msgid,msg,3600)
        self.redirect('/NewRSSListM?msg='+msgid)
def test_add_contact_in_group(app, db, check_ui):
    if len(db.get_contact_list()) == 0:
        app.contact.create(Contact(firstname="Vlad", lastname="hater"))
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="test"))
    if len(db.get_contacts_not_in_group()) == 0:
        app.contact.create(Contact(firstname="Vlad", lastname="hater"))
    group = app.group.get_group_list()
    groups = random.choice(group)
    group_id = groups.id
    contacts = db.get_contacts_not_in_group()
    contact = random.choice(contacts)
    contact_id = contact.id
    print(db.get_contacts_in_group())
    old_contact = db.get_contacts_in_group()
    app.contact.add_contact_to_group(contact_id, group_id)
    new_contacts = db.get_contacts_in_group()
    assert len(old_contact) + 1 == len(new_contacts)
    contact_ui = db.get_contacts_in_group()
    if check_ui:
        assert sorted(contact_ui, key=Contact.id_or_max) == sorted(
            app.group.get_group_list(), key=Contact.id_or_max)
Пример #15
0
    def get(self):
        username=get_current_user(self)
        grouplist=[]
        noteid=self.request.get('Noteid',0)
        note={}
        imglist=[]
        if noteid:
            note=Note.get_by_id(int(noteid))
            if note:
                imgstrlist=re.findall('(?i)templink/([^/\s\?&]*)/',note.content)

                for img in imgstrlist:
                    img=int(img)
                    imglist.append(img)
                imglist=Img.get_by_id(imglist)
                news, number = re.subn('[\*TempLink/([^/]*/[^\]]*]','', note.content)
                note.content=news
        groupid=self.request.get('GroupId')
        if note:
            groupid=note.group
        group=None
        if groupid:
#            group=Group.get_by_id(int(groupid))
            group=getGroup(int(groupid))
        if not group:
            if '000'==username:
                self.redirect('/GroupListM')
                return
            else:
                for g in Group.all().filter('author =',username):
                    grouplist.append(g)

        msg=memcache.get(self.request.get('msgid',''))
        if not msg:
            msg=''
        self.render('templates/noteAdd.html',{'group':group,'grouplist':grouplist,'note':note,'imglist':imglist,'msg':msg})
Пример #16
0
from model.models import Group

testdata = [
    Group(name="name1", header="header1", footer="footer1"),
    Group(name="name2", header="header2", footer="footer2")
]
Пример #17
0
    opts, args = getopt.getopt(sys.argv[1:], "n:f:", ["Number_of_groups", "file"])
except getopt.GetoptError as err:
    getopt.usage()
    sys.exit(2)

n = 2
f = "data/groups.json"


for o, a in opts:
    if o == "-n":
        n = int(a)
    elif o == "-f":
        f = a


def random_string(prefix, maxlen):
    symbols = string.ascii_letters + string.digits + string.punctuation + " "*10
    return prefix + "".join([random.choice(symbols) for i in range(random.randrange(maxlen))])


testdata = [
    Group(name=random_string("name", 10), header=random_string("header", 20), footer=random_string("footer", 20))
    for i in range(6)
]

file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", f)

with open(file, "w") as out:
    jsonpickle.set_encoder_options("json", indent=2)
    out.write(jsonpickle.encode(testdata))
Пример #18
0
 def convert(group):
     return Group(id=str(group.id),
                  name=group.name,
                  header=group.header,
                  footer=group.footer)
Пример #19
0
 def get(self):
     self.render('templates/group.html',{'grouplist':Group.all(),'taglist':Tag.all()})
Пример #20
0
def new_group(name, header, footer):
    return Group(name=name, header=header, footer=footer)
Пример #21
0
def non_empty_group_list(db, app):
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name="new name"))
    return db.get_group_list()
Пример #22
0
    def post(self):
        try:
            userName=self.request.get("UserName")
            user=getorAddUser(userName)
            dm=self.request.get("dm")
            dmall=self.request.get("dmall")
            type_n=self.request.get("type_n")
            name=self.request.get("name")
            ###操作类型
            do=self.request.get('DoType')# '1'为加入 '2'为退订
            groupId=self.request.get('GroupId')
            if do=='1':
                #### 下面是加入群
                realNo=dmall
                if dmall=='sh000001':
                    dm=dmall
                if type_n in ['11','12']:
                    pass
#                    dm=dmall
                elif type_n == '31':
                    realNo='hk'+dm
                    #dm=realNo

                elif type_n=='41':
                    realNo='gb_'+dm
                    #dm=realNo
                else:
                    self.response.out.write(resultStr%('fail',u'只能订阅A股、B股、港股、美股',''))
                    return
                gupiaoToGroup=memcache.get('gupiaodm'+dm)
                if not gupiaoToGroup:
                    gupiaoToGroup=GupiaoToGroup.get_by_key_name(key_names='g'+dm)
                    if gupiaoToGroup:
                        memcache.set('gupiaodm'+dm,gupiaoToGroup,36000)
                if not gupiaoToGroup:
                    group=Group()
                    group.name=name
#                    if type_n =='11':
#                        group.gonggao=u'A股'
#                    if type_n =='12':
#                        group.gonggao=u'B股'
                    if type_n =='31':
                        group.gonggao=u'[港]'
                    if type_n =='41':
                        group.gonggao=u'[美]'
                    group.type=4
                    group.apptype='4'
                    group.author='000'
                    group.head=int(type_n)
                    group.notecount=1
                    group.put()
                    guPiaoNote=GuPiaoNote(key_name='g'+str(group.key().id()))
                    guPiaoNote.imagestr='_%s_%s'%(realNo,type_n)
                    guPiaoNote.updateTime=datetime.datetime.utcnow()+timezone
                    guPiaoNote.put()
                    gupiaoToGroup=GupiaoToGroup(key_name='g'+dm)
                    gupiaoToGroup.group=group.key().id()
                    gupiaoToGroup.name=name
                    gupiaoToGroup.dmall=dmall
                    gupiaoToGroup.type=type_n
                    gupiaoToGroup.put()
                    #######
                    ###同步给股票同步应用
                    result = urlfetch.fetch(
                        url =setting.GUPIAOURL+'/markGroup?groupid=%s&dm=%s&type=%s&realNo=%s'%(group.key().id(),dm,type_n,realNo),
        #                    payload = login_data,
                        method = urlfetch.GET,
                        headers = {'Content-Type':'application/x-www-form-urlencoded',
                                   'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6'},
                        follow_redirects = False,deadline=20)
                    if result.status_code != 200 :
                        group.delete()
                        gupiaoToGroup.delete()
                        guPiaoNote.delete()
                        self.response.out.write(resultStr%('fail',u'订阅股票失败,请稍后再试',''))
                        return
                    else:
                        memcache.set('gupiaodm'+dm,gupiaoToGroup,36000)
                        logging.info(result.content)
                        logging.info(guPiaoNote.content)
                        if result.content!=guPiaoNote.content:
                            guPiaoNote.content=result.content.decode('utf-8')
                            guPiaoNote.updateTime=datetime.datetime.utcnow()+timezone
                            guPiaoNote.put()


                else:
                    group=memacheGroup(gupiaoToGroup.group)
                if group:
                    if userName not in group.member:
                        group.member.append(userName)
                        group.put()
                    if group.key().id() not in user.memberGroup:
                        if group.key().id() not in user.memberGroupAdd:
                            user.memberGroupAdd.append(group.key().id())
                            user.put()
                        if group.key().id() in user.memberGroupRemove:
                            user.memberGroupRemove.remove(group.key().id())
                            user.put()
                else:
                    self.response.out.write(resultStr%('fail',u'订阅股票失败,股票已被删除',''))
                    return


            elif do=='2':
                ##### 下面是退出群 退订股票
                if groupId:
                    try:
                        groupId=int(groupId)
                    except Exception,e:
                        logging.info(str(e))
                        self.response.out.write('1')
                        return
                    group=memacheGroup(groupId)
                    if userName in group.member:
                        group.member.remove(userName)
                    if group.key().id() in user.memberGroup:
                        user.memberGroup.remove(group.key().id())
                        if group.key().id() not in user.memberGroupRemove:
                            user.memberGroupRemove.append(group.key().id())
                            if group.key().id() in user.memberGroupAdd:
                                user.memberGroupAdd.remove(group.key().id())
            self.response.out.write(resultStr%('success','',setting.WEBURL[7:]+'/InfoUpdate'))
Пример #23
0
 def clean(group):
     return Group(id=group.id, name=group.name.strip())