Welcome to Fox.Web.Assistant’s documentation!
This software includes a contact book with the ability to save contact information, notes for recording textual information, and a function for uploading and categorizing user files, as well as aggregating news from various sources on selected topics.
CONTACTS
contacts.forms module
- class contacts.forms.ContactForm(*args, **kwargs)[source]
-
Bases:
ModelFormForm fields:
-
name: Name (CharField) -
address: Address (CharField) -
phone_number: Phone number (CharField) -
email: Email (EmailField) -
birthday: Birthday (DateField) -
note: Note (CharField)
- __init__(*args, **kwargs)[source]
-
The __init__ method initializes the ContactForm object. It sets up the attributes of an instance of a ContactForm object. The user and request arguments are optional, but if they are not provided, they will be set to None.
- Parameters:
-
-
self – Refer to the current instance of the object
-
*args –
Non-keyworded variable length argument list
-
**kwargs –
Pass keyword arguments to a function
-
- Returns:
-
The user and request objects
- Doc-author:
-
Trelent
- clean_birthday()[source]
-
The clean_birthday function validates the birthday field. It checks that the date is not in the future, and that it is at least 18 years ago.
- Parameters:
-
self – Access the instance of the class
- Returns:
-
The birthday field
- Doc-author:
-
Trelent
- clean_email()[source]
-
The clean_email function is a function that checks to see if the email address entered by the user is valid. It does this by using a regular expression, which looks for an @ symbol and at least one period in the string. If it finds these things, then it returns true and allows the user to continue with their registration process.
- Parameters:
-
self – Refer to the current instance of the class
- Returns:
-
The email address if it is valid
- Doc-author:
-
Trelent
- clean_phone_number()[source]
-
The clean_phone_number function is a function that takes in the phone number and checks to see if it matches the regular expression. If it does not match, then an error message will be raised. Otherwise, the data will be returned.
- Parameters:
-
self – Refer to the current instance of the class
- Returns:
-
A valid phone number
- Doc-author:
-
Trelent
- property media
-
Return all media required to render the widgets on this form.
- save(user=None, commit=True)[source]
-
The save function is a function that saves the form. It takes two arguments: user and commit. The user argument is an optional argument, which defaults to None if not specified. The commit argument is also an optional argument, which defaults to True if not specified.
- Parameters:
-
-
self – Refer to the current instance of a class
-
user – Assign the user to the contact
-
commit – Tell django whether or not to save the model after it has been created
-
- Returns:
-
The instance of the model
- Doc-author:
-
Trelent
-
- contacts.forms.validate_birth_date(value)[source]
-
The validate_birth_date function is a custom validator that ensures the birthdate is in the past and not more than 120 years ago. It raises a ValidationError if either of these conditions are not met.
- Parameters:
-
value – Pass the value of the field that is being validated
- Returns:
-
The value if it is a valid birthdate
- Doc-author:
-
Trelent
contacts.views module
- contacts.views.contact_list(request)[source]
-
The contact_list function is a view that displays all contacts in the database. It takes an HTTP request as its first argument and returns an HTTP response. The contact_list function uses the render() shortcut to generate a template response, which means it will return an HttpResponse object with the rendered template content filled in.
- Parameters:
-
request – Get the user’s contacts
- Returns:
-
A rendered template, which is the html for the contacts page
- Doc-author:
-
Trelent
- contacts.views.create_contact(request)[source]
-
The create_contact function is used to create a new contact. The function first checks if the request method is POST, which means that the user has submitted data via a form. If so, it creates an instance of ContactForm and passes in the POST data from the request object as an argument. It then sets form’s request attribute equal to request (this will be explained later). Next, it checks if form is valid by calling its is_valid() method. If so, it saves contact without committing changes to database yet by calling save(commit=False) on form and assigning result to variable named contact;
- Parameters:
-
request – Get the request object
- Returns:
-
A redirect to the contact_list view
- Doc-author:
-
Trelent
- contacts.views.delete_contact(request, contact_id)[source]
-
The delete_contact function is a view that allows the user to delete a contact. The function takes two arguments: request and contact_id. The request argument is an HTTP Request object, which contains information about the current web request that has triggered this view. The contact_id argument is an integer representing the primary key of the Contact instance we want to delete.
- Parameters:
-
-
request – Get the current request
-
contact_id – Identify the contact to be deleted
-
- Returns:
-
A render function
- Doc-author:
-
Trelent
- contacts.views.edit_contact(request, contact_id)[source]
-
The edit_contact function is used to edit a contact. It takes the request and contact_id as parameters, gets the object or 404 error if it doesn’t exist, checks if the method is POST and then saves it.
- Parameters:
-
-
request – Get the current request
-
contact_id – Retrieve the contact from the database
-
- Returns:
-
An httpresponseredirect object
- Doc-author:
-
Trelent
- contacts.views.get_contacts_with_birthday_in(request)[source]
-
The get_contacts_with_birthday_in function takes a request object as its only argument. It then extracts the days_until_birthday parameter from the GET data of that request, and attempts to convert it into an integer. If this conversion fails, or if the resulting number is not positive, we render a search error page and return immediately. Otherwise we calculate target date end by adding days until birthday to current date (which is calculated using timezone now). We then use Q objects to filter our contacts with birthdays in that range.
- Parameters:
-
request – Get the user’s input from the search box
- Returns:
-
A rendered template with the contacts that have a birthday within
- Doc-author:
-
Trelent
- contacts.views.search_contacts(request)[source]
-
The search_contacts function takes a request and returns a rendered template. The request is expected to be an HTTP GET with the query parameter ‘q’ set to the search term. The function will return all contacts whose name contains the search term in any case.
- Parameters:
-
request – Pass the request object to the view
- Returns:
-
A list of contacts that match the query
- Doc-author:
-
Trelent
EXCHANGE
exchange.exchange module
- exchange.exchange.clear_currency_database()[source]
-
The clear_currency_database function deletes all the objects in the Currencies database. This is useful for when you want to update your currency database with new data.
- Returns:
-
Nothing
- Doc-author:
-
Trelent
- exchange.exchange.finance_currency(url='https://finance.ua/ru/currency')[source]
-
The finance_currency function scrapes the Finance.ua website for currency exchange rates and returns a list of dictionaries containing the following keys: bank_name - name of the bank (Finance.ua) eur_buy - Euro buy rate eur_sell - Euro sell rate usd_buy - US Dollar buy rate usd_sell - US Dollar sell rate
- Parameters:
-
url – Specify the url of the page that we want to scrape
- Returns:
-
A list with one dictionary
- Doc-author:
-
Trelent
- exchange.exchange.minfin_currency(url='https://minfin.com.ua/currency/')[source]
-
The minfin_currency function scrapes the Minfin website for currency exchange rates. It returns a list of dictionaries with the following keys: bank_name, eur_buy, eur_sell, usd_buy, usd_sell and pln buy. The values are strings representing the current exchange rate.
- Parameters:
-
url – Specify the url of the page to scrape
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- exchange.exchange.privat_currency(url='https://privatbank.ua')[source]
-
The privat_currency function scrapes the PrivatBank website for currency exchange rates. It returns a list of dictionaries containing the following keys: bank_name, eur_buy, eur_sell, usd_buy, usd_sell, pln_buy and pln sell.
- Parameters:
-
url – Pass the url to the function
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- exchange.exchange.pumb_currency(url='https://about.pumb.ua/info/currency_converter')[source]
-
The pumb_currency function scrapes the Pumb bank’s website for currency exchange rates. It returns a list of dictionaries with the following keys: - bank_name (str) - eur_buy (float) - eur_sell (float) - usd_buy (float) - usd_sell(float)
- Parameters:
-
url – Specify the url of the page to be scraped
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- exchange.exchange.save_currencies_to_database(currencies_list)[source]
-
The save_currencies_to_database function takes a list of dictionaries as an argument. Each dictionary in the list contains information about one bank’s currency exchange rates. The function creates Currencies objects from each dictionary and saves them to the database.
- Parameters:
-
currencies_list – Pass the list of dictionaries to the function
- Returns:
-
The number of created objects
- Doc-author:
-
Trelent
exchange.views module
- exchange.views.add_currency(request)[source]
-
The add_currency function is used to add currency data from four different sources to the database. The function takes in a request object and returns an HttpResponseRedirect object that redirects the user to the currency page.
- Parameters:
-
request – Get the data from the form
- Returns:
-
The redirect function, which is used to return an http response with a url to the client
- Doc-author:
-
Trelent
- exchange.views.list_currency(request)[source]
-
The list_currency function is used to display the exchange rate of different banks. It takes a request as an argument and returns a render function with the following arguments: - request, which is passed from the view; - "home/exchange_rate.html", which is a template for displaying data; - {"privat"
- : privat, " pumb": pumb, "minfin": minfin, "finance": finance},
-
where privat = Currencies.objects.filter(bank_name="PrivatBank"), pumb = Currencies.objects.filter(bank
- Parameters:
-
request – Pass the request object to the view
- Returns:
-
The exchange rate for each bank
- Doc-author:
-
Trelent
NOTES
notes.views module
- class notes.views.NoteCreateView(**kwargs)[source]
-
Bases:
LoginRequiredMixin,CreateView- form_class
-
alias of
NoteForm
- form_valid(form)[source]
-
The form_valid function is called when a form is submitted and valid. It’s passed the form object, which contains all of the data entered by the user. The function should return an HttpResponseRedirect to redirect to another page or render_to_response() to display a template.
- Parameters:
-
-
self – Refer to the current instance of a class
-
form – Pass the form to the view
-
- Returns:
-
The superclass form_valid function
- Doc-author:
-
Trelent
- get_context_data(**kwargs)[source]
-
The get_context_data function is a method that Django calls when rendering the template. It allows us to add extra context data to the template, which we can then use in our templates. In this case, we’re adding a list of all tags owned by the current user.
- Parameters:
-
-
self – Refer to the current object
-
**kwargs –
Pass keyword arguments to the view
-
- Returns:
-
A dictionary of data that is passed to the template
- Doc-author:
-
Trelent
- get_success_url()[source]
-
The get_success_url function is a helper function that returns the URL to redirect to after processing a form. The default implementation will return the value of success_url, if it’s set. Otherwise, it’ll try and determine the correct URL by looking at the object’s get_absolute_url method.
- Parameters:
-
self – Refer to the object that is calling the function
- Returns:
-
The url of the page that we want to go to after a successful form submission
- Doc-author:
-
Trelent
- model
-
alias of
Note
- template_name = 'notes/note_form.html'
- class notes.views.NoteDeleteView(*args, **kwargs)[source]
-
Bases:
LoginRequiredMixin,DeleteView- get_success_url()[source]
-
The get_success_url function is a helper function that returns the URL to redirect to after processing a form. The default implementation will return the value of success_url, if it’s set. Otherwise, it’ll try and determine the correct URL by looking at the object’s get_absolute_url method.
- Parameters:
-
self – Refer to the current object
- Returns:
-
The url of the note list view
- Doc-author:
-
Trelent
- model
-
alias of
Note
- template_name = 'notes/note_confirm_delete.html'
- class notes.views.NoteDetailView(**kwargs)[source]
-
Bases:
LoginRequiredMixin,DetailView- context_object_name = 'note'
- get_context_data(**kwargs)[source]
-
The get_context_data function is a method that Django calls when rendering the template. It allows us to add extra context data to the template, which we can then use in our templates. In this case, we’re adding a list of all tags owned by the current user.
- Parameters:
-
-
self – Refer to the current object
-
**kwargs –
Pass keyworded, variable-length argument list to a function
-
- Returns:
-
A dictionary
- Doc-author:
-
Trelent
- model
-
alias of
Note
- template_name = 'notes/note_detail.html'
- class notes.views.NoteEditView(**kwargs)[source]
-
Bases:
LoginRequiredMixin,UpdateView- form_class
-
alias of
NoteForm
- get_context_data(**kwargs)[source]
-
The get_context_data function is a method that Django calls when rendering the template. It allows us to add extra context data to the template, which we can then use in our templates. In this case, we’re adding a list of all tags owned by the current user.
- Parameters:
-
-
self – Refer to the current object
-
**kwargs –
Pass keyworded, variable-length argument list to a function
-
- Returns:
-
A dictionary of context data
- Doc-author:
-
Trelent
- get_success_url()[source]
-
The get_success_url function is a helper function that returns the URL to redirect to after processing a form. The default implementation will return the value of success_url, if it’s set. Otherwise, it’ll try and determine the correct URL by looking at the object’s get_absolute_url method.
- Parameters:
-
self – Refer to the current instance of the class
- Returns:
-
The url of the note list page
- Doc-author:
-
Trelent
- model
-
alias of
Note
- template_name = 'notes/note_form.html'
- class notes.views.NoteListView(**kwargs)[source]
-
Bases:
LoginRequiredMixin,ListView- context_object_name = 'notes'
- get_context_data(**kwargs)[source]
-
The get_context_data function is a method that Django calls when rendering the template. It allows us to add extra context variables to the template, which we can then use in our templates.
- Parameters:
-
-
self – Refer to the current instance of the class
-
**kwargs –
Pass keyword arguments to the function
-
- Returns:
-
A dictionary with the key "all_tags" and value of all tags for the current user
- Doc-author:
-
Trelent
- get_queryset()[source]
-
The get_queryset function is a method that returns the queryset of objects to be displayed in the view. The default implementation simply returns self.model._default_manager.all(), but it may be overridden to customize the behavior of all list views.
- Parameters:
-
self – Refer to the current object
- Returns:
-
A queryset that is filtered by the current user
- Doc-author:
-
Trelent
- model
-
alias of
Note
- template_name = 'notes/note_list.html'
- class notes.views.TagCreateView(**kwargs)[source]
-
Bases:
LoginRequiredMixin,CreateView- form_class
-
alias of
TagForm
- form_valid(form)[source]
-
The form_valid function is called when a form is submitted and valid. It’s passed the form object, which contains all of the data entered by the user. The function should return an HttpResponseRedirect to redirect to another page or render_to_response() to display a template.
- Parameters:
-
-
self – Refer to the current instance of a class
-
form – Access the form that was submitted
-
- Returns:
-
The super() of the form_valid function
- Doc-author:
-
Trelent
- get_success_url()[source]
-
The get_success_url function is a helper function that returns the URL to redirect to after successful form submission.
- Parameters:
-
self – Refer to the current object
- Returns:
-
The url of the tag_list view
- Doc-author:
-
Trelent
- model
-
alias of
Tag
- template_name = 'notes/tag_form.html'
- class notes.views.TagDeleteView(*args, **kwargs)[source]
-
Bases:
LoginRequiredMixin,DeleteView- get_success_url()[source]
-
The get_success_url function is a helper function that returns the URL to redirect to after processing a valid form. It’s used by both CreateView and UpdateView, but it can be overridden if you need custom logic.
- Parameters:
-
self – Represent the instance of the object
- Returns:
-
The success_url variable
- Doc-author:
-
Trelent
- model
-
alias of
Tag
- success_url = '/notes/tags/'
- class notes.views.TagEditView(**kwargs)[source]
-
Bases:
LoginRequiredMixin,UpdateView- form_class
-
alias of
TagForm
- get_success_url()[source]
-
The get_success_url function is a helper function that returns the URL to redirect to after successful form submission.
- Parameters:
-
self – Refer to the current object
- Returns:
-
The url of the tag_list view
- Doc-author:
-
Trelent
- model
-
alias of
Tag
- template_name = 'notes/tag_form.html'
- class notes.views.TagListView(**kwargs)[source]
-
Bases:
LoginRequiredMixin,ListView- context_object_name = 'tags'
- get_queryset()[source]
-
The get_queryset function is a method that returns the queryset of objects that will be used to create this view. By default, it returns model._default_manager.all(), but we override it here to return only the notes owned by the current user.
- Parameters:
-
self – Refer to the current object
- Returns:
-
A queryset that filters the objects by owner
- Doc-author:
-
Trelent
- model
-
alias of
Tag
- template_name = 'notes/tag_list.html'
- notes.views.toggle_note_done(request, pk)[source]
-
The toggle_note_done function is a view that toggles the done status of a note. It takes an HTTP request and the primary key of a note as arguments, gets the note with get_object_or_404, toggles its done attribute, saves it back into the database and redirects back to the list view.
- Parameters:
-
-
request – Pass the request object to the view
-
pk – Retrieve the note object from the database
-
- Returns:
-
A redirect to the note_list view
- Doc-author:
-
Trelent
PARSING
parsing.news module
- parsing.news.auto_news(url='https://tsn.ua/auto')[source]
-
The auto_news function scrapes the TSN.ua website for news articles about cars and returns a list of dictionaries, each dictionary containing information about one article: - category (string) - short_description (string) - news_link (string) - photo_link (string or None if no photo is available for that article).
- Parameters:
-
url – Specify the url of the page from which we want to get news
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- parsing.news.economy_news(url='https://tsn.ua/groshi')[source]
-
The economy_news function scrapes the TSN website for economy news. It returns a list of dictionaries, each dictionary containing information about one article: - category (Economy) - short_description (the first 35 characters of the article’s text) - news_link (a link to the full article on TSN’s website) - photo_link (a link to an image associated with that particular article).
- Parameters:
-
url – Specify the url of the page from which we will take news
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- parsing.news.health_news(url='https://tsn.ua/zdorovya')[source]
-
The health_news function scrapes the TSN website for health news articles. It returns a list of dictionaries, each dictionary containing information about one article: - category (string) - short_description (string) - news_link (string) # link to the full article on tsn.ua website - photo_link (string or NoneType if no photo is available for this particular article).
- Parameters:
-
url – Pass the url of the page from which we want to get news
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- parsing.news.other_news(url='https://tsn.ua/other')[source]
-
The other_news function scrapes the TSN.ua website for news articles in the ‘Other’ category, and returns a list of dictionaries containing information about each article.
- Parameters:
-
url – Specify the url of the page from which we want to get information
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- parsing.news.politika_news(url='https://tsn.ua/politika')[source]
-
The politika_news function scrapes the TSN website for news articles in the ‘Politika’ category. It returns a list of dictionaries, each dictionary containing information about one article: - category (string) - short_description (string) - news_link (string) - photo_link (string or NoneType if no photo is available for that article).
- Parameters:
-
url – Specify the url of the website we want to scrape
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- parsing.news.save_news_to_database(news_list)[source]
-
The save_news_to_database function takes a list of dictionaries as an argument. Each dictionary in the list represents a news article, and has keys for category, short_description, news_link and photo_link. The function creates News objects from each dictionary in the list (using bulk create), then saves them to the database.
- Parameters:
-
news_list – Pass the list of dictionaries to the function
- Returns:
-
Nothing
- Doc-author:
-
Trelent
- parsing.news.science_and_it_news(url='https://tsn.ua/nauka_it')[source]
-
The science_and_it_news function scrapes the TSN website for science and IT news. It returns a list of dictionaries, each dictionary containing information about one article: category, short_description, news_link and photo_link.
- Parameters:
-
url – Get the url of the page from which we will scrape data
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- parsing.news.sport_news(url='https://tsn.ua/prosport')[source]
-
The sport_news function scrapes the TSN website for the latest sport news. It returns a list of dictionaries, each dictionary containing information about one article: - category (Sport) - short_description (the first 35 characters of the article’s title) - news_link (a link to the full article on TSN’s website) - photo_link (a link to an image associated with that particular article).
- Parameters:
-
url – Pass the url of the page from which we want to get news
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
- parsing.news.tourism_news(url='https://tsn.ua/tourism')[source]
-
The tourism_news function scrapes the TSN.ua website for tourism news and returns a list of dictionaries, each dictionary containing information about one article: - category (str) - short_description (str) - news_link (str) - photo_link (str or NoneType if no photo is available for that article).
- Parameters:
-
url – Specify the url of the page to be scraped
- Returns:
-
A list of dictionaries
- Doc-author:
-
Trelent
parsing.views module
S3_STORAGE
s3_storage.models module
- class s3_storage.models.File(id, user, category, file, original_filename, description, upload_date)[source]
-
Bases:
Model- Parameters:
-
-
id (BigAutoField) – Primary key: ID
-
file (FileField) – File
-
original_filename (CharField) – Original filename
-
description (TextField) – Description
-
upload_date (DateTimeField) – Upload date
-
Relationship fields:
- Parameters:
-
-
user (
ForeignKeytoUser) – User (related name:files) -
category (
ForeignKeytoFileCategory) – Category (related name:files)
-
- exception DoesNotExist
-
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
-
Bases:
MultipleObjectsReturned
- category
-
Type:
ForeignKeytoFileCategoryCategory (related name:
files)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- description
-
Type:
TextFieldDescription
A wrapper for a deferred-loading field. When the value is read from this
- file
-
Type:
FileFieldFile
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') as f:
- get_next_by_upload_date(*, field=<django.db.models.DateTimeField: upload_date>, is_next=True, **kwargs)
-
Finds next instance based on
upload_date. Seeget_next_by_FOO()for more information.
- get_previous_by_upload_date(*, field=<django.db.models.DateTimeField: upload_date>, is_next=False, **kwargs)
-
Finds previous instance based on
upload_date. Seeget_previous_by_FOO()for more information.
- id
-
Type:
BigAutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- original_filename
-
Type:
CharFieldOriginal filename
A wrapper for a deferred-loading field. When the value is read from this
- upload_date
-
Type:
DateTimeFieldUpload date
A wrapper for a deferred-loading field. When the value is read from this
- user
-
Type:
ForeignKeytoUserUser (related name:
files)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- class s3_storage.models.FileCategory(id, user, name)[source]
-
Bases:
Model- Parameters:
-
-
id (BigAutoField) – Primary key: ID
-
name (CharField) – Name
-
Relationship fields:
- Parameters:
-
user (
ForeignKeytoUser) – User (related name:file_categories)
Reverse relationships:
- Parameters:
-
files (Reverse
ForeignKeyfromFile) – All files of this file category (related name ofcategory)
- exception DoesNotExist
-
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
-
Bases:
MultipleObjectsReturned
- files
-
Type: Reverse
ForeignKeyfromFileAll files of this file category (related name of
category)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.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- id
-
Type:
BigAutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- user
-
Type:
ForeignKeytoUserUser (related name:
file_categories)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- class s3_storage.models.Profile(id, user, avatar)[source]
-
Bases:
Model- Parameters:
-
-
id (BigAutoField) – Primary key: ID
-
avatar (ImageField) – Avatar
-
Relationship fields:
- Parameters:
-
user (
OneToOneFieldtoUser) – User (related name:profile)
- exception DoesNotExist
-
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
-
Bases:
MultipleObjectsReturned
- avatar
-
Type:
ImageFieldAvatar
Just like the FileDescriptor, but for ImageFields. The only difference is
- id
-
Type:
BigAutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- save(*args, **kwargs)[source]
-
The save function is a function that saves the image to the database. It takes in two arguments, *args and **kwargs. The first argument is a tuple of positional arguments, and second argument is a dictionary of keyword arguments.
- Parameters:
-
-
self – Refer to the current instance of the class
-
*args –
Send a non-keyworded variable length argument list to the function
-
**kwargs –
Pass keyworded, variable-length argument list to a function
-
- Returns:
-
The instance of the object
- Doc-author:
-
Trelent
- user
-
Type:
OneToOneFieldtoUserUser (related name:
profile)Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
- s3_storage.models.upload_avatar(instance, filename)[source]
-
The upload_avatar function is a function that takes in an instance and filename. It then splits the filename into two parts, the extension and the name of the file. The extension is stored as ext, while uuid4() generates a random hexadecimal number and stores it as filename. The return statement returns avatars/filename.
- Parameters:
-
-
instance – Get the user id and filename is used to get the file extension
-
filename – Get the file name of the image
-
- Returns:
-
A string that is the path to the avatar
- Doc-author:
-
Trelent
- s3_storage.models.upload_to_s3(instance, filename)[source]
-
The upload_to_s3 function is a callback function that will be called when the model instance is saved. It takes two arguments: an instance of the model, and a filename. The function returns a string which is used as the path to upload the file to S3.
- Parameters:
-
-
instance – Access the instance of the model that is being saved
-
filename – Specify the name of the file that is being uploaded to s3
-
- Returns:
-
A string with the name of the file to be uploaded
- Doc-author:
-
Trelent
s3_storage.views module
- s3_storage.views.category_list(request)[source]
-
The category_list function is a view that displays all of the categories that belong to the user. It takes in a request object and returns an HttpResponse object with the rendered template "s3_storage/category_list.html" and context variable "categories", which contains all of the FileCategory objects belonging to this user.
- Parameters:
-
request – Get the user from the request object
- Returns:
-
A list of all the categories for a user
- Doc-author:
-
Trelent
- s3_storage.views.create_category(request)[source]
-
The create_category function is used to create a new category for the user. The function first checks if the request method is POST, and if it is, then it creates a new FileCategory object with the name of the category being equal to what was entered in by the user. The function then saves this object and redirects to s3_storage:category_list.
- Parameters:
-
request – Get the request object, which contains information about the user and their session
- Returns:
-
A redirect to the category_list view
- Doc-author:
-
Trelent
- s3_storage.views.delete_category(request, category_id)[source]
-
The delete_category function deletes a file category.
- Parameters:
-
-
request – Get the user from the request object
-
category_id – Find the category that is to be deleted
-
- Returns:
-
A jsonresponse with a message and status code 200 if the category is successfully deleted
- Doc-author:
-
Trelent
- s3_storage.views.delete_file(request, file_id)[source]
-
The delete_file function takes a request and file_id as parameters. It gets the object or returns 404 if it doesn’t exist. It then deletes the file from S3, and finally deletes the object from our database.
- Parameters:
-
-
request – Get the user and the file_id parameter is used to get a specific file
-
file_id – Get the file object from the database
-
- Returns:
-
A redirect to the list view
- Doc-author:
-
Trelent
- s3_storage.views.download_file(request, file_id)[source]
-
The download_file function is used to download a file from the server. It takes in a request and file_id, and returns an HttpResponse object with the content of the file.
- Parameters:
-
-
request – Get the user from the request object
-
file_id – Get the file object from the database
-
- Returns:
-
The file object as a response
- Doc-author:
-
Trelent
- s3_storage.views.edit_category(request, category_id)[source]
-
The edit_category function is used to edit the name of a category. It takes in a request and category_id as parameters, and returns an HttpResponse object. The function first gets the FileCategory object with id=category_id, or raises 404 if it doesn’t exist. If the request method is POST, then we set the name of that FileCategory to be whatever was submitted in POST["name"], save it, and redirect back to s3_storage:category_list (the list view). If not POST (i.e., GET), then we render out s3_storage/category_edit.html
- Parameters:
-
-
request – Get the current user
-
category_id – Get the category object from the database
-
- Returns:
-
The category_edit
- Doc-author:
-
Trelent
- s3_storage.views.edit_file(request, file_id)[source]
-
The edit_file function is used to edit a file. It takes in the request and the file_id of the file that needs to be edited. The function then gets the object or returns a 404 error if it does not exist. If there is an HTTP POST method, then we create a form with all of our data from our post request and instance=file (the current version). We save this form if it’s valid, otherwise we return an error message saying that something went wrong with saving your changes. Otherwise, we just create a new FileForm instance.
- Parameters:
-
-
request – Get the request from the user
-
file_id – Get the file object from the database
-
- Returns:
-
A render function
- Doc-author:
-
Trelent
- s3_storage.views.file_list(request)[source]
-
The file_list function is a view that returns an HTML page with the list of files and categories for the current user. The file_list function takes in one parameter, request, which is a HttpRequest object. The file_list function returns an HttpResponse object containing the rendered template s3_storage/file_list.html.
- Parameters:
-
request – Get the current user
- Returns:
-
A list of the files that are uploaded to the s3 bucket
- Doc-author:
-
Trelent
- s3_storage.views.profile(request)[source]
-
The profile function is used to render the profile.html template, which is a page that allows users to view and edit their profiles.
- Parameters:
-
request – Get the request object
- Returns:
-
The profile
- Doc-author:
-
Trelent
- s3_storage.views.profile_settings(request)[source]
-
The profile_settings function is a view that allows the user to update their profile. The function first checks if the user has a profile, and if not, creates one for them. If the request method is POST (i.e., they are submitting an updated form), then it saves the new information in their profile and redirects them back to this page with a success message.
- Parameters:
-
request – Get the user information
- Returns:
-
The profile_settings
- Doc-author:
-
Trelent
- s3_storage.views.upload_file(request)[source]
-
The upload_file function is responsible for handling the file upload process. It first checks if the request method is POST, which means that a form has been submitted. If it’s not POST, then we render the file_upload template with all of our categories in it. If it’s POST, then we get our category from the form and create a new File object with all of its attributes.
- Parameters:
-
request – Get the file from the form
- Returns:
-
A redirect to the list view
- Doc-author:
-
Trelent