def create_proposal(latest_name, market_id_csv, item_type_name): proposal = ItemChangeProposal() proposal.proposed_by_process = "autoimporter" proposal.existing_item = None proposal.change = "create" proposal.name = latest_name proposal.eve_echoes_market_id = market_id_csv proposal.item_type = ItemSubSubType.objects.get(name=item_type_name) proposal.save()
def create_item_form(request, existing_item): if request.method == "POST": form = ItemChangeProposalForm(request.POST, existing_item=existing_item) if form.is_valid(): proposal = ItemChangeProposal() save_proposal(existing_item, form, proposal, request) NOTIFICATION_TYPES["itemchanges"].send() messages.success(request, f"Successfully created {proposal}") return HttpResponseRedirect(reverse("item-change-list")) else: initial = {} if existing_item: initial = { "name": existing_item.name, "item_type": existing_item.item_type, "eve_echoes_market_id": existing_item.eve_echoes_market_id, } form = ItemChangeProposalForm(initial=initial, existing_item=existing_item) return render( request, "items/item_change/item_change_form.html", { "form": form, "existing_item": existing_item }, )
def add_proposal(item, latest_name, market_id_csv, item_type_name): proposal = ItemChangeProposal() proposal.proposed_by_process = "autoimporter" proposal.existing_item = item proposal.change = "update" changed = False if item.name != latest_name: proposal.name = latest_name changed = True if item.eve_echoes_market_id != market_id_csv: proposal.eve_echoes_market_id = market_id_csv changed = True if item.item_type.name != item_type_name: proposal.item_type = ItemSubSubType.objects.get( name=item_type_name) changed = True if changed: proposal.save()
def delete_item_change(request, pk): proposal = get_object_or_404(ItemChangeProposal, pk=pk) if not proposal.has_edit_admin(request.gooseuser): return forbidden(request) if request.method == "POST": try: proposal.try_delete() if ItemChangeProposal.open_proposals().count() == 0: NOTIFICATION_TYPES["itemchanges"].dismiss() messages.success(request, f"Succesfully deleted {proposal}") except ItemChangeError as e: messages.error(request, e.message) return HttpResponseRedirect(reverse("item-change-list")) else: return render( request, "items/item_change/item_change_confirm_delete.html", {"itemchangeproposal": proposal}, )
def handle(self, *args, **options): r = requests.get( "https://api.eve-echoes-market.com/market-stats/stats.csv") content = r.content decoded_content = content.decode("UTF-8") csv_lines = csv.reader(decoded_content.splitlines(), delimiter=",") data = self.get_item_names() approve = options["approve"] dont_sync = options["dontsync"] if approve: print("WARNING WILL AUTO APPROVE ALL ITEM CHANGES AT THE END") for tenant in Client.objects.all(): with tenant_context(tenant): if tenant.name != "public": if not dont_sync: item_id_to_sub_sub_type = self.setup_groups(data) self.sync_items(csv_lines, data, item_id_to_sub_sub_type) if approve: for p in ItemChangeProposal.open_proposals(): p.approve(None)
class ItemChangeProposalList(ListView): queryset = ItemChangeProposal.open_proposals() context_object_name = "change_list" template_name = "items/item_change/item_change_list.html"