1. wang wanqing
  2. zpage

Commits

zuroc  committed 6f5bea0 Merge

fix

  • Participants
  • Parent commits e28dc04, 0e15ac2
  • Branches default

Comments (0)

Files changed (19)

File ctrl/me/i.py

View file
  • Ignore whitespace
 
     txt = self.get_argument('txt', '')
     if txt:
+        txt = txt.replace("\r\n","\n").replace("\r","\n")
         txt_new(current_user_id, txt)
 
     birthday = self.get_argument('birthday', '0')

File ctrl/zsite/index.py

View file
  • Ignore whitespace
 from zkit.escape import json_encode 
 from model.po_tag import REDIS_REC_CID_DICT, po_tag_by_cid 
 from model.autocomplete_tag import autocomplete_tag
+from zsite_user import render_zsite_user
 #from model.po_tag import po_tag
 def render_zsite_site(self, n=1, page_template='/-%s'):
     zsite_id = self.zsite_id
         zsite_cid = zsite.cid
 
         if zsite_cid == CID_USER:
-            self.render("/ctrl/zsite/index/user.htm")
+            render_zsite_user(self)
         elif zsite_cid == CID_SITE:
         #if zsite_cid == CID_SITE:
             li, page = render_zsite_site(self, n)
 from model.zsite import Zsite
 from model.zsite_star import ZsiteStar
 from model.po import Po
+from cgi import escape
+
 def render_zsite_star(self, n=1):
     self.zsite.star = star = ZsiteStar.mc_get(self.zsite_id)
     star.user = Zsite.mc_get(star.user_id)

File ctrl/zsite/zsite_user.py

View file
  • Ignore whitespace
+from cgi import escape 
+from model.user_school import user_school_tuple
+from model.career import career_list_all
+from model.user_info import UserInfo, MARRY_ONE
+
+def _left_html_hight(career_list, school_tuple, info):
+    height = 0 
+    for i in career_list:
+        unit = career.unit
+        title = career.title
+        txt = career.txt
+        end_time = career.end_time
+        if end_time or (title and txt):
+            height+=73
+        else:
+            height+=50
+
+    for id, school_id, school_year, school_degree, title, txt in school_tuple:
+        if school_year or school_degree:
+            height += 73
+        else:
+            height += 50
+    
+    if home:
+        height+50
+ 
+    return height+73
+
+
+def _right_html_hight(txt):
+    txt = txt.rstrip().split("\n")
+
+    height = 0
+    if txt: 
+        for i in txt:
+            if i:
+                height+=28*(int(len(i.decode("utf-8","ignore").encode("gb18030","ignore"))/38)+1)
+                height+=14 
+
+        txt = "<p>%s</p>"%(
+            "</p><p>".join(
+                map(escape, txt)
+            )
+        )
+        height -= 14
+    return txt, height 
+
+def render_zsite_user(self):
+    zsite_id = self.zsite_id 
+    zsite = self.zsite
+
+    info = UserInfo.mc_get(zsite_id)
+    career_list = career_list_all(zsite_id)
+    school_tuple = user_school_tuple(zsite_id)
+
+    motto_left = False
+    motto = motto_get(zsite_id)
+
+    if motto:
+        left_height = _left_html_hight(career_list, school_tuple, info)
+        txt , right_hight = _right_html_hight(zsite.txt)
+
+        if right_hight - left_height > 41:
+            motto_left = True
+
+
+    self.render(
+        "/ctrl/zsite/index/user.htm",
+        txt=txt,
+        motto_left=motto_left,
+        info=info,
+        career_list=career_list,
+        school_tuple=school_tuple,
+        motto=motto
+    )
+

File god/vps.py

View file
  • Ignore whitespace
 from _urlmap import urlmap
 from model.vps_sell import VpsOrder , vps_order_count, vps_order_by_state, vps_one_list_by_vps_order, vps_one_open, vps_order_open, VPS_ORDER_STATE_PAY, vps_one_by_state, vps_order_cancel, VpsOne, VpsOneIp, vps_one_expire_list, vps_one_ip_rm, vps_one_ip_new, vps_one_rm
 from model.vps_ip import vps_ip_new, vps_ip_list, vps_ip_count, vps_ip_rm
-from model.vps_real import vps_real_new, vps_real_list
+from model.vps_host import vps_host_new, vps_host_list
 from zkit.page import page_limit_offset
 from zkit.ip import ip2int
 from model.user_mail import user_id_by_mail
     def post(self, id):
         ip = self.get_argument('ip','')
         ram_count = self.get_argument('ram_count', '')
-        disk_count = self.get_argument('disk_count','')
+        hd_count = self.get_argument('hd_count','')
         txt = self.get_argument('txt','')
-        if ip and ram_count and disk_count:
-            vps_real_new(
+        if ip and ram_count and hd_count:
+            vps_host_new(
                 ip,
                 id,
-                ram_count,
-                disk_count,
+                float(ram_count),
+                hd_count,
                 txt
             )        
         return self.redirect('/vps/room/%s/pc'%id)
 
-@urlmap('/vps/room/pc/(\d+)')
+@urlmap('/vps/room/(\d+)/pc')
 class VpsRoomPc(Base):
     def get(self, id):
-        return self.render(ol=vps_real_list(id), id=id)
+        return self.render(ol=vps_host_list(id), id=id)
 
 
 

File htm/_util/_g1.htm

View file
  • Ignore whitespace
 %>
 
 
-<%def name="about_me(zsite_id, is_owner)">
+<%def name="about_me(zsite_id, is_owner, info=None, career_list=None, school_tuple=None)">
 <%
 namecard = namecard_get(zsite_id)
-info = UserInfo.mc_get(zsite_id)
+
+if info is None:
+    info = UserInfo.mc_get(zsite_id)
+if career_list is None:
+    career_list = career_list_all(zsite_id)
+if school_tuple is None:
+    school_tuple = user_school_tuple(zsite_id)
 
 line1     = []
 pid_now   = None
 home = None
 sex = None
 astrology = None
+age = None
 if info:
 
     if info.pid_home and info.pid_home>1:
 
     astrology = s
 
-career_list = career_list_all(zsite_id)
-school_tuple = user_school_tuple(zsite_id)
 
 %>
 %if astrology or pid_now or is_owner:
 <div class="user_txt">\
     %if pid_now:
-<span class="user_alt\
+<span class="user_alt user_alt_place\
 %if pid_now!=pid_now_city:
- user_alt_yearw user_alt_place
+ user_alt_yearw 
 %endif
 ">\
 <span id="user_at">@</span>${place_name(pid_now_city)}\
 %endif
 </span>\
     %endif
-<div class="user_alt_unit">${astrology}\
+<div class="user_alt_unit">\
+%if astrology:
+${astrology}\
+%endif
 %if age:
 <div class="user_alt_txt"><span class="mr3">${age}</span>岁
-%if marry and age:
+%if age and marry==MARRY_ONE:
  , 
 %endif
 %if marry == MARRY_ONE:
 单身\
 %endif
+%if not sex and is_owner:
+<a class="c00f" href="/i">设置性别</a>\
+%endif
 </div>
 %endif
 </div>\
-%if not sex:
-<a class="c00f" href="/i">设置性别</a>\
-%endif
 </div>\
 %endif
 %if is_owner and not career_list and not school_tuple:
 end_time = career.end_time
 %>
 <div class="user_txt">\
-<span class="user_alt user_alt_yearw">\
+<span class="user_alt\
+%if end_time:
+ user_alt_yearw\
+%endif
+">\
 %if unit:
 ${unit}\
 %endif
 %if school_tuple:
 %for id, school_id, school_year, school_degree, title, txt in school_tuple:
 <div class="user_txt">\
-<span class="user_alt user_alt_yearw">\
+<span class="user_alt\
+%if school_year or school_degree:
+ user_alt_yearw\
+%endif
+">\
 %if school_id:
 ${SCHOOL_UNIVERSITY[school_id]}
 %endif
 
 %if home:
 <div class="user_txt">\
-<span class="user_alt user_alt_yearw">家乡</span>\
+<span class="user_alt">家乡</span>\
 <div class="user_alt_unit">${home}</div>
 </div>\
 %endif

File htm/ctrl/zsite/index/user.htm

View file
  • Ignore whitespace
 from model.fav import fav_po_count_by_user_id
 from model.motto import motto_get
 from model.follow import follow_get
-from cgi import escape
 %>
 
 <%inherit file="/ctrl/_base/_base2.htm" />
 <img src="${pic_url_with_default(zsite_id, 266)}">
 </div>
 <div id="user_left" class="c"><div id="user_left3"><div id="user_left3in">\
-<%
-motto = motto_get(zsite_id)
-txt = zsite.txt
-if txt:
-    txt = "<p>%s</p>"%(
-        "<p></p>".join(
-            map(escape, txt.rstrip().split("\n"))
-        )
-    )
-%>
-%if motto:
+%if motto and not motto_left:
 <div id="user_motto"
 %if not txt:
 style="border-bottom:0"
 </div></div>
 <div id="user_left2">\
 <h1 id="zsite_name">${zsite.name}</h1>\
-${about_me(zsite_id, is_owner)}\
+${about_me(zsite_id, is_owner, info, career_list, school_tuple)}\
+%if motto and motto_left:
+<div id="user_motto">${motto}</div>\
+%endif
 </div></div>
 </div></div></div>
  

File htm/god/vps/room_ip.htm

View file
  • Ignore whitespace
 <%inherit file="_base.htm" />
 <%!
 from model.vps_sell import VPS_COUNTRY_DICT
-from model.vps_real import vps_real_count 
+from model.vps_host import vps_host_count 
 from model.vps_ip import vps_ip_used_total
 %>
 <%
-real_count = vps_real_count()
+real_count = vps_host_count()
 used, total = vps_ip_used_total()
 %>
 <h2 class="vps_ip_h2">
 _real_count = real_count.get(room_id, '')
 %>
 %if _real_count:
-<a class="real_count" href="/vps/room/pc/${room_id}">\
+<a class="real_count" href="/vps/room/${room_id}/pc">\
 ${_real_count}</a>\
 %endif
 </td>

File htm/god/vps/vps_room_pc.htm

View file
  • Ignore whitespace
 <table class="vps_room">
 <tr>
     <th class="tc">编号</th>
+    <th class="tc">虚拟机数</th>
     <th class="tc">硬盘</th>
     <th class="tc">内存</th>
     <th class="tc">IP</th>
 %for i in ol:
 <tr class="ip_line">
 <td class="tc">${i.id}</td>
-<td class="tc">${i.disk_used} / ${i.disk_count}</td>
-<td class="tc">${i.ram_used} / ${i.ram_count}</td>
+<td class="tc">${i.vps_count}</td>
+<td class="tc">${i.hd_used} / ${i.hd_count}</td>
+<td class="tc">${i.ram_used/1024} / ${(i.ram_count/1024)}</td>
 <td class="tc">${int2ip(i.ip)}</td>
 <td class="tc"><pre>${i.txt}</pre></td>
 </tr>

File htm/god/vps/vps_room_pc_new.htm

View file
  • Ignore whitespace
 <span class="desc">给 VPS 预留的内存 , 单位G</span>
 </div>
 <div class="item">
-<label>可用硬盘</label><input name="disk_count" autocomplete="off">\
+<label>可用硬盘</label><input name="hd_count" autocomplete="off">\
 <span class="desc">给 VPS 预留的硬盘 , 单位G</span>\
 </div>
 <div class="item">
     vps_room_ip.submit(function(){
         var ip=vps_room_ip.find('input[name=ip]'), ip_val=$.trim(ip.val());
         ip.val(ip2int(ip_val)||'')
-        return must_have('ip', 'IP') && must_have('disk_count', '可用硬盘') && must_have('ram_count', '可用内存')
+        return must_have('ip', 'IP') && must_have('hd_count', '可用硬盘') && must_have('ram_count', '可用内存')
     })
 })()
 </script>

File misc/backup/table_main.sql

View file
  • Ignore whitespace
   UNIQUE KEY `vps_type_id` (`vps_type_id`,`cid`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;
-DROP TABLE IF EXISTS `vps_real`;
+DROP TABLE IF EXISTS `vps_host`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
 /*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `vps_real` (
+CREATE TABLE `vps_host` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `ip` int(10) unsigned NOT NULL,
   `data_center` int(10) unsigned NOT NULL,
   `ram_count` int(10) unsigned NOT NULL,
   `ram_used` int(10) unsigned NOT NULL DEFAULT '0',
   `state` tinyint(3) unsigned NOT NULL,
-  `disk_used` int(10) unsigned NOT NULL DEFAULT '0',
-  `disk_count` int(10) unsigned NOT NULL,
+  `hd_used` int(10) unsigned NOT NULL DEFAULT '0',
+  `hd_count` int(10) unsigned NOT NULL,
   `vps_count` int(10) unsigned NOT NULL DEFAULT '0',
   `txt` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
   PRIMARY KEY (`id`),

File misc/once/test/vps_autoopen.py

View file
  • Ignore whitespace
 import _env
 from model.vps_sell import VpsOrder, vps_order_auto_open
 
-order = VpsOrder.get(88)
+order = VpsOrder.get(123)
 vps_order_auto_open(order)
 

File misc/once/user_img.py

View file
  • Ignore whitespace
         with open(path) as img:
             pic = picopen(img.read())
             if pic:
-                p3 = pic_fit_height_if_high(pic, 266, 266)
+                p3 = pic_square(pic, 266, size=266)
                 fs_set_jpg('266', i.id, p3)
                 height , width = pic.size
                 redis.hset(

File model/ico.py

View file
  • Ignore whitespace
     p3 = pic_fit_height_if_high(pic, 219, 123)
     fs_set_jpg('219', pic_id, p3)
     
-    p4 = pic_fit_height_if_high(pic, 266, 266)
+    p4 = pic_square(pic, 266, size=266)
     fs_set_jpg('266', pic_id, p4)
 
 def pic_url(id, size='721'):

File model/txt.py

View file
  • Ignore whitespace
 
 if __name__ == '__main__':
     pass
+    from zweb.orm import ormiter
+    for i in ormiter(Txt):
+        i.txt = i.txt.replace("\r\n","\n").replace("\r","\n")
+        i.save()
+        print i.id
+

File model/vps_host.py

View file
  • Ignore whitespace
+#coding:utf-8
+
+#CREATE TABLE  `zpage`.`vps_host` (
+#  `id` int(10) unsigned NOT NULL auto_increment,
+#  `ip` int(10) unsigned NOT NULL,
+#  `data_center` int(10) unsigned NOT NULL,
+#  `ram_count` int(10) unsigned NOT NULL,
+#  `ram_used` int(10) unsigned NOT NULL,
+#  `state` tinyint(3) unsigned NOT NULL,
+#  `hd_used` int(10) unsigned NOT NULL,
+#  `hd_count` int(10) unsigned NOT NULL,
+#  `vps_count` int(10) unsigned NOT NULL default '0',
+#txt
+#  PRIMARY KEY  (`id`),
+#  KEY `index_2` USING BTREE (`data_center`,`state`)
+#) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+from _db import McModel, Model, McNum, McCache, mc, redis, McCacheM
+
+REDIS_VPS_REAL = 'VpsHost' #记录data_center的机器数目
+
+VPS_REAL_STATE_STOP = 10 #未启用
+VPS_REAL_STATE_RUN = 20
+
+
+class VpsHost(Model):
+    @property
+    def ram_used(self):
+        return self.ram_count - self.ram_remain
+
+    @property
+    def hd_used(self):
+        return self.hd_count - self.hd_remain
+
+def vps_host_new(ip, data_center, ram_count, hd_count, txt):
+    data_center = int(data_center)
+    ram = int(ram_count*1024)
+    real = VpsHost(
+        ip=ip,
+        data_center=data_center,
+        ram_count=ram,
+        ram_remain=ram,
+        hd_count=hd_count,
+        hd_remain=hd_count,
+        state=VPS_REAL_STATE_RUN,
+        txt=txt
+    )
+    real.save()
+    redis.hincrby(REDIS_VPS_REAL, data_center, 1)
+    return real.id
+
+def vps_host_count():
+    return redis.hgetall(REDIS_VPS_REAL)
+
+def vps_host_list(data_center):
+    return VpsHost.where(data_center=data_center)
+
+def vps_host_id_bind(vps):
+    if vps.host_id:
+        return
+    data_center = vps.data_center
+    ram = vps.ram
+    hd = vps.hd
+    host = VpsHost.where(data_center=data_center).where(
+        "ram_remain>%s and hd_remain>%s", ram, hd
+    ).order_by('ram_remain')[:1]
+    if host:
+        host = host[0]
+        vps.host_id = host.id
+        host.vps_count += 1
+        host.ram_remain -= ram
+        host.hd_remain -= hd
+        host.save()
+
+def vps_host_rm(vps):
+    host_id = vps.host_id
+    if not host_id:
+        return
+    host = VpsHost.get(host_id)
+    host.vps_count -= 1
+    host.ram_remain += vps.ram
+    host.hd_remain += vps.hd
+    host.save()
+    
+
+
+if __name__ == '__main__':
+    #print v
+    print host
+    raise
+    #    i.delete()
+    #

File model/vps_real.py

  • Ignore whitespace
-#coding:utf-8
-
-#CREATE TABLE  `zpage`.`vps_real` (
-#  `id` int(10) unsigned NOT NULL auto_increment,
-#  `ip` int(10) unsigned NOT NULL,
-#  `data_center` int(10) unsigned NOT NULL,
-#  `ram_count` int(10) unsigned NOT NULL,
-#  `ram_used` int(10) unsigned NOT NULL,
-#  `state` tinyint(3) unsigned NOT NULL,
-#  `disk_used` int(10) unsigned NOT NULL,
-#  `disk_count` int(10) unsigned NOT NULL,
-#  `vps_count` int(10) unsigned NOT NULL default '0',
-#txt
-#  PRIMARY KEY  (`id`),
-#  KEY `index_2` USING BTREE (`data_center`,`state`)
-#) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-
-from _db import McModel, Model, McNum, McCache, mc, redis, McCacheM
-
-REDIS_VPS_REAL = "VpsReal" #记录data_center的机器数目
-
-VPS_REAL_STATE_STOP   = 10 #未启用
-VPS_REAL_STATE_RUN    = 20 
-
-
-class VpsReal(Model):
-    pass
-
-def vps_real_new(ip, data_center, ram_count, disk_count, txt):
-    data_center = int(data_center)
-    real = VpsReal(
-        ip = ip,
-        data_center = data_center,
-        ram_count=ram_count,
-        disk_count=disk_count,
-        state = VPS_REAL_STATE_RUN,
-        txt=txt
-    )
-    real.save()
-    redis.hincrby(REDIS_VPS_REAL, data_center, 1)
-    return real.id
- 
-def vps_real_count():
-    return redis.hgetall(REDIS_VPS_REAL)
-
-def vps_real_list(data_center):
-    return VpsReal.where(data_center=data_center)
-
-

File model/vps_sell.py

View file
  • Ignore whitespace
 from zkit.ip import int2ip
 from zkit.password import password_random
 from model.vps_ip import vps_ip_autobind, vps_ip_bind, vps_ip_unbind
+from vps_host import VpsHost, vps_host_id_bind, vps_host_rm
 from const.vps import * 
 
 MAIL_VPS_ORDER = '42qu-vps-order@googlegroups.com'
         for i in xrange(diff):
             vps = _vps_one_pay(
                 user_id, os, country, data_center,
-                host_id_by_data_center(data_center) ,
                 cpu, ram, hd, netflow, vps_price.days,
                 vps_type.id
             )
-            vps.save()
             VpsOneOrder(
                 vps_one_id=vps.id,
                 vps_order_id=vps_order_id,
     #o.ip_detail = vps_ip_autobind(o)
     return result
 
-def _vps_one_pay(user_id, os, country, data_center, host_id, cpu, ram, hd, netflow, days, vps_type_id):
+def _vps_one_pay(user_id, os, country, data_center,  cpu, ram, hd, netflow, days, vps_type_id):
     today = today_days()
     o = VpsOne(
         user_id=user_id,
         state=VPS_STATE_PAY,
         txt='',
         vps_type_id=vps_type_id
-        )
+    )
+    vps_host_id_bind(o)
     o.save()
     return o
 
 
 def vps_one_rm(vps_id):
     one = VpsOne.get(vps_id)
-    if one:
+    if one and one.state > VPS_STATE_RM:
+        vps_host_rm(one)
         one.state_set(VPS_STATE_RM)
 
 def vps_mv(from_id, to_id):
     mc.set(MC_VPS_ONE_EXPIRE_COUNT, count, ONE_DAY)
     return ol
 
-def host_id_by_data_center(data_center):
-    if data_center == 1:
-        return 2
 
 
 def vps_order_auto_open(order):
         #    continue
         #if not i.ip_autobind():
         #    continue
+
         host_id = i.host_id
         from yun.vps.server.model.vps import vps_saas_cmd_open
         if not host_id:
 
 if __name__ == '__main__':
     pass
+    ########################################################
+    #绑定机器
+    from model.vps_sell import VpsOne
+    from vps_host import VpsHost, vps_host_id_bind
+    for i in VpsHost.where():
+        i.vps_count = 0
+        i.hd_remain = i.hd_count
+        i.ram_remain = i.ram_count
+        i.save()
 
-    for i in VpsOne.where(data_center=1).order_by("id"):
-        print i.id,"\t", " ".join(i.ip_list)
-    
-    for i in VpsOne.where("data_center!=1").order_by("id"):
-        print i.id,"\t", " ".join(i.ip_list)
+    for i in VpsOne.where("state>=%s",VPS_STATE_PAY):
+        i.host_id = 0
+        print i.id,i.hd
+        i.save()
+
+    for i in VpsOne.where("state>=%s",VPS_STATE_PAY):
+        vps_host_id_bind(i)  
+        print i.host_id 
+        i.save()
+    ###############################################################
+
+ 
+   # for i in VpsOne.where(data_center=1).order_by("id"):
+   #     print i.id,"\t", " ".join(i.ip_list)
+   # 
+   # for i in VpsOne.where("data_center!=1").order_by("id"):
+   #     print i.id,"\t", " ".join(i.ip_list)
 
 #   # vps_close(12)
 #    

File model/zsite.py

View file
  • Ignore whitespace
 #        path = '/mnt/zpage/%s'%s[18:]
 #        if not  exists(path):
 #            print path
-    from model.po import Po
-    zsite = Po.mc_get(10280391)
-    print zsite.user_id, zsite.create_time
+#    from model.po import Po
+#    zsite = Po.mc_get(10280391)
+#    print zsite.user_id, zsite.create_time
 
 

File static/css/ctrl/zsite/index/user.css

View file
  • Ignore whitespace
 }
 .user_alt_txt{
 font-size:12px;line-height:18px;color:#333;
-width:200px;
+}
+.user_alt_txt,.user_alt_unit{
+width:180px;
 }
 .user_alt_txt,.user_alt_year{
 font-family: Tahoma, Geneva, sans-serif;
 margin-bottom: 64px; 
 width: 266px;
 }
-
 #user_motto{
-line-height: 43px; border-bottom: 1px dotted #ccc; 
+line-height: 41px; 
+}
+#user_left2 #user_motto{
+border-top:1px dotted #ccc; 
+margin-top:38px;
+padding-top:38px;
+}
+#user_left3in #user_motto{
+border-bottom: 1px dotted #ccc; 
 margin-bottom: 38px;
 padding-bottom: 38px;
 }