def allgateways(request): ''' View to look at all RG's in a tabular format, with owners and attached volumes. ''' session = request.session username = session['login_email'] # Get gateways try: qry = db.list_replica_gateways() except: qry = [] gateways = [] for g in qry: gateways.append(g) # Get volumes and owners vols = [] g_owners = [] for g in gateways: volset = [] for v in g.volume_ids: volset.append(db.get_volume(v)) vols.append(volset) attrs = {"SyndicateUser.owner_id ==":g.owner_id} g_owners.append(db.get_user(attrs)) gateway_vols_owners = zip(gateways, vols, g_owners) t = loader.get_template('gateway_templates/allreplicagateways.html') c = RequestContext(request, {'username':username, 'gateway_vols_owners':gateway_vols_owners}) return HttpResponse(t.render(c))
def allgateways(request): ''' View to look at all AG's in a tabular format, with owners and attached volumes. ''' session = request.session username = session['login_email'] # Get gateways try: qry = db.list_acquisition_gateways() except: qry = [] gateways = [] for g in qry: gateways.append(g) # Get volumes and owners vols = [] g_owners = [] for g in gateways: volset = [] for v in g.volume_ids: volset.append(db.read_volume(v)) vols.append(volset) attrs = {"SyndicateUser.owner_id ==": g.owner_id} g_owners.append(db.get_user(attrs)) gateway_vols_owners = zip(gateways, vols, g_owners) t = loader.get_template('gateway_templates/allacquisitiongateways.html') c = RequestContext(request, { 'username': username, 'gateway_vols_owners': gateway_vols_owners }) return HttpResponse(t.render(c))
def viewgateway(request, g_id=0): ''' The view for viewing and changing any of the main settings on any UG. Passes forms for changing different settings, and the volumes attached to the gateway. ''' session = request.session username = session['login_email'] message = session.pop('message', "") g_id = int(g_id) g = db.read_user_gateway(g_id) if not g: logging.error("Error reading gateway %d : Does note exist" % g_id) message = "No user gateway with the ID %d exists." % g_id t = loader.get_template("gateway_templates/viewgateway_failure.html") c = Context({'message': message, 'username': username}) return HttpResponse(t.render(c)) # Create necessary forms location_form = gatewayforms.ModifyGatewayLocation(initial={ 'host': g.host, 'port': g.port }) change_form = gatewayforms.ChangeVolume() password_form = libforms.Password() change_password_form = libforms.ChangePassword() vol = db.read_volume(g.volume_id) if not vol: vol = None owner = None """ if g.volume_id != 0: logging.error("Volume ID %s in gateways volume_ids does not map to volume. Gateway: %s" % (g.volume_id, g_id)) return redirect('django_ug.views.allgateways') else: vol = None owner = None """ else: attrs = {"SyndicateUser.owner_id ==": vol.owner_id} owner = db.get_user(attrs) logging.info(owner) logging.info(vol.owner_id) t = loader.get_template("gateway_templates/viewusergateway.html") c = RequestContext( request, { 'username': username, 'gateway': g, 'message': message, 'vol': vol, 'owner': owner, 'location_form': location_form, 'change_form': change_form, 'password_form': password_form, 'change_password_form': change_password_form }) return HttpResponse(t.render(c))
def validate_work(self, message): try: user = storage.get_random_user() user = self.client_refrence.guilds[0].get_member(user.id.val) return State.OK, Message( content=f'@{user.name} bedankt sich! Du erhaelst 10$', channel=message.channel) worker = storage.get_user(self.user.id) worker.money(worker.money.val + 10) except Exception as e: print(e) return State.FAILED, None
def work(self, message): if self.state == 0: parsed = self.parse_message(message) if not parsed: return State.FAILED, None _, category = parsed result = self.handle_request(category) print(result) if result: return State.OK, result else: return State.FAILED, None elif self.state == 1: parsed = self.parse_message(message) if parsed: command, params = parsed if command == '!info': try: i = int(params) return State.NO_UPDATE, Message( content=self.items[i].get_info(), channel=self.channel) except Exception as e: print(e) return State.SKIP, None if message.content == '!next': result = self.handle_request(self.category) return State.NO_UPDATE, Message(content=result, channel=self.channel) try: i = int(message.content[1]) item = self.items[i] except Exception as e: print(e) return State.SKIP, None user = storage.get_user(self.requester.id) if self.validate_transaction(user, item): storage.insert_new_item(self.requester.id, self.category, item.objId) user.money(user.money.val - item.price) return State.OK, Message( content=f'du hast {item.get_name()} gekauft, danke!', channel=self.channel) else: return State.OK, Message( content= f'Du hast net genug Geld also verpiss dich. Geh mal lieber arbeiten du stück scheiße', channel=self.channel)
def allvolumes(request): ''' Display all public volumes ''' session = request.session username = session['login_email'] v_attrs = {'Volume.private !=': True} volumes = db.list_volumes(v_attrs) owners = [] for v in volumes: attrs = {"SyndicateUser.owner_id ==": v.owner_id} owners.append(db.get_user(attrs)) vols = zip(volumes, owners) t = loader.get_template('allvolumes.html') c = Context({'username': username, 'vols': vols}) return HttpResponse(t.render(c))
def allgateways(request): ''' List all UG gateways view ''' session = request.session username = session['login_email'] try: qry = db.list_user_gateways() except: qry = [] gateways = [] for g in qry: gateways.append(g) vols = [] for g in gateways: add_vol = db.read_volume(g.volume_id) if add_vol: vols.append(add_vol) else: vols.append([]) owners = [] for v in vols: if v: volume_owner = v.owner_id attrs = {"SyndicateUser.owner_id ==": volume_owner} owners.append(db.get_user(attrs)) else: owners.append("") gateway_vols_owners = zip(gateways, vols, owners) t = loader.get_template('gateway_templates/allusergateways.html') c = RequestContext(request, { 'username': username, 'gateway_vols_owners': gateway_vols_owners }) return HttpResponse(t.render(c))
def add_workdone(self, user_id): user = storage.get_user(user_id) user.work_done(user.work_done.val + 1)
def viewgateway(request, g_id=0): ''' The view for viewing and changing any of the main settings on any AG. Passes forms for changing different settings, and the volumes attached to the gateway. ''' session = request.session username = session['login_email'] g_id = int(g_id) # Check for passed error messages or inital data from session-state. message = session.pop('message', "") ag_initial_data = session.get('ag_initial_data' + str(g_id), []) # Make sure this gateway actually exists. g = db.read_acquisition_gateway(g_id) if not g: logging.error("Error reading gateway %s : Does not exist." % (g_id)) message = "No acquisition gateway with the ID %s exists." % g_id t = loader.get_template("gateway_templates/viewgateway_failure.html") c = Context({'message': message, 'username': username}) return HttpResponse(t.render(c)) # Create forms for changing location, adding volumes, # changing password, getting password, and changing config location_form = gatewayforms.ModifyGatewayLocation(initial={ 'host': g.host, 'port': g.port }) add_form = gatewayforms.GatewayAddVolume() json_form = gatewayforms.ModifyGatewayConfig() password_form = libforms.Password() change_password_form = libforms.ChangePassword() # Get all attached volumes and their respective owners owners = [] vols = [] for v_id in g.volume_ids: vol = db.read_volume(v_id) if not vol: logging.error( "Volume ID in gateways volume_ids does not map to volume. Gateway: %s" % g_name) else: vols.append(vol) attrs = {"SyndicateUser.owner_id ==": vol.owner_id} owners.append(db.get_user(attrs)) vol_owners = zip(vols, owners) # Create formatted data based on vols for the formset, if not passed in state. if not ag_initial_data: for v in vols: ag_initial_data.append({'volume_name': v.name, 'remove': False}) session['ag_initial_data' + str(g_id)] = ag_initial_data VolumeFormSet = formset_factory(gatewayforms.GatewayRemoveVolume, extra=0) if ag_initial_data: formset = VolumeFormSet(initial=ag_initial_data) else: formset = None t = loader.get_template("gateway_templates/viewacquisitiongateway.html") c = RequestContext( request, { 'username': username, 'gateway': g, 'message': message, 'vol_owners': vol_owners, 'location_form': location_form, 'add_form': add_form, 'json_form': json_form, 'remove_forms': formset, 'password_form': password_form, 'change_password_form': change_password_form }) return HttpResponse(t.render(c))
def viewgateway(request, g_id=0): ''' The view for viewing and changing any of the main settings on any RG. Passes forms for changing different settings, and the volumes attached to the gateway. ''' session = request.session username = session['login_email'] g_id = int(g_id) # Check for any passed error messages and initial_data from state to save db calls. message = session.pop('message', "") rg_initial_data = session.get('rg_initial_data' + str(g_id), []) # Make sure gateway exists. g = db.read_replica_gateway(g_id) if not g: logging.error("Error reading gateway %d : Exception: %s" % (g_id, e)) message = "No replica gateway with the ID %d exists." % g_id t = loader.get_template("gateway_templates/viewgateway_failure.html") c = Context({'message':message, 'username':username}) return HttpResponse(t.render(c)) # Create forms for changing location, adding volumes, # changing password, getting password, and changing config location_form = gatewayforms.ModifyGatewayLocation(initial={'host':g.host, 'port':g.port}) add_form = gatewayforms.GatewayAddVolume() json_form = gatewayforms.ModifyGatewayConfig() password_form = libforms.Password() change_password_form = libforms.ChangePassword() # Get all attached volumes and their respective owners owners = [] vols = [] for v_id in g.volume_ids: vol = db.read_volume(v_id) if not vol: logging.error("Volume ID in gateways volume_ids does not map to volume. Gateway: %s" % g_name) else: vols.append(vol) attrs = {"SyndicateUser.owner_id ==": vol.owner_id} owners.append(db.get_user(attrs)) vol_owners = zip(vols, owners) # Create formatted data based on vols for the formset, if not passed in state. if not rg_initial_data: for v in vols: rg_initial_data.append({'volume_name':v.name, 'remove':False}) session['rg_initial_data' + str(g_id)] = rg_initial_data VolumeFormSet = formset_factory(gatewayforms.GatewayRemoveVolume, extra=0) if rg_initial_data: formset = VolumeFormSet(initial=rg_initial_data) else: formset = [] t = loader.get_template("gateway_templates/viewreplicagateway.html") c = RequestContext(request, {'username':username, 'gateway':g, 'message':message, 'vol_owners':vol_owners, 'location_form':location_form, 'add_form':add_form, 'json_form':json_form, 'remove_forms':formset, 'password_form':password_form, 'change_password_form':change_password_form}) return HttpResponse(t.render(c))
def work(self, message): if self.state == 0: if message.content == '!blackjack': return State.NO_UPDATE, Message( content='waiting for players', channel=self.channel) if message.content == '!join': player = storage.get_user(message.author.id) join_validation, payload = self.validate_join(player) if join_validation: self.hands.append(Hand(player)) return State.NO_UPDATE, Message( content=f'{len(self.hands)}/5 Spieler!', channel=self.channel) else: return State.NO_UPDATE, payload elif message.content == '!start' and len(self.hands) >= 1: first = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name self.pointer += 1 return State.OK, [ Message( content='initialisiere Spiel..', channel=self.channel), Message( content=f'@{first} was setzen Sie?', channel=self.channel) ] else: return State.SKIP, None elif self.state == 1: try: commitment = int(message.content[1:]) if commitment > self.hands[self.pointer-1].player.money.val: return State.NO_UPDATE, Message( content=f'dein Geld reicht nicht aus', channel=self.channel) else: self.commitcommitment(self.hands[self.pointer-1], commitment) if len(self.hands) == self.pointer: msg = '' for hand in self.hands: name = self.client_reference.guilds[0].get_member(hand.player.id.val).name self.givecards(hand) card_string = ' '.join([self.getimage(card) for card in hand.cards]) msg += f'{name}: {card_string} \n' dealer_string = ' '.join([self.getimage(card) for card in self.dealer_hand.cards]) msg += f'dealer hand: {dealer_string}' self.pointer = 0 first = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name return State.OK, [ Message( content=f'```{msg}```', channel=self.channel), Message( content=f'@{first} haetten Sie gerne noch eine Karte?', channel=self.channel )] name = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name self.pointer += 1 return State.NO_UPDATE, Message( content=f'@{name} was setzen Sie?', channel=self.channel ) except ValueError as e: print(e) return State.NO_UPDATE, None pointer +=1 elif self.state == 2: if message.content[1:] == 'ja': self.givecard(self.hands[self.pointer]) msg = '' for hand in self.hands: name = self.client_reference.guilds[0].get_member(hand.player.id.val).name card_string = ' '.join([self.getimage(card) for card in hand.cards]) msg += f'{name}: {card_string} \n' dealer_string = ' '.join([self.getimage(card) for card in self.dealer_hand.cards]) msg += f'dealer hand: {dealer_string}' if self.validate_hand(self.hands[self.pointer]): name = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name return State.NO_UPDATE, [ Message( content=f'```{msg}```', channel=self.channel), Message( content=f'@{name} haetten Sie gerne noch eine Karte?', channel=self.channel)] else: self.hands.remove(self.hands[self.pointer]) self.pointer += 1 name = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name return State.NO_UPDATE, [ Message( content='schade!', channel=self.channel), Message( content=f'```{msg}```', channel=self.channel), Message( content=f'@{name} haetten Sie gerne noch eine Karte?', channel=self.channel)] else: self.pointer += 1 name = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name return Message( content=f'{name} haetten Sie gerne noch eine Karte?', channel=self.channel )