def getSourceList(request): """This view returns the list of sources, used in the index-view of update. This view is not a complete website, as it is supposed to be called via AJAX""" data = {} # Create a list over sources data['sources'] = createSourceList() return render(request, "update/sourceList.tpl", data)
def getSourceList(request): """This view returns the list of sources, used in the index-view of update. This view is not a complete website, as it is supposed to be called via AJAX""" data = {} # Create a list over sources data["sources"] = createSourceList() return render(request, "update/sourceList.tpl", data)
def index(request): """The default view for the update section.""" data = {} # Create a list over sources. data['sources'] = createSourceList() # If something is posted: if (request.POST): # Create the form based on the posted data data['manualUpdateForm'] = ManualUpdateForm(request.POST, request.FILES) # If the form is considered valid: if (data['manualUpdateForm'].is_valid()): # Construct some path where we can work. workarea = Config.get("storage", "inputFiles") create = Config.get("storage", "createIfNotExists") filename = os.path.join(workarea, request.FILES['file'].name) # Create the working-directories, if needed and wanted. if (os.path.isdir(workarea) == False and create == "true"): os.makedirs(workarea) # Store the uploaded file. upload = open(filename, "wb+") for chunk in request.FILES['file'].chunks(): upload.write(chunk) upload.close() # Generate a message for the user source = Source.objects.get(pk=request.POST['source']) if (source.locked): data[ 'uploadMessage'] = "There is already an update going for this source!" else: data[ 'uploadMessage'] = "The ruleset is now uploaded, and the processing of the file is started. This might take a while however, depending on the size of the file." # Call the background-update script. subprocess.call( ['/usr/bin/snowman-manualUpdate', filename, source.name]) # If nothing is posted, create an empty form else: data['manualUpdateForm'] = ManualUpdateForm() return render(request, "update/index.tpl", data)
def index(request): """The default view for the update section.""" data = {} # Create a list over sources. data["sources"] = createSourceList() # If something is posted: if request.POST: # Create the form based on the posted data data["manualUpdateForm"] = ManualUpdateForm(request.POST, request.FILES) # If the form is considered valid: if data["manualUpdateForm"].is_valid(): # Construct some path where we can work. workarea = Config.get("storage", "inputFiles") create = Config.get("storage", "createIfNotExists") filename = os.path.join(workarea, request.FILES["file"].name) # Create the working-directories, if needed and wanted. if os.path.isdir(workarea) == False and create == "true": os.makedirs(workarea) # Store the uploaded file. upload = open(filename, "wb+") for chunk in request.FILES["file"].chunks(): upload.write(chunk) upload.close() # Generate a message for the user source = Source.objects.get(pk=request.POST["source"]) if source.locked: data["uploadMessage"] = "There is already an update going for this source!" else: data[ "uploadMessage" ] = "The ruleset is now uploaded, and the processing of the file is started. This might take a while however, depending on the size of the file." # Call the background-update script. subprocess.call(["/usr/bin/snowman-manualUpdate", filename, source.name]) # If nothing is posted, create an empty form else: data["manualUpdateForm"] = ManualUpdateForm() return render(request, "update/index.tpl", data)