コード例 #1
0
ファイル: models.py プロジェクト: jobava-eve/eve-wspace
 def save(self, *args, **kwargs):
     """
     Ensure that Sig IDs are proper.
     """
     self.system.clear_sig_cache()
     self.sigid = utils.convert_signature_id(self.sigid)
     super(Signature, self).save(*args, **kwargs)
コード例 #2
0
ファイル: models.py プロジェクト: Unsettled/eve-wspace
 def save(self, *args, **kwargs):
     """
     Ensure that Sig IDs are proper.
     """
     self.system.clear_sig_cache()
     self.sigid = utils.convert_signature_id(self.sigid)
     super(Signature, self).save(*args, **kwargs)
コード例 #3
0
ファイル: views.py プロジェクト: neosilver-gk/eve-wspace
def bulk_sig_import(request, map_id, ms_id):
    """
    GET gets a bulk signature import form. POST processes it, creating sigs
    with blank info and type for each sig ID detected.
    """
    if not request.is_ajax():
        raise PermissionDenied

    map_system = get_object_or_404(MapSystem, pk=ms_id)
    k = 0  # all imported sigs
    numchanged = 0  # sigs changed during import
    numscanned = 0  # sigs changed and fully scanned down during import
    if request.method == "POST":
        reader = csv.reader(request.POST.get("paste", "").decode().splitlines(), delimiter="\t")
        COL_SIG = 0
        COL_STRENGTH = 4
        for row in reader:
            # To prevent pasting of POSes into the sig importer, make sure
            # the strength column is present
            try:
                test_var = row[COL_STRENGTH]
            except IndexError:
                return HttpResponse("A valid signature paste was not found", status=400)
            # limit number of rows pasted
            if k < 75:
                # get sig id from pasted data
                sig_id = utils.convert_signature_id(row[COL_SIG])
                # Query signatures in system to see if it exists
                sig, sigcreated = Signature.objects.get_or_create(sigid=sig_id, system=map_system.system)

                # Update sig with copied TSV data
                sig, update_type = sig.update_from_tsv(request.user, sigcreated, row, map_system)

                sig.modified_by = request.user
                sig.save()
                signals.signature_update.send_robust(
                    sig, user=request.user, map=map_system.map, signal_strength=row[COL_STRENGTH]
                )
                # increment really changed sigs counter
                if update_type == "Updated" or update_type == "Created":
                    numchanged += 1
                if update_type == "Scanned":
                    numscanned += 1
                # increment all imported sigs counter
                k += 1

        # Log the summary as a publicly visible log entry
        map_system.map.add_log(
            request.user,
            "Imported %s signatures for %s(%s). Adjusted:  %s. Scanned: %s."
            % (k, map_system.system.name, map_system.friendlyname, numchanged, numscanned),
            True,
        )

        map_system.system.lastscanned = datetime.now(pytz.utc)
        map_system.system.save()
        return HttpResponse()
    else:
        return TemplateResponse(request, "bulk_sig_form.html", {"mapsys": map_system})
コード例 #4
0
ファイル: views.py プロジェクト: BeanBagKing/eve-wspace
def edit_signature(request, map_id, ms_id, sig_id=None):
    """
    GET gets a pre-filled edit signature form.
    POST updates the signature with the new information and returns a
    blank add form.
    """
    if not request.is_ajax():
        raise PermissionDenied
    map_system = get_object_or_404(MapSystem, pk=ms_id)
    action = None
    if sig_id != None:
        signature = get_object_or_404(Signature, pk=sig_id)
        created = False

    if request.method == 'POST':
        form = SignatureForm(request.POST)
        if form.is_valid():
            ingame_id = utils.convert_signature_id(form.cleaned_data['sigid'])
            if sig_id == None:
                signature, created = Signature.objects.get_or_create(
                            system=map_system.system, sigid=ingame_id)

            signature.sigid = ingame_id
            signature.updated = True
            signature.info = form.cleaned_data['info']
            if request.POST['sigtype'] != '':
                sigtype = form.cleaned_data['sigtype']
            else:
                sigtype = None
            signature.sigtype = sigtype
            signature.save()
            map_system.system.lastscanned = datetime.now(pytz.utc)
            map_system.system.save()
            if created:
                action = 'Created'
            else:
                action = 'Updated'
            map_system.map.add_log(request.user,
                                   "%s signature %s in %s (%s)" %
                                   (action, signature.sigid, map_system.system.name,
                                    map_system.friendlyname))
            signals.signature_update.send_robust(signature, user=request.user,
                                                 map=map_system.map)
        else:
            return TemplateResponse(request, "edit_sig_form.html",
                                    {'form': form,
                                    'system': map_system, 'sig': signature})
    form = SignatureForm()
    if sig_id == None or action == 'Updated':
        return TemplateResponse(request, "add_sig_form.html",
                        {'form': form, 'system': map_system})
    else:
        return TemplateResponse(request, "edit_sig_form.html",
                                {'form': SignatureForm(instance=signature),
                                'system': map_system, 'sig': signature})
コード例 #5
0
def bulk_sig_import(request, map_id, ms_id):
    """
    GET gets a bulk signature import form. POST processes it, creating sigs
    with blank info and type for each sig ID detected.
    """


    if not request.is_ajax():
        raise PermissionDenied
    map_system = get_object_or_404(MapSystem, pk=ms_id)
    k = 0
    if request.method == 'POST':
        reader = csv.reader(request.POST.get('paste', '').decode(
                'utf-8').splitlines(), delimiter="\t")
        COL_SIG = 0
        COL_STRENGTH = 4
        for row in reader:
            # To prevent pasting of POSes into the sig importer, make sure
            # the strength column is present
            try:
                test_var =  row[COL_STRENGTH]
            except IndexError:
                return HttpResponse('A valid signature paste was not found',
                        status=400)
            if k < 75:
                sig_id = utils.convert_signature_id(row[COL_SIG])
                if not Signature.objects.filter(sigid=sig_id,
                        system=map_system.system).exists():

                    new_sig = Signature(sigid=sig_id,
                                        system=map_system.system)
                    updated_sig = _update_sig_from_tsv(new_sig, row)
                    updated_sig.save()
                else:
                    old_sig = Signature.objects.get(
                            sigid=sig_id,
                            system=map_system.system)
                    updated_sig = _update_sig_from_tsv(old_sig, row)
                    updated_sig.save()

                k += 1
        map_system.map.add_log(request.user,
                              "Imported %s signatures for %s(%s)."
                              % (k, map_system.system.name,
                                 map_system.friendlyname), True)
        map_system.system.lastscanned = datetime.now(pytz.utc)
        map_system.system.save()
        return HttpResponse()
    else:
        return TemplateResponse(request, "bulk_sig_form.html",
                                {'mapsys': map_system})
コード例 #6
0
def add_signature(request, map_id, ms_id):
    """
    This function processes the Add Signature form. GET gets the form
    and POST submits it and returns either a blank form or one with errors.
    All requests should be AJAX.
    """
    if not request.is_ajax():
        raise PermissionDenied
    map_system = get_object_or_404(MapSystem, pk=ms_id)

    if request.method == 'POST':
        form = SignatureForm(request.POST)
        if form.is_valid():
            new_sig = form.save(commit=False)
            new_sig.sigid = utils.convert_signature_id(new_sig.sigid)
            if Signature.objects.filter(system=map_system.system,
                    sigid=new_sig.sigid).exists():
                old_sig = Signature.objects.get(system=map_system.system,
                        sigid=new_sig.sigid)
                edit_signature(request, map_id, ms_id, old_sig.pk)
            else:
                new_sig.system = map_system.system
                new_sig.updated = True
                new_sig.save()
                map_system.system.lastscanned = datetime.now(pytz.utc)
                map_system.system.save()
                map_system.map.add_log(
                    request.user, "Added signature %s to %s (%s)."
                    % (new_sig.sigid, map_system.system.name,
                       map_system.friendlyname)
                )
            new_form = SignatureForm()
            return TemplateResponse(request, "add_sig_form.html",
                                {'form': new_form, 'system': map_system})
        else:
            return TemplateResponse(request, "add_sig_form.html",
                                    {'form': form, 'system': map_system})
    else:
        form = SignatureForm()
    return TemplateResponse(request, "add_sig_form.html",
                            {'form': form, 'system': map_system})
コード例 #7
0
ファイル: views.py プロジェクト: yokozuna/eve-wspace
def edit_signature(request, map_id, ms_id, sig_id=None):
    """
    GET gets a pre-filled edit signature form.
    POST updates the signature with the new information and returns a
    blank add form.
    """
    if not request.is_ajax():
        raise PermissionDenied
    map_system = get_object_or_404(MapSystem, pk=ms_id)
    # If the user can't edit signatures, return a blank response
    if map_system.map.get_permission(request.user) != 2:
        return HttpResponse()
    action = None
    isnewscan = False

    if sig_id is not None:
        signature = get_object_or_404(Signature, pk=sig_id)
        created = False
        if not signature.owned_by:
            signature.toggle_ownership(request.user)

    if request.method == 'POST':
        form = SignatureForm(request.POST)
        if form.is_valid():
            # get data from form
            ingame_id = utils.convert_signature_id(form.cleaned_data['sigid'])
            ingame_info = form.cleaned_data['info']
            if request.POST['sigtype'] != '':
                sigtype = form.cleaned_data['sigtype']
            else:
                sigtype = None

            # If new sig entered manually, create it
            if sig_id is None:
                signature, created = Signature.objects.get_or_create(
                    system=map_system.system, sigid=ingame_id)
            # Check for new scan info
            if ingame_info != '' and signature.info != ingame_info:
                isnewscan = True
            # Populate signature
            signature.sigid = ingame_id
            signature.info = ingame_info
            signature.sigtype = sigtype
            # Update signature
            signature.modified_by = request.user
            signature.update()

            map_system.system.lastscanned = datetime.now(pytz.utc)
            map_system.system.save()

            # log the update
            if created:
                action = 'Created'
            if isnewscan:
                action = 'Scanned'
            else:
                action = 'Updated'
            signature.log_sig(request.user, action, map_system)

            if signature.owned_by:
                signature.toggle_ownership(request.user)

            signals.signature_update.send_robust(signature,
                                                 user=request.user,
                                                 map=map_system.map)
        else:
            return TemplateResponse(request, "edit_sig_form.html", {
                'form': form,
                'system': map_system,
                'sig': signature
            })
    form = SignatureForm()
    if sig_id is None or action == 'Updated':
        return TemplateResponse(request, "add_sig_form.html", {
            'form': form,
            'system': map_system
        })
    else:
        return TemplateResponse(
            request, "edit_sig_form.html", {
                'form': SignatureForm(instance=signature),
                'system': map_system,
                'sig': signature
            })
コード例 #8
0
ファイル: views.py プロジェクト: yokozuna/eve-wspace
def bulk_sig_import(request, map_id, ms_id):
    """
    GET gets a bulk signature import form. POST processes it, creating sigs
    with blank info and type for each sig ID detected.
    """
    if not request.is_ajax():
        raise PermissionDenied

    map_system = get_object_or_404(MapSystem, pk=ms_id)
    k = 0  # all imported sigs
    numchanged = 0  # sigs changed during import
    numscanned = 0  # sigs changed and fully scanned down during import
    if request.method == 'POST':
        reader = csv.reader(request.POST.get('paste',
                                             '').decode().splitlines(),
                            delimiter="\t")
        COL_SIG = 0
        COL_STRENGTH = 4
        for row in reader:
            # To prevent pasting of POSes into the sig importer, make sure
            # the strength column is present
            try:
                test_var = row[COL_STRENGTH]
            except IndexError:
                return HttpResponse('A valid signature paste was not found',
                                    status=400)
            # limit number of rows pasted
            if k < 75:
                # get sig id from pasted data
                sig_id = utils.convert_signature_id(row[COL_SIG])
                # Query signatures in system to see if it exists
                sig, sigcreated = Signature.objects.get_or_create(
                    sigid=sig_id, system=map_system.system)

                # Update sig with copied TSV data
                sig, update_type = sig.update_from_tsv(request.user,
                                                       sigcreated, row,
                                                       map_system)

                sig.modified_by = request.user
                sig.save()
                signals.signature_update.send_robust(
                    sig,
                    user=request.user,
                    map=map_system.map,
                    signal_strength=row[COL_STRENGTH])
                # increment really changed sigs counter
                if update_type == "Updated" or update_type == "Created":
                    numchanged += 1
                if update_type == "Scanned":
                    numscanned += 1
                # increment all imported sigs counter
                k += 1

        # Log the summary as a publicly visible log entry
        map_system.map.add_log(
            request.user,
            "Imported %s signatures for %s(%s). Adjusted:  %s. Scanned: %s." %
            (k, map_system.system.name, map_system.friendlyname, numchanged,
             numscanned), True)

        map_system.system.lastscanned = datetime.now(pytz.utc)
        map_system.system.save()
        return HttpResponse()
    else:
        return TemplateResponse(request, "bulk_sig_form.html",
                                {'mapsys': map_system})
コード例 #9
0
ファイル: views.py プロジェクト: viarr/eve-wspace
def edit_signature(request, map_id, ms_id, sig_id=None):
    """
    GET gets a pre-filled edit signature form.
    POST updates the signature with the new information and returns a
    blank add form.
    """
    if not request.is_ajax():
        raise PermissionDenied
    map_system = get_object_or_404(MapSystem, pk=ms_id)
    action = None
    if sig_id != None:
        signature = get_object_or_404(Signature, pk=sig_id)
        created = False

    if request.method == 'POST':
        form = SignatureForm(request.POST)
        if form.is_valid():
            ingame_id = utils.convert_signature_id(form.cleaned_data['sigid'])
            if sig_id == None:
                signature, created = Signature.objects.get_or_create(
                    system=map_system.system, sigid=ingame_id)

            signature.sigid = ingame_id
            signature.updated = True
            signature.info = form.cleaned_data['info']
            if request.POST['sigtype'] != '':
                sigtype = form.cleaned_data['sigtype']
            else:
                sigtype = None
            signature.sigtype = sigtype
            signature.save()
            map_system.system.lastscanned = datetime.now(pytz.utc)
            map_system.system.save()
            if created:
                action = 'Created'
            else:
                action = 'Updated'
            map_system.map.add_log(
                request.user, "%s signature %s in %s (%s)" %
                (action, signature.sigid, map_system.system.name,
                 map_system.friendlyname))
            signals.signature_update.send_robust(signature,
                                                 user=request.user,
                                                 map=map_system.map)
        else:
            return TemplateResponse(request, "edit_sig_form.html", {
                'form': form,
                'system': map_system,
                'sig': signature
            })
    form = SignatureForm()
    if sig_id == None or action == 'Updated':
        return TemplateResponse(request, "add_sig_form.html", {
            'form': form,
            'system': map_system
        })
    else:
        return TemplateResponse(
            request, "edit_sig_form.html", {
                'form': SignatureForm(instance=signature),
                'system': map_system,
                'sig': signature
            })
コード例 #10
0
ファイル: views.py プロジェクト: jbong/eve-wspace
def edit_signature(request, map_id, ms_id, sig_id=None):
    """
    GET gets a pre-filled edit signature form.
    POST updates the signature with the new information and returns a
    blank add form.
    """
    if not request.is_ajax():
        raise PermissionDenied
    map_system = get_object_or_404(MapSystem, pk=ms_id)
    # If the user can't edit signatures, return a blank response
    if map_system.map.get_permission(request.user) != 2:
        return HttpResponse()
    action = None
    if sig_id != None:
        signature = get_object_or_404(Signature, pk=sig_id)
        created = False
        if not signature.owned_by:
            signature.toggle_ownership(request.user)
    if request.method == "POST":
        form = SignatureForm(request.POST)
        if form.is_valid():
            ingame_id = utils.convert_signature_id(form.cleaned_data["sigid"])
            if sig_id == None:
                signature, created = Signature.objects.get_or_create(system=map_system.system, sigid=ingame_id)

            signature.sigid = ingame_id
            signature.updated = True
            signature.info = form.cleaned_data["info"]
            if request.POST["sigtype"] != "":
                sigtype = form.cleaned_data["sigtype"]
            else:
                sigtype = None
            signature.sigtype = sigtype
            signature.modified_by = request.user
            signature.save()
            map_system.system.lastscanned = datetime.now(pytz.utc)
            map_system.system.save()
            if created:
                action = "Created"
            else:
                action = "Updated"
            if signature.owned_by:
                signature.toggle_ownership(request.user)
            map_system.map.add_log(
                request.user,
                "%s signature %s in %s (%s)"
                % (action, signature.sigid, map_system.system.name, map_system.friendlyname),
            )
            signals.signature_update.send_robust(signature, user=request.user, map=map_system.map)
        else:
            return TemplateResponse(
                request, "edit_sig_form.html", {"form": form, "system": map_system, "sig": signature}
            )
    form = SignatureForm()
    if sig_id == None or action == "Updated":
        return TemplateResponse(request, "add_sig_form.html", {"form": form, "system": map_system})
    else:
        return TemplateResponse(
            request,
            "edit_sig_form.html",
            {"form": SignatureForm(instance=signature), "system": map_system, "sig": signature},
        )
コード例 #11
0
ファイル: views.py プロジェクト: neosilver-gk/eve-wspace
def edit_signature(request, map_id, ms_id, sig_id=None):
    """
    GET gets a pre-filled edit signature form.
    POST updates the signature with the new information and returns a
    blank add form.
    """
    if not request.is_ajax():
        raise PermissionDenied
    map_system = get_object_or_404(MapSystem, pk=ms_id)
    # If the user can't edit signatures, return a blank response
    if map_system.map.get_permission(request.user) != 2:
        return HttpResponse()
    action = None
    isnewscan = False

    if sig_id is not None:
        signature = get_object_or_404(Signature, pk=sig_id)
        created = False
        if not signature.owned_by:
            signature.toggle_ownership(request.user)

    if request.method == "POST":
        form = SignatureForm(request.POST)
        if form.is_valid():
            # get data from form
            ingame_id = utils.convert_signature_id(form.cleaned_data["sigid"])
            ingame_info = form.cleaned_data["info"]
            if request.POST["sigtype"] != "":
                sigtype = form.cleaned_data["sigtype"]
            else:
                sigtype = None

            # If new sig entered manually, create it
            if sig_id is None:
                signature, created = Signature.objects.get_or_create(system=map_system.system, sigid=ingame_id)
            # Check for new scan info
            if ingame_info != "" and signature.info != ingame_info:
                isnewscan = True
            # Populate signature
            signature.sigid = ingame_id
            signature.info = ingame_info
            signature.sigtype = sigtype
            # Update signature
            signature.modified_by = request.user
            signature.update()

            map_system.system.lastscanned = datetime.now(pytz.utc)
            map_system.system.save()

            # log the update
            if created:
                action = "Created"
            if isnewscan:
                action = "Scanned"
            else:
                action = "Updated"
            signature.log_sig(request.user, action, map_system)

            if signature.owned_by:
                signature.toggle_ownership(request.user)

            signals.signature_update.send_robust(signature, user=request.user, map=map_system.map)
        else:
            return TemplateResponse(
                request, "edit_sig_form.html", {"form": form, "system": map_system, "sig": signature}
            )
    form = SignatureForm()
    if sig_id is None or action == "Updated":
        return TemplateResponse(request, "add_sig_form.html", {"form": form, "system": map_system})
    else:
        return TemplateResponse(
            request,
            "edit_sig_form.html",
            {"form": SignatureForm(instance=signature), "system": map_system, "sig": signature},
        )