示例#1
0
 def post(self):
     bin = Bin()
     if bool( self.request.get( 'privatebin' ) ):
         bin.privatebin = make_cookie_vague( bin )
     bin.escapehtml = bool( self.request.get( 'escapehtml' ) )
     bin.put()
     emit_cookie( self, bin )
     self.redirect('/%s' % bin.name)
示例#2
0
 def _get_bin(self, path):
     name = path[1:].split('/')[0]
     bin = Bin.all().filter('name =', name).get()
     if bin:
         return bin
     else:
         raise NotFound()
示例#3
0
    def post(self):
        app = App.instance()
        app.total_posts += 1
        app.put()
        ip = self.request.get('ip')
        bin = self.request.get('bin')
        size = int(self.request.get('size'))
        day = datetime.datetime.now().day

        daily_ip_key = 'usage-%s-%s' % (day, ip)
        daily_ip_usage = memcache.get(daily_ip_key) or 0
        memcache.set(daily_ip_key, int(daily_ip_usage) + size, time=24 * 3600)
        if daily_ip_usage > 500000000:  # about 500MB
            mail.send_mail(sender="*****@*****.**",
                           to="*****@*****.**",
                           subject="PostBin user IP over quota",
                           body=ip)

        daily_bin_key = 'usage-%s-%s' % (day, bin)
        daily_bin_usage = memcache.get(daily_bin_key) or 0
        memcache.set(daily_bin_key,
                     int(daily_bin_usage) + size,
                     time=24 * 3600)
        if daily_bin_usage > 10485760:  # 10MB
            obj = Bin.get_by_name(bin)
            obj.delete()
示例#4
0
 def _get_bin(self):
     name = self.request.path.replace('/', '')
     bin = Bin.all().filter('name =', name).get()
     if bin:
         return bin
     else:
         self.redirect('/')
示例#5
0
文件: bin.py 项目: bholtsclaw/postbin
 def _get_bin(self, path):
     name = path[1:].split('/')[0]
     bin = Bin.all().filter('name =', name).get()
     if bin:
         return bin
     else:
         raise NotFound()
示例#6
0
 def post(self):
     name = self.request.path.split('/')[-1]
     if is_valid_postbin_name( name ):
         bin = Bin.all().filter( 'name =', name ).get() # FIX: is this expensive?
         if bin and check_postbin_access( self, bin ):
             if bin.post_set:
                 [p.delete() for p in bin.post_set]
             bin.delete()
     self.redirect( '/' )
示例#7
0
 def post(self):
     city = None
     if self.request.get("city").lower() != "":
         if not getCityObjectByName(self.request.get("city").lower()):
             city = City()
             city.name = self.request.get("city").lower()
             city.put()
         else:
             city = getCityObjectByName(self.request.get("city").lower())
         bin = None
         if not getBinObjectByName(city.key,
                                   self.request.get("bin_name").lower()):
             bin = Bin(parent=city.key)
             bin.name = self.request.get("bin_name").lower()
             bin.image = self.request.get("image").lower()
             bin.sortingInstructions = self.request.get(
                 "sorting_instructions")
             putBinObject(bin)
     else:
         pass
     bin_add_template = jinja_env.get_template("templates/addbin.html")
     self.response.out.write(bin_add_template.render())
示例#8
0
def addMultiBins(form, wh):
    bins_ = []
    bins = form.name.data.split(",")
    error = 0
    if bins:
        for bin_ in bins:
            isBin = Bin.query.filter_by(name=bin_).first()
            if isBin is None:
                abin = Bin(name=bin_, depth=form.depth.data, warehouse_id=wh)
                bins_.append(abin)

        error = db_bulk_insert(bins_)

    return error
示例#9
0
def new_tool():
    """
    Add a new special tool
    """
    form = ToolForm(request.form)

    if request.method == 'POST' and form.validate():
        # save the tool
        bin = Bin()
        save_changes(bin, form, new=True)
        flash('Tool listing created successfully.')
        return redirect('/')

    return render_template('new_tool.html', form=form)
示例#10
0
文件: funcs_.py 项目: CPJDEV/wms
def addMultiBins(form):
    bins_, abins = [], []
    bins = form.name.data.split(",")
    error = 0
    if bins:
        for bin_ in bins:
            bin_exist = Bin.query.filter_by(name=bin_).first()
            if not bin_exist:
                abin = Bin(name=bin_.upper(),
                           depth=form.depth.data,
                           warehouse_id=form.warehouse.data,
                           aisle_id=form.aisle.data)
                if bin_.upper() not in abins:
                    abins.append(bin_.upper())
                    bins_.append(abin)

        error = db_bulk_insert(bins_)

    return error
示例#11
0
 def post(self):
     binname = self.request.path.split('/')[-2]
     postname = self.request.path.split('/')[-1]
     deleteall = postname == 'all'
     if deleteall or is_valid_postbin_name( binname ):
         bin = Bin.all().filter( 'name =', binname ).get() # FIX: is this expensive?
         if bin and bin.post_set and check_postbin_access( self, bin ):
             theremustbeabetterway = True
             offset = 0
             while theremustbeabetterway:
                 post = bin.post_set.fetch( 1, offset ) # FIX: there must be a better way
                 offset += 1
                 if post:
                     if deleteall:
                         post[0].delete()
                         offset = 0
                     elif post[0].id() == postname:
                         post[0].delete()
                         theremustbeabetterway = False
                 else:
                     theremustbeabetterway = False
         self.redirect( '/%s' % (binname) )
     else:
         self.redirect( '/' )
示例#12
0
 def post(self):
     bin = Bin()
     bin.put()
     self.redirect('/%s' % bin.name)
示例#13
0
 def post(self):
     bin = Bin()
     bin.put()
     self.redirect('/%s' % bin.name)
示例#14
0
def is_valid_postbin_name( name, badchars = None ):
    if not badchars:
        badchars = re.compile( '\W' ) # \W is anything that is NOT a letter, number, or underscore
    bin = Bin.all().filter( 'name =', name ).get() # FIX: is this expensive?
    return name and bin and not badchars.search( name )
示例#15
0
 def get_by_name(cls, name):
     return Bin.all().filter('name =', name).get()