Пример #1
0
def update_users():
    new_data = []
    local_data = User.objects.fingerprint_map()
    fresh_data = get_sheet("users").get_data()
    fields = settings.USER_FIELDS

    for item in fresh_data:

        fingerprint = get_fingerprint(item[fields["timestamp"]], item[fields["email"]])

        try:
            local_item = local_data.pop(fingerprint)
            local_item.data = json.dumps(item)
            local_item.enabled = item.get(fields["enabled"]) == "TRUE"
            local_item.organizer = item.get(fields["organizer"]) == "TRUE"
            local_item.terminator = item.get(fields["terminator"]) == "TRUE"
            local_item.save()
        except KeyError:
            new_data.append(
                User.objects.create(
                    timestamp=item[fields["timestamp"]],
                    email=item[fields["email"]],
                    data=json.dumps(item),
                    enabled=item.get(fields["enabled"]) == "TRUE",
                    organizer=item.get(fields["organizer"]) == "TRUE",
                    terminator=item.get(fields["terminator"]) == "TRUE",
                )
            )

    for deleted_item in local_data.values():
        deleted_item.deleted = True
        deleted_item.save()

    for user in User.objects.filter(deleted=False, enabled=True, invitation_sent=False):
        user.invite()
Пример #2
0
    def fingerprint_map(self):
        """
        Return maping of users fingerprint to user instances.
        """
        results = {}

        for user in self.get_queryset().all():
            results[get_fingerprint(user.timestamp, user.email)] = user

        return results
Пример #3
0
    def fingerprint_map(self):
        """
        Return maping of application fingerprint to application instance.
        """
        results = {}

        for app in self.get_queryset().all():
            results[get_fingerprint(app.timestamp, app.email)] = app

        return results