Best Python code snippet using lisa_python
xasyActions.py
Source:xasyActions.py
1#!/usr/bin/env python2###########################################################################3#4# xasyActions implements the possible actions and their inverses5# for the undo/redo stack in xasy6#7# Author: Orest Shardt8# Created: July 23, 20079#10###########################################################################11import math12import UndoRedoStack13import xasy2asy14from Tkinter import *15class translationAction(UndoRedoStack.action):16 def __init__(self,owner,itemList,indexList,translation):17 self.translation = translation18 self.owner = owner19 self.itemList = itemList20 self.indexList = indexList21 UndoRedoStack.action.__init__(self,self.transF,self.unTransF)22 def transF(self):23 mag = self.owner.magnification24 for i in range(len(self.itemList)):25 for index in self.indexList[i]:26 self.owner.translateSomething(-1,(self.translation[0]/mag,self.translation[1]/mag),self.itemList[i],index)27 if index==None:28 index = 029 try:30 self.owner.mainCanvas.move(self.itemList[i].imageList[index].IDTag,self.translation[0]*mag,-self.translation[1]*mag)31 except:32 self.owner.mainCanvas.move(self.itemList[i].IDTag,self.translation[0]*mag,-self.translation[1]*mag)33 self.owner.updateSelection()34 self.owner.updateCanvasSize()35 def unTransF(self):36 mag = self.owner.magnification37 for i in range(len(self.itemList)):38 for index in self.indexList[i]:39 self.owner.translateSomething(-1,(-self.translation[0]/mag,-self.translation[1]/mag),self.itemList[i],index)40 try:41 self.owner.mainCanvas.move(self.itemList[i].imageList[index].IDTag,-self.translation[0]*mag,self.translation[1]*mag)42 except:43 self.owner.mainCanvas.move(self.itemList[i].IDTag,-self.translation[0]*mag,self.translation[1]*mag)44 self.owner.updateSelection()45 self.owner.updateCanvasSize()46 def __str__(self):47 return "Translation of "+str(self.itemList)+str(self.indexList)+" by "+str(self.translation)48class rotationAction(UndoRedoStack.action):49 def __init__(self,owner,itemList,indexList,angle,origin):50 self.owner = owner51 self.itemList = itemList52 self.indexList = indexList53 self.angle = angle54 self.origin = origin55 UndoRedoStack.action.__init__(self,self.rotF,self.unRotF)56 def rotF(self):57 for i in range(len(self.itemList)):58 for index in self.indexList[i]:59 self.owner.rotateSomething(-1,self.angle,self.origin,self.itemList[i],index)60 for item in self.itemList:61 item.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)62 self.owner.bindItemEvents(item)63 self.owner.updateSelection()64 self.owner.updateCanvasSize()65 def unRotF(self):66 for i in range(len(self.itemList)):67 for index in self.indexList[i]:68 self.owner.rotateSomething(-1,-self.angle,self.origin,self.itemList[i],index)69 for item in self.itemList:70 item.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)71 self.owner.bindItemEvents(item)72 self.owner.updateSelection()73 self.owner.updateCanvasSize()74 def __str__(self):75 return "Rotation of "+str(self.itemList)+str(self.indexList)+" by "+"%.3f"%(self.angle*180.0/math.pi)+" about "+str(self.origin)76class addLabelAction(UndoRedoStack.action):77 def __init__(self,owner,label):78 self.owner = owner79 self.label = label80 UndoRedoStack.action.__init__(self,self.addF,self.unAddF)81 def addF(self):82 self.owner.addItemToFile(self.label)83 self.label.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)84 self.owner.bindItemEvents(self.label)85 def unAddF(self):86 self.label.removeFromCanvas()87 del self.owner.fileItems[-1]88 self.owner.propList.delete(0)89 self.owner.clearSelection()90 def __str__(self):91 return "Addition of a label"92class deleteLabelAction(UndoRedoStack.action):93 def __init__(self,owner,label,index):94 self.owner = owner95 self.label = label96 self.index = index97 UndoRedoStack.action.__init__(self,self.delF,self.unDelF)98 def delF(self):99 self.owner.fileItems[self.index].removeFromCanvas()100 self.owner.propList.delete(len(self.owner.fileItems)-self.index-1)101 del self.owner.fileItems[self.index]102 def unDelF(self):103 self.owner.fileItems.insert(self.index,self.label)104 self.owner.fileItems[self.index].drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)105 self.owner.propList.insert(len(self.owner.fileItems)-self.index-1,self.owner.describeItem(self.label))106 self.owner.bindItemEvents(self.label)107 def __str__(self):108 return "Deletion of a label"109class editLabelTextAction(UndoRedoStack.action):110 def __init__(self,owner,label,newText,oldText):111 self.owner = owner112 self.label = label113 self.newText = newText114 self.oldText = oldText115 UndoRedoStack.action.__init__(self,self.modT,self.unModT)116 def modT(self):117 self.label.label.setText(self.newText)118 self.label.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)119 self.owner.bindItemEvents(self.label)120 def unModT(self):121 self.label.label.setText(self.oldText)122 self.label.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)123 self.owner.bindItemEvents(self.label)124 def __str__(self):125 return "Editing a label's text"126class editLabelPenAction(UndoRedoStack.action):127 def __init__(self,owner,oldPen,newPen,index):128 self.owner = owner129 self.newPen = newPen130 self.oldPen = oldPen131 self.index = index132 UndoRedoStack.action.__init__(self,self.editF,self.unEditF)133 def editF(self):134 self.owner.fileItems[self.index].removeFromCanvas()135 self.owner.fileItems[self.index].label.pen = self.newPen136 self.owner.fileItems[self.index].drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)137 self.owner.bindItemEvents(self.owner.fileItems[self.index])138 def unEditF(self):139 self.owner.fileItems[self.index].removeFromCanvas()140 self.owner.fileItems[self.index].label.pen = self.oldPen141 self.owner.fileItems[self.index].drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)142 self.owner.bindItemEvents(self.owner.fileItems[self.index])143 def __str__(self):144 return "Changing a label's pen"145class addScriptAction(UndoRedoStack.action):146 def __init__(self,owner,script):147 self.owner = owner148 self.script = script149 UndoRedoStack.action.__init__(self,self.addF,self.unAddF)150 def addF(self):151 self.owner.addItemToFile(self.script)152 self.script.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)153 self.owner.bindItemEvents(self.script)154 def unAddF(self):155 self.script.removeFromCanvas()156 del self.owner.fileItems[-1]157 self.owner.propList.delete(0)158 self.owner.clearSelection()159 def __str__(self):160 return "Addition of a script"161class deleteScriptAction(UndoRedoStack.action):162 def __init__(self,owner,script,index):163 self.owner = owner164 self.script = script165 self.index = index166 UndoRedoStack.action.__init__(self,self.delF,self.unDelF)167 def delF(self):168 self.owner.fileItems[self.index].removeFromCanvas()169 self.owner.propList.delete(len(self.owner.fileItems)-self.index-1)170 del self.owner.fileItems[self.index]171 def unDelF(self):172 self.owner.fileItems.insert(self.index,self.script)173 self.owner.fileItems[self.index].drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)174 self.owner.propList.insert(len(self.owner.fileItems)-self.index-1,self.owner.describeItem(self.script))175 self.owner.bindItemEvents(self.script)176 177 def __str__(self):178 return "Deletion of a script"179class deleteScriptItemAction(UndoRedoStack.action):180 def __init__(self,owner,script,indices,oldTransforms):181 self.owner = owner182 self.script = script183 self.indices = indices[:]184 UndoRedoStack.action.__init__(self,self.delI,self.unDelI)185 def delI(self):186 for index in self.indices:187 self.script.transform[index].deleted = True188 self.owner.mainCanvas.delete(self.script.imageList[index].IDTag)189 def unDelI(self):190 for i in range(len(self.indices)):191 index = self.indices[i]192 self.script.transform[index].deleted = False193 bbox = self.script.imageList[index].originalImage.bbox194 self.script.imageList[index].IDTag = self.owner.mainCanvas.create_image(bbox[0],-bbox[3],anchor=NW,tags=("image"),image=self.script.imageList[index].itk)195 self.owner.bindEvents(self.script.imageList[index].IDTag)196 self.owner.resetStacking()197 def __str__(self):198 return "Deletion of item "+str(self.indices)+" in "+str(self.script)199class editScriptAction(UndoRedoStack.action):200 def __init__(self,owner,script,newText,oldText):201 self.owner = owner202 self.script = script203 self.newText = newText204 self.oldText = oldText205 UndoRedoStack.action.__init__(self,self.modS,self.unModS)206 def modS(self):207 self.script.setScript(self.newText)208 self.script.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)209 self.owner.bindItemEvents(self.script)210 def unModS(self):211 self.script.setScript(self.oldText)212 self.script.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)213 self.owner.bindItemEvents(self.script)214 def __str__(self):215 return "Modification of a script"216class clearItemTransformsAction(UndoRedoStack.action):217 def __init__(self,owner,item,oldTransforms):218 self.owner = owner219 self.item = item220 self.oldTransforms = oldTransforms221 UndoRedoStack.action.__init__(self,self.clearF,self.unClearF)222 def clearF(self):223 for i in range(len(self.oldTransforms)):224 self.item.transform[i] = xasy2asy.identity()225 self.item.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)226 def unClearF(self):227 for i in range(len(self.oldTransforms)):228 self.item.transform[i] = self.oldTransforms[i]229 self.item.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification)230 def __str__(self):231 return "Clear the transforms of "+str(self.item)+" from "+str(self.oldTransforms)232class itemRaiseAction(UndoRedoStack.action):233 def __init__(self,owner,items,oldPositions):234 self.owner = owner235 self.items = items[:]236 self.oldPositions = oldPositions[:]237 UndoRedoStack.action.__init__(self,self.raiseI,self.unRaiseI)238 def raiseI(self):239 for item in self.items:240 self.owner.raiseSomething(item)241 def unRaiseI(self):242 length = len(self.owner.fileItems)243 indices = self.oldPositions[:]244 indices = [length-i-1 for i in indices]245 indices.reverse()246 for index in indices:247 for i in range(index):248 self.owner.raiseSomething(self.owner.fileItems[length-index-1])249 def __str__(self):250 return "Raise items "+str(self.items)+" from positions "+str(self.oldPositions)251class itemLowerAction(UndoRedoStack.action):252 def __init__(self,owner,items,oldPositions):253 self.owner = owner254 self.items = items[:]255 self.oldPositions = oldPositions[:]256 UndoRedoStack.action.__init__(self,self.lowerI,self.unLowerI)257 def lowerI(self):258 for item in self.items:259 self.owner.lowerSomething(item)260 def unLowerI(self):261 indices = self.oldPositions[:]262 indices.reverse()263 for index in indices:264 for i in range(index):265 self.owner.lowerSomething(self.owner.fileItems[index])266 def __str__(self):267 return "Lower items "+str(self.items)+" from positions "+str(self.oldPositions)268class addDrawnItemAction(UndoRedoStack.action):269 def __init__(self,owner,item):270 self.owner = owner271 self.item = item272 UndoRedoStack.action.__init__(self,self.drawF,self.unDrawF)273 def drawF(self):274 self.owner.addItemToFile(self.item)275 self.item.drawOnCanvas(self.owner.mainCanvas,self.owner.magnification,forceAddition=True)276 self.owner.bindItemEvents(self.item)277 def unDrawF(self):278 self.item.removeFromCanvas(self.owner.mainCanvas)279 del self.owner.fileItems[-1]280 self.owner.propList.delete(0)281 self.owner.clearSelection()282 def __str__(self):283 return "Drawing of an item"284class deleteDrawnItemAction(UndoRedoStack.action):285 def __init__(self,owner,item,index):286 self.owner = owner287 self.item = item288 self.index = index289 UndoRedoStack.action.__init__(self,self.delF,self.unDelF)290 def delF(self):291 self.owner.fileItems[self.index].removeFromCanvas(self.owner.mainCanvas)292 self.owner.propList.delete(len(self.owner.fileItems)-self.index-1)293 del self.owner.fileItems[self.index]294 def unDelF(self):295 self.owner.fileItems.insert(self.index,self.item)296 self.owner.fileItems[self.index].drawOnCanvas(self.owner.mainCanvas,self.owner.magnification,forceAddition=True)297 self.owner.propList.insert(len(self.owner.fileItems)-self.index-1,self.owner.describeItem(self.item))298 self.owner.bindItemEvents(self.item)299 def __str__(self):300 return "Deletion of a drawn item"301class editDrawnItemAction(UndoRedoStack.action):302 def __init__(self,owner,oldItem,newItem,index):303 self.owner = owner304 self.oldItem = oldItem305 self.newItem = newItem306 self.index = index307 UndoRedoStack.action.__init__(self,self.editF,self.unEditF)308 def editF(self):309 self.owner.fileItems[self.index].removeFromCanvas(self.owner.mainCanvas)310 self.owner.fileItems[self.index].path = self.newItem.path311 self.owner.fileItems[self.index].pen = self.newItem.pen312 self.owner.fileItems[self.index].transform = self.newItem.transform313 self.owner.fileItems[self.index].IDTag = self.newItem.IDTag314 self.owner.fileItems[self.index].drawOnCanvas(self.owner.mainCanvas,self.owner.magnification,forceAddition=True)315 self.owner.bindItemEvents(self.owner.fileItems[self.index])316 def unEditF(self):317 self.owner.fileItems[self.index].removeFromCanvas(self.owner.mainCanvas)318 self.owner.fileItems[self.index].path = self.oldItem.path319 self.owner.fileItems[self.index].pen = self.oldItem.pen320 self.owner.fileItems[self.index].transform = self.oldItem.transform321 self.owner.fileItems[self.index].IDTag = self.oldItem.IDTag322 self.owner.fileItems[self.index].drawOnCanvas(self.owner.mainCanvas,self.owner.magnification,forceAddition=True)323 self.owner.bindItemEvents(self.owner.fileItems[self.index])324 def __str__(self):...
owners_finder.py
Source:owners_finder.py
...54 self.owners_to_files = {}55 self._map_owners_to_files(files)56 self.files_to_owners = {}57 self._map_files_to_owners()58 self.owners_score = self.db.total_costs_by_owner(59 self.all_possible_owners, files)60 self.original_files_to_owners = copy.deepcopy(self.files_to_owners)61 self.comments = self.db.comments62 # This is the queue that will be shown in the interactive questions.63 # It is initially sorted by the score in descending order. In the64 # interactive questions a user can choose to "defer" its decision, then the65 # owner will be put to the end of the queue and shown later.66 self.owners_queue = []67 self.unreviewed_files = set()68 self.reviewed_by = {}69 self.selected_owners = set()70 self.deselected_owners = set()71 self.reset()72 def run(self):73 self.reset()74 while self.owners_queue and self.unreviewed_files:75 owner = self.owners_queue[0]76 if (owner in self.selected_owners) or (owner in self.deselected_owners):77 continue78 if not any((file_name in self.unreviewed_files)79 for file_name in self.owners_to_files[owner]):80 self.deselect_owner(owner)81 continue82 self.print_info(owner)83 while True:84 inp = self.input_command(owner)85 if inp == 'y' or inp == 'yes':86 self.select_owner(owner)87 break88 elif inp == 'n' or inp == 'no':89 self.deselect_owner(owner)90 break91 elif inp == '' or inp == 'd' or inp == 'defer':92 self.owners_queue.append(self.owners_queue.pop(0))93 break94 elif inp == 'f' or inp == 'files':95 self.list_files()96 break97 elif inp == 'o' or inp == 'owners':98 self.list_owners(self.owners_queue)99 break100 elif inp == 'p' or inp == 'pick':101 self.pick_owner(gclient_utils.AskForData('Pick an owner: '))102 break103 elif inp.startswith('p ') or inp.startswith('pick '):104 self.pick_owner(inp.split(' ', 2)[1].strip())105 break106 elif inp == 'r' or inp == 'restart':107 self.reset()108 break109 elif inp == 'q' or inp == 'quit':110 # Exit with error111 return 1112 self.print_result()113 return 0114 def _map_owners_to_files(self, files):115 for owner in self.all_possible_owners:116 for dir_name, _ in self.all_possible_owners[owner]:117 for file_name in files:118 if file_name.startswith(dir_name):119 self.owners_to_files.setdefault(owner, set())120 self.owners_to_files[owner].add(file_name)121 def _map_files_to_owners(self):122 for owner in self.owners_to_files:123 for file_name in self.owners_to_files[owner]:124 self.files_to_owners.setdefault(file_name, set())125 self.files_to_owners[file_name].add(owner)126 def reset(self):127 self.files_to_owners = copy.deepcopy(self.original_files_to_owners)128 self.unreviewed_files = set(self.files_to_owners.keys())129 self.reviewed_by = {}130 self.selected_owners = set()131 self.deselected_owners = set()132 # Randomize owners' names so that if many reviewers have identical scores133 # they will be randomly ordered to avoid bias.134 owners = list(self.owners_to_files.keys())135 random.shuffle(owners)136 self.owners_queue = sorted(owners,137 key=lambda owner: self.owners_score[owner])138 self.find_mandatory_owners()139 def select_owner(self, owner, findMandatoryOwners=True):140 if owner in self.selected_owners or owner in self.deselected_owners\141 or not (owner in self.owners_queue):142 return143 self.writeln('Selected: ' + owner)144 self.owners_queue.remove(owner)145 self.selected_owners.add(owner)146 for file_name in filter(147 lambda file_name: file_name in self.unreviewed_files,148 self.owners_to_files[owner]):149 self.unreviewed_files.remove(file_name)150 self.reviewed_by[file_name] = owner151 if findMandatoryOwners:152 self.find_mandatory_owners()153 def deselect_owner(self, owner, findMandatoryOwners=True):154 if owner in self.selected_owners or owner in self.deselected_owners\155 or not (owner in self.owners_queue):156 return157 self.writeln('Deselected: ' + owner)158 self.owners_queue.remove(owner)159 self.deselected_owners.add(owner)160 for file_name in self.owners_to_files[owner] & self.unreviewed_files:161 self.files_to_owners[file_name].remove(owner)162 if findMandatoryOwners:163 self.find_mandatory_owners()164 def find_mandatory_owners(self):165 continues = True166 for owner in self.owners_queue:167 if owner in self.selected_owners:168 continue169 if owner in self.deselected_owners:170 continue171 if len(self.owners_to_files[owner] & self.unreviewed_files) == 0:172 self.deselect_owner(owner, False)173 while continues:174 continues = False175 for file_name in filter(176 lambda file_name: len(self.files_to_owners[file_name]) == 1,177 self.unreviewed_files):178 owner = first(self.files_to_owners[file_name])179 self.select_owner(owner, False)180 continues = True181 break182 def print_comments(self, owner):183 if owner not in self.comments:184 self.writeln(self.bold_name(owner))185 else:186 self.writeln(self.bold_name(owner) + ' is commented as:')187 self.indent()188 if owners_module.GLOBAL_STATUS in self.comments[owner]:189 self.writeln(190 self.greyed(self.comments[owner][owners_module.GLOBAL_STATUS]) +191 ' (global status)')192 if len(self.comments[owner]) == 1:193 self.unindent()194 return195 for path in self.comments[owner]:196 if path == owners_module.GLOBAL_STATUS:197 continue198 elif len(self.comments[owner][path]) > 0:199 self.writeln(self.greyed(self.comments[owner][path]) +200 ' (at ' + self.bold(path or '<root>') + ')')201 else:202 self.writeln(self.greyed('[No comment] ') + ' (at ' +203 self.bold(path or '<root>') + ')')204 self.unindent()205 def print_file_info(self, file_name, except_owner=''):206 if file_name not in self.unreviewed_files:207 self.writeln(self.greyed(file_name +208 ' (by ' +209 self.bold_name(self.reviewed_by[file_name]) +210 ')'))211 else:212 if len(self.files_to_owners[file_name]) <= 3:213 other_owners = []214 for ow in self.files_to_owners[file_name]:215 if ow != except_owner:216 other_owners.append(self.bold_name(ow))217 self.writeln(file_name +218 ' [' + (', '.join(other_owners)) + ']')219 else:220 self.writeln(file_name + ' [' +221 self.bold(str(len(self.files_to_owners[file_name]))) +222 ']')223 def print_file_info_detailed(self, file_name):224 self.writeln(file_name)225 self.indent()226 for ow in sorted(self.files_to_owners[file_name]):227 if ow in self.deselected_owners:228 self.writeln(self.bold_name(self.greyed(ow)))229 elif ow in self.selected_owners:230 self.writeln(self.bold_name(self.greyed(ow)))231 else:232 self.writeln(self.bold_name(ow))233 self.unindent()234 def print_owned_files_for(self, owner):235 # Print owned files236 self.print_comments(owner)237 self.writeln(self.bold_name(owner) + ' owns ' +238 str(len(self.owners_to_files[owner])) + ' file(s):')239 self.indent()240 for file_name in sorted(self.owners_to_files[owner]):241 self.print_file_info(file_name, owner)242 self.unindent()243 self.writeln()244 def list_owners(self, owners_queue):245 if (len(self.owners_to_files) - len(self.deselected_owners) -246 len(self.selected_owners)) > 3:247 for ow in owners_queue:248 if ow not in self.deselected_owners and ow not in self.selected_owners:249 self.print_comments(ow)250 else:251 for ow in owners_queue:252 if ow not in self.deselected_owners and ow not in self.selected_owners:253 self.writeln()254 self.print_owned_files_for(ow)255 def list_files(self):256 self.indent()257 if len(self.unreviewed_files) > 5:258 for file_name in sorted(self.unreviewed_files):259 self.print_file_info(file_name)260 else:261 for file_name in self.unreviewed_files:262 self.print_file_info_detailed(file_name)263 self.unindent()264 def pick_owner(self, ow):265 # Allowing to omit domain suffixes266 if ow not in self.owners_to_files:267 if ow + self.email_postfix in self.owners_to_files:268 ow += self.email_postfix269 if ow not in self.owners_to_files:270 self.writeln('You cannot pick ' + self.bold_name(ow) + ' manually. ' +271 'It\'s an invalid name or not related to the change list.')272 return False273 elif ow in self.selected_owners:274 self.writeln('You cannot pick ' + self.bold_name(ow) + ' manually. ' +275 'It\'s already selected.')276 return False277 elif ow in self.deselected_owners:278 self.writeln('You cannot pick ' + self.bold_name(ow) + ' manually.' +279 'It\'s already unselected.')280 return False281 self.select_owner(ow)282 return True283 def print_result(self):284 # Print results285 self.writeln()286 self.writeln()287 if len(self.selected_owners) == 0:288 self.writeln('This change list already has owner-reviewers for all '289 'files.')290 self.writeln('Use --ignore-current if you want to ignore them.')291 else:292 self.writeln('** You selected these owners **')293 self.writeln()294 for owner in self.selected_owners:295 self.writeln(self.bold_name(owner) + ':')...
components.js
Source:components.js
1var components = {2 "core": {3 "meta": {4 "path": "components/prism-core.js",5 "option": "mandatory"6 },7 "core": "Core"8 },9 "themes": {10 "meta": {11 "path": "themes/{id}.css",12 "link": "index.html?theme={id}",13 "exclusive": true14 },15 "prism": {16 "title": "Default",17 "option": "default"18 },19 "prism-dark": "Dark",20 "prism-funky": "Funky",21 "prism-okaidia": {22 "title": "Okaidia",23 "owner": "ocodia"24 },25 "prism-twilight": {26 "title": "Twilight",27 "owner": "remybach"28 },29 "prism-coy": {30 "title": "Coy",31 "owner": "tshedor"32 },33 "prism-solarizedlight": {34 "title": "Solarized Light",35 "owner": "hectormatos2011 "36 }37 },38 "languages": {39 "meta": {40 "path": "components/prism-{id}",41 "noCSS": true,42 "examplesPath": "examples/prism-{id}",43 "addCheckAll": true44 },45 "markup": {46 "title": "Markup",47 "aliasTitles": { "html": "HTML", "xml": "XML", "svg": "SVG", "mathml": "MathML" },48 "option": "default"49 },50 "css": {51 "title": "CSS",52 "option": "default"53 },54 "clike": {55 "title": "C-like",56 "option": "default"57 },58 "javascript": {59 "title": "JavaScript",60 "option": "default",61 "require": "clike"62 },63 "abap": {64 "title": "ABAP",65 "owner": "dellagustin"66 },67 "actionscript": {68 "title": "ActionScript",69 "require": "javascript",70 "owner": "Golmote"71 },72 "ada": {73 "title": "Ada",74 "owner": "Lucretia"75 },76 "apacheconf": {77 "title": "Apache Configuration",78 "owner": "GuiTeK"79 },80 "apl": {81 "title": "APL",82 "owner": "ngn"83 },84 "applescript": {85 "title": "AppleScript",86 "owner": "Golmote"87 },88 "asciidoc": {89 "title": "AsciiDoc",90 "owner": "Golmote"91 },92 "aspnet": {93 "title": "ASP.NET (C#)",94 "require": "markup",95 "owner": "nauzilus"96 },97 "autoit": {98 "title": "AutoIt",99 "owner": "Golmote"100 },101 "autohotkey": {102 "title": "AutoHotkey",103 "owner": "aviaryan"104 },105 "bash": {106 "title": "Bash",107 "owner": "zeitgeist87"108 },109 "basic": {110 "title": "BASIC",111 "owner": "Golmote"112 },113 "batch": {114 "title": "Batch",115 "owner": "Golmote"116 },117 "bison": {118 "title": "Bison",119 "require": "c",120 "owner": "Golmote"121 },122 "brainfuck": {123 "title": "Brainfuck",124 "owner": "Golmote"125 },126 "bro": {127 "title": "Bro",128 "owner": "wayward710"129 },130 "c": {131 "title": "C",132 "require": "clike",133 "owner": "zeitgeist87"134 },135 "csharp": {136 "title": "C#",137 "require": "clike",138 "owner": "mvalipour"139 },140 "cpp": {141 "title": "C++",142 "require": "c",143 "owner": "zeitgeist87"144 },145 "coffeescript": {146 "title": "CoffeeScript",147 "require": "javascript",148 "owner": "R-osey"149 },150 "crystal": {151 "title": "Crystal",152 "require": "ruby",153 "owner": "MakeNowJust"154 },155 "css-extras": {156 "title": "CSS Extras",157 "require": "css",158 "owner": "milesj"159 },160 "d": {161 "title": "D",162 "require": "clike",163 "owner": "Golmote"164 },165 "dart": {166 "title": "Dart",167 "require": "clike",168 "owner": "Golmote"169 },170 "diff": {171 "title": "Diff",172 "owner": "uranusjr"173 },174 "docker": {175 "title": "Docker",176 "owner": "JustinBeckwith"177 },178 "eiffel": {179 "title": "Eiffel",180 "owner": "Conaclos"181 },182 "elixir": {183 "title": "Elixir",184 "owner": "Golmote"185 },186 "erlang": {187 "title": "Erlang",188 "owner": "Golmote"189 },190 "fsharp": {191 "title": "F#",192 "require": "clike",193 "owner": "simonreynolds7"194 },195 "fortran": {196 "title": "Fortran",197 "owner": "Golmote"198 },199 "gherkin": {200 "title": "Gherkin",201 "owner": "hason"202 },203 "git": {204 "title": "Git",205 "owner": "lgiraudel"206 },207 "glsl": {208 "title": "GLSL",209 "require": "clike",210 "owner": "Golmote"211 },212 "go": {213 "title": "Go",214 "require": "clike",215 "owner": "arnehormann"216 },217 "graphql": {218 "title": "GraphQL",219 "owner": "Golmote"220 },221 "groovy": {222 "title": "Groovy",223 "require": "clike",224 "owner": "robfletcher"225 },226 "haml": {227 "title": "Haml",228 "require": "ruby",229 "owner": "Golmote"230 },231 "handlebars": {232 "title": "Handlebars",233 "require": "markup",234 "owner": "Golmote"235 },236 "haskell": {237 "title": "Haskell",238 "owner": "bholst"239 },240 "haxe": {241 "title": "Haxe",242 "require": "clike",243 "owner": "Golmote"244 },245 "http": {246 "title": "HTTP",247 "owner": "danielgtaylor"248 },249 "icon": {250 "title": "Icon",251 "owner": "Golmote"252 },253 "inform7": {254 "title": "Inform 7",255 "owner": "Golmote"256 },257 "ini": {258 "title": "Ini",259 "owner": "aviaryan"260 },261 "j": {262 "title": "J",263 "owner": "Golmote"264 },265 "jade": {266 "title": "Jade",267 "require": "javascript",268 "owner": "Golmote"269 },270 "java": {271 "title": "Java",272 "require": "clike",273 "owner": "sherblot"274 },275 "jolie": {276 "title": "Jolie",277 "require": "clike",278 "owner": "thesave"279 },280 "json": {281 "title": "JSON",282 "owner": "CupOfTea696"283 },284 "julia": {285 "title": "Julia",286 "owner": "cdagnino"287 },288 "keyman": {289 "title": "Keyman",290 "owner": "mcdurdin"291 },292 "kotlin": {293 "title": "Kotlin",294 "require": "clike",295 "owner": "Golmote"296 },297 "latex": {298 "title": "LaTeX",299 "owner": "japborst"300 },301 "less": {302 "title": "Less",303 "require": "css",304 "owner": "Golmote"305 },306 "livescript": {307 "title": "LiveScript",308 "owner": "Golmote"309 },310 "lolcode": {311 "title": "LOLCODE",312 "owner": "Golmote"313 },314 "lua": {315 "title": "Lua",316 "owner": "Golmote"317 },318 "makefile": {319 "title": "Makefile",320 "owner": "Golmote"321 },322 "markdown": {323 "title": "Markdown",324 "require": "markup",325 "owner": "Golmote"326 },327 "matlab": {328 "title": "MATLAB",329 "owner": "Golmote"330 },331 "mel": {332 "title": "MEL",333 "owner": "Golmote"334 },335 "mizar": {336 "title": "Mizar",337 "owner": "Golmote"338 },339 "monkey": {340 "title": "Monkey",341 "owner": "Golmote"342 },343 "nasm": {344 "title": "NASM",345 "owner": "rbmj"346 },347 "nginx": {348 "title": "nginx",349 "owner": "westonganger",350 "require": "clike"351 },352 "nim": {353 "title": "Nim",354 "owner": "Golmote"355 },356 "nix": {357 "title": "Nix",358 "owner": "Golmote"359 },360 "nsis": {361 "title": "NSIS",362 "owner": "idleberg"363 },364 "objectivec": {365 "title": "Objective-C",366 "require": "c",367 "owner": "uranusjr"368 },369 "ocaml": {370 "title": "OCaml",371 "owner": "Golmote"372 },373 "oz": {374 "title": "Oz",375 "owner": "Golmote"376 },377 "parigp": {378 "title": "PARI/GP",379 "owner": "Golmote"380 },381 "parser": {382 "title": "Parser",383 "require": "markup",384 "owner": "Golmote"385 },386 "pascal": {387 "title": "Pascal",388 "owner": "Golmote"389 },390 "perl": {391 "title": "Perl",392 "owner": "Golmote"393 },394 "php": {395 "title": "PHP",396 "require": "clike",397 "owner": "milesj"398 },399 "php-extras": {400 "title": "PHP Extras",401 "require": "php",402 "owner": "milesj"403 },404 "powershell": {405 "title": "PowerShell",406 "owner": "nauzilus"407 },408 "processing": {409 "title": "Processing",410 "require": "clike",411 "owner": "Golmote"412 },413 "prolog": {414 "title": "Prolog",415 "owner": "Golmote"416 },417 "properties": {418 "title": ".properties",419 "owner": "Golmote"420 },421 "protobuf": {422 "title": "Protocol Buffers",423 "require": "clike",424 "owner": "just-boris"425 },426 "puppet": {427 "title": "Puppet",428 "owner": "Golmote"429 },430 "pure": {431 "title": "Pure",432 "owner": "Golmote"433 },434 "python": {435 "title": "Python",436 "owner": "multipetros"437 },438 "q": {439 "title": "Q",440 "owner": "Golmote"441 },442 "qore": {443 "title": "Qore",444 "require": "clike",445 "owner": "temnroegg"446 },447 "r": {448 "title": "R",449 "owner": "Golmote"450 },451 "jsx":{452 "title": "React JSX",453 "require": ["markup", "javascript"],454 "owner": "vkbansal"455 },456 "reason": {457 "title": "Reason",458 "require": "clike",459 "owner": "Golmote"460 },461 "rest": {462 "title": "reST (reStructuredText)",463 "owner": "Golmote"464 },465 "rip": {466 "title": "Rip",467 "owner": "ravinggenius"468 },469 "roboconf": {470 "title": "Roboconf",471 "owner": "Golmote"472 },473 "ruby": {474 "title": "Ruby",475 "require": "clike",476 "owner": "samflores"477 },478 "rust": {479 "title": "Rust",480 "owner": "Golmote"481 },482 "sas": {483 "title": "SAS",484 "owner": "Golmote"485 },486 "sass": {487 "title": "Sass (Sass)",488 "require": "css",489 "owner": "Golmote"490 },491 "scss": {492 "title": "Sass (Scss)",493 "require": "css",494 "owner": "MoOx"495 },496 "scala": {497 "title": "Scala",498 "require": "java",499 "owner": "jozic"500 },501 "scheme" : {502 "title": "Scheme",503 "owner" : "bacchus123"504 },505 "smalltalk": {506 "title": "Smalltalk",507 "owner": "Golmote"508 },509 "smarty": {510 "title": "Smarty",511 "require": "markup",512 "owner": "Golmote"513 },514 "sql": {515 "title": "SQL",516 "owner": "multipetros"517 },518 "stylus" : {519 "title": "Stylus",520 "owner": "vkbansal"521 },522 "swift": {523 "title": "Swift",524 "require": "clike",525 "owner": "chrischares"526 },527 "tcl": {528 "title": "Tcl",529 "owner": "PeterChaplin"530 },531 "textile": {532 "title": "Textile",533 "require": "markup",534 "owner": "Golmote"535 },536 "twig": {537 "title": "Twig",538 "require": "markup",539 "owner": "brandonkelly"540 },541 "typescript":{542 "title": "TypeScript",543 "require": "javascript",544 "owner": "vkbansal"545 },546 "verilog": {547 "title": "Verilog",548 "owner": "a-rey"549 },550 "vhdl": {551 "title": "VHDL",552 "owner": "a-rey"553 },554 "vim": {555 "title": "vim",556 "owner": "westonganger"557 },558 "wiki": {559 "title": "Wiki markup",560 "require": "markup",561 "owner": "Golmote"562 },563 "xojo": {564 "title": "Xojo (REALbasic)",565 "owner": "Golmote"566 },567 "yaml": {568 "title": "YAML",569 "owner": "hason"570 }571 },572 "plugins": {573 "meta": {574 "path": "plugins/{id}/prism-{id}",575 "link": "plugins/{id}/"576 },577 "line-highlight": "Line Highlight",578 "line-numbers": {579 "title": "Line Numbers",580 "owner": "kuba-kubula"581 },582 "show-invisibles": "Show Invisibles",583 "autolinker": "Autolinker",584 "wpd": "WebPlatform Docs",585 "custom-class": {586 "title": "Custom Class",587 "owner": "dvkndn"588 },589 "file-highlight": {590 "title": "File Highlight",591 "noCSS": true592 },593 "show-language": {594 "title": "Show Language",595 "owner": "nauzilus",596 "noCSS": true,597 "require": "toolbar"598 },599 "jsonp-highlight": {600 "title": "JSONP Highlight",601 "noCSS": true,602 "owner": "nauzilus"603 },604 "highlight-keywords": {605 "title": "Highlight Keywords",606 "owner": "vkbansal",607 "noCSS": true608 },609 "remove-initial-line-feed": {610 "title": "Remove initial line feed",611 "owner": "Golmote",612 "noCSS": true613 },614 "previewer-base": {615 "title": "Previewer: Base",616 "owner": "Golmote"617 },618 "previewer-color": {619 "title": "Previewer: Color",620 "require": "previewer-base",621 "owner": "Golmote"622 },623 "previewer-gradient": {624 "title": "Previewer: Gradient",625 "require": "previewer-base",626 "owner": "Golmote"627 },628 "previewer-easing": {629 "title": "Previewer: Easing",630 "require": "previewer-base",631 "owner": "Golmote"632 },633 "previewer-time": {634 "title": "Previewer: Time",635 "require": "previewer-base",636 "owner": "Golmote"637 },638 "previewer-angle": {639 "title": "Previewer: Angle",640 "require": "previewer-base",641 "owner": "Golmote"642 },643 "autoloader": {644 "title": "Autoloader",645 "owner": "Golmote",646 "noCSS": true647 },648 "keep-markup": {649 "title": "Keep Markup",650 "owner": "Golmote",651 "after": "normalize-whitespace",652 "noCSS": true653 },654 "command-line": {655 "title": "Command Line",656 "owner": "chriswells0"657 },658 "unescaped-markup": "Unescaped Markup",659 "normalize-whitespace": {660 "title": "Normalize Whitespace",661 "owner": "zeitgeist87",662 "after": "unescaped-markup",663 "noCSS": true664 },665 "data-uri-highlight": {666 "title": "Data-URI Highlight",667 "owner": "Golmote",668 "noCSS": true669 },670 "toolbar": {671 "title": "Toolbar",672 "owner": "mAAdhaTTah"673 },674 "copy-to-clipboard": {675 "title": "Copy to Clipboard Button",676 "owner": "mAAdhaTTah",677 "require": "toolbar",678 "noCSS": true679 }680 }...
views.py
Source:views.py
1from django.shortcuts import redirect, render2from .models import *3from accounts.models import *4from customer.models import Order,Orderdish5# Create your views here.6def dashboard(request,id):7 request.session["owner_id"]=id8 owner=Owner.objects.get(id=id)9 resturant=None10 dishes=None11 order=False12 recieved_order=None13 panding_order=None14 if Resturant.objects.all().filter(owner=owner):15 resturant=Resturant.objects.get(owner=owner)16 if Dish.objects.all().filter(owner=owner):17 dishes=Dish.objects.all().filter(owner=owner)18 if resturant:19 orders_list=Order.objects.filter(restaurant_id=resturant.id,complete=True)20 recieved_order=[]21 panding_order=[]22 # print(orders_list)23 for order in orders_list:24 dishess=Orderdish.objects.filter(order=order)25 # print(dishess)26 if dishess:27 d=[]28 total_bill=029 for dish in dishess:30 quantity=dish.quantity31 name=dish.dish.name32 price=dish.dish.price33 obj=Info1(name,price,quantity)34 d.append(obj)35 total_bill=total_bill+quantity*price36 obj=Info2(d,order.id,total_bill)37 if order.status=="placed":38 recieved_order.append(obj)39 40 elif order.status=="panding":41 panding_order.append(obj)42 # print(recieved_order)43 # print(panding_order)44 45 if recieved_order or panding_order:46 order=True47 48 return render(request,'dashboard.html',{49 'name':owner.name,50 'id':id,51 'resturant':resturant,52 'dishes':dishes,53 'recieved_order':recieved_order,54 'panding_order':panding_order,55 'order':order56 })57 58def add_resturant(request,owner_id):59 if request.method=="POST":60 owner=Owner.objects.get(id=owner_id)61 name=request.POST["name"]62 address=request.POST["address"]63 latitude=request.POST["latitude"]64 longitude=request.POST["longitude"]65 opening_time=request.POST["opening_time"]66 closing_time=request.POST["closing_time"]67 bill_limit=request.POST["bill_limit"]68 Resturant.objects.create(69 owner=owner,70 name=name,71 address=address,72 latitude=latitude,73 longitude=longitude,74 opening_time=opening_time,75 closing_time=closing_time,76 bill_limit=bill_limit77 )78 return redirect("dashboard",id=owner_id)79 return render(request,'add_resturant.html')80def resturant_details(request,id):81 owner=Owner.objects.get(id=id)82 resturant=Resturant.objects.get(id=id)83 if request.method=="POST":84 name=request.POST["name"]85 address=request.POST["address"]86 latitude=request.POST["latitude"]87 longitude=request.POST["longitude"]88 opening_time=request.POST["opening_time"]89 closing_time=request.POST["closing_time"]90 bill_limit=request.POST["bill_limit"]91 print(latitude)92 print(longitude)93 Resturant.objects.all().filter(owner=owner).update(94 owner=owner,95 name=name,96 address=address,97 latitude=latitude,98 longitude=longitude,99 opening_time=opening_time,100 closing_time=closing_time,101 bill_limit=bill_limit102 )103 return redirect("dashboard",id=id)104 return render(request,'resturant_details.html',{105 'resturant':resturant106 })107def add_dish(request,owner_id):108 owner=Owner.objects.get(id=owner_id)109 if request.method=="POST":110 name=request.POST["name"]111 price=request.POST["price"]112 Dish.objects.create(113 owner=owner,114 name=name,115 price=price116 )117 owner_id=request.session["owner_id"]118 return redirect("dashboard",id=owner_id)119 return render(request,'add_dish.html')120def edit_dish(request,dish_id):121 if request.method=="POST":122 name=request.POST["name"]123 price=request.POST["price"]124 Dish.objects.all().filter(id=dish_id).update(125 name=name,126 price=price127 )128 owner_id=request.session["owner_id"]129 return redirect("dashboard",id=owner_id)130 dish=Dish.objects.get(id=dish_id)131 return render(request,'edit_dish.html',{132 'dish':dish133 })134def remove_dish(request,dish_id):135 instance=Dish.objects.get(id=dish_id)136 instance.delete()137 owner_id=request.session["owner_id"]138 return redirect("dashboard",id=owner_id)139class Info1:140 def __init__(self,name,price,quantity):141 self.name=name142 self.price=price143 self.quantity=quantity144class Info2:145 def __init__(self,dishes,id,bill):146 self.dishes=dishes147 self.id=id148 self.bill=bill149def accept_order(request,order_id):150 Order.objects.filter(id=order_id).update(151 status="panding"152 )153 owner_id=request.session["owner_id"]154 return redirect("dashboard",owner_id)155def reject_order(request,order_id):156 Order.objects.filter(id=order_id).update(157 status="rejected"158 )159 owner_id=request.session["owner_id"]160 return redirect("dashboard",owner_id)161def complete_order(request,order_id):162 Order.objects.filter(id=order_id).update(163 status="completed"164 )165 owner_id=request.session["owner_id"]...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!