コード例 #1
0
def save(request, icao):
    """
    Create airport commit.
    @param request: The HttpRequest; it has to contain new airport data.
    @param icao: The airport ICAO code.
    @return: The JsonResponse.
    """
    try:
        airport = Airport.objects.get(icao=icao)
        commit = Commit.create(airport)
        commit.email = request.POST['email']
        commit.description = request.POST['description']
        commit.url = '/airports/details/' + airport.icao
        commit.save()

        fields = ['iata', 'name', 'city', 'country', 'latitude', 'longitude', 'altitude']
        for f in fields:
            try:
                old = unicode(getattr(airport, f))
                new = request.POST[f].strip()
            except AttributeError:
                return {'result': 0, 'reason': 'Invalid request'}

            if old != new:
                data = CommitData.create(commit, f, old, new)
                data.save()

        return {'result': 1}
    except KeyError:
        return {'result': 0, 'reason': 'Invalid request'}
コード例 #2
0
def save(request, icao):
    """
    Create airline commit.
    @param request: The HttpRequest; has to store new airline values in POST.
    @param icao: The airline ICAO code.
    @return: The JsonResponse.
    """
    try:
        airline = Airline.objects.get(icao=icao)
        commit = Commit.create(airline)
        commit.email = request.POST['email']
        commit.description = request.POST['description']
        commit.url = '/airlines/details/' + airline.icao
        commit.save()

        fields = ['name', 'country', 'website', 'logo']
        for f in fields:
            try:
                old = unicode(getattr(airline, f))
                new = request.POST[f].strip()
            except AttributeError:
                return {'result': 0, 'reason': 'Invalid request'}

            if old != new:
                data = CommitData.create(commit, f, old, new)
                data.save()

        return {'result': 1}
    except KeyError:
        return {'result': 0, 'reason': 'Invalid request'}
コード例 #3
0
 def create_commit(self, git_commit, author, branch):
     hexsha = git_commit.hexsha
     date = git_commit.authored_datetime
     msg = git_commit.message
     is_merge = len(git_commit.parents) > 1
     stats = git_commit.stats.total
     ins = int(stats['insertions']) if not is_merge else 0
     dels = int(stats['deletions']) if not is_merge else 0
     lines = int(stats['lines']) if not is_merge else 0
     net = int(ins - dels) if not is_merge else 0
     real_author = author.get_principal()
     return Commit(hexsha=hexsha,
                   repository=self.repo,
                   branch=branch,
                   date=make_aware(date) if not is_aware(date) else date,
                   message=msg,
                   insertions=ins,
                   deletions=dels,
                   lines=lines,
                   net=net,
                   is_merge=is_merge,
                   author=real_author,
                   original_author=author)