avatar.models

Define the Avatar models.

Copyright (C) 2018 Gitcoin Core

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Avatar

Avatar(self, *args, **kwargs)

Store the options necessary to render a Gitcoin avatar.

avatar_url

Return the appropriate avatar URL.

config

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

custom_avatar_png

Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.

_method

Avatar._method(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=True, **kwargs)

_method

Avatar._method(self, *, field=<django.db.models.fields.DateTimeField: modified_on>, is_next=True, **kwargs)

_method

Avatar._method(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=False, **kwargs)

_method

Avatar._method(self, *, field=<django.db.models.fields.DateTimeField: modified_on>, is_next=False, **kwargs)

github_avatar_url

Return the Github avatar URL.

github_svg

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like::

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do::

>>> with open('/path/to/hello.world', 'r') as f:
...     instance.file = File(f)

ICON_SIZE

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

png

Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.

profile_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

svg

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like::

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do::

>>> with open('/path/to/hello.world', 'r') as f:
...     instance.file = File(f)

use_github_avatar

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save

Avatar.save(self, *args, force_insert=False, force_update=False, **kwargs)

Override the save to perform change comparison against PNG and SVG fields.

pull_github_avatar

Avatar.pull_github_avatar(self)

Pull the latest avatar from Github and store in Avatar.png.

Returns: str: The stored Github avatar URL.

determine_response

Avatar.determine_response(self, use_svg=True)

Determine the content type and file to serve.

Args: use_svg (bool): Whether or not to use SVG format.

get_avatar_url

Avatar.get_avatar_url(self, use_svg=True)

Get the Avatar URL.

Args: use_svg (bool): Whether or not to use SVG format.

create_from_config

Avatar.create_from_config(self)

Create an avatar SVG from the configuration.

TODO: * Deprecate in favor of request param based view using templates.

convert_field

Avatar.convert_field(self, source, target='custom_avatar_png', input_fmt='svg', output_fmt='png', force_save=False)

Handle converting from the source field to the target based on format.

convert_custom_svg

Avatar.convert_custom_svg(self, force_save=False)

Handle converting the custom Avatar SVG to PNG.

convert_github_png

Avatar.convert_github_png(self, force_save=False)

Handle converting the Github Avatar PNG to SVG.