def create_default_configs(request, user, is_new, **kwargs): if is_new: cf = Config() cf.name = "Default config" cf.user = user cf.sv_motd = 'Standard capture the flag game' cf.save()
def config(self, api_port): logger.info('Configuring alcazard with state at {}', self.state_path) api_port = api_port or DEFAULT_PORT os.makedirs(self.state_path, exist_ok=True) DB.init(self.db_path) with DB: self._init_db() config = Config.select().first() if not config: from transmission.params import DEFAULT_TRANSMISSION_SETTINGS_TEMPLATE config = Config( is_fully_configured=True, transmission_settings= DEFAULT_TRANSMISSION_SETTINGS_TEMPLATE, is_dht_enabled=False, local_port_pools_fmt='9091-9291', peer_port_pools_fmt='21413-21613', ) config.api_port = api_port config.save() logger.info('Saved configuration - done.')
def init_db(): # Create the fixtures point = Point(name='John Smith', latitude='0', longitud='0.1', phone='+79000000000') point.save() config = Config(version=1, allowedRadius=1000, isDayPeriodAllowed=True) config.save()
def process(self, commit, *args, **kwargs): data = commit.data config = Config() config.id = data["id"] del data["id"] data["cuota"] = str(data["cuota"]) config.data = data # config.commits.append(commit) commit.save() config.save()
def register(request): if request.method == "GET": template = get_template('registration/register.html') context = RequestContext(request, {}) return HttpResponse(template.render(context)) elif request.method == "POST": username = strip_tags(request.POST.get('username')) password = make_password(request.POST.get('password')) title = "Pagina de " + username user = User(username=username, password=password) user.save() user = User.objects.get(username=username) config = Config(user=user, title=title, color='#D7C4B7', size=14) config.save() return HttpResponseRedirect("/") else: template = get_template('notfound.html') return HttpResponseNotFound(template.render())
def config_add(request): if request.method == 'POST': config_name = request.POST.get('config_name') cpu = request.POST.get('cpu') memory = request.POST.get('memory') disk = request.POST.get('disk') description = request.POST.get('description') print config_name, cpu, memory, disk, description server_config = Config(name=config_name, cpu=cpu, memory=memory, disk=disk, description=description) server_config.save() return HttpResponse('添加成功') return render_to_response('config_add.html')
def process(filepath, verbose=False): if not os.path.exists(filepath): raise Exception('filepath(%s) does not exists!' % filepath) configs = dict(sitename='ABCcms', siteurl='http://localhost') with open(filepath, 'r') as ff: for line in ff.readlines(): line = line.strip('\n') line = line.decode('gbk') if line == '': continue if len(line.split('=')) == 2: key, value = line.split('=') configs[key] = value else: print 'Error Data', line print configs config = Config(**configs) config.save()
from models import db, Config try: config=Config.select().where(Config.id==1).get() except: config=Config(sitename='ABCcms', siteurl='http://localhost') config.shutdown=False config.save()
def post(self): #print self.request #print self.request.body #print self.request.arguments #print self.request.files.keys() #print self.request.files['logo'] #print '-'*80 config_id = int(self.get_argument('config_id', '1')) ip = self.get_argument('ip', '') domain = self.get_argument('domain', '') sitename = self.get_argument('sitename', '') siteurl = self.get_argument('siteurl', '') title = self.get_argument('title', '') keywords = self.get_argument('keywords', '') description = self.get_argument('description', '') copyright = self.get_argument('copyright', '') shutdown = int(self.get_argument('shutdown', '0')) reason = self.get_argument('reason', '') logo = self.get_argument('logo', '') print logo try: file_dict_list = self.request.files['logo'] except KeyError: filename = None # no image uploaded else: for fd in file_dict_list: filename = fd["filename"] ext = filename.split('.')[-1] filename = 'logo%s.%s' % (str(int(1000 * (time.time()))), ext) filepath = os.path.join(MEDIA_ROOT, 'images', filename) f = open(filepath, "wb") f.write(fd["body"]) f.close() try: config = Config.select().where(Config.id == config_id).get() except: config_count = Config.select().count() if config_count > 0: raise tornado.web.HTTPError(500, 'Server Config is broken!') else: defaults = {} config = Config(sitename='ABCcms', siteurl='http://localhost') config.save() print config print 'shutdown', bool(shutdown) config.sitename = sitename config.siteurl = siteurl config.title = title config.keywords = keywords config.description = description config.copyright = copyright config.shutdown = bool(shutdown) config.reason = reason config.ip = ip config.domain = domain if filename: config.logo = filename config.save() self.redirect('/admin/channel')