Django Ditto Documentation Release 0.9.0

Django Ditto Documentation Release 0.9.0

Django Ditto Documentation Release 0.9.0 Phil Gyford Nov 03, 2018 Contents 1 Introduction 3 1.1 Services covered.............................................3 1.2 What Ditto includes...........................................4 2 Installation 5 2.1 Pillow...................................................5 2.2 Install django-ditto............................................5 2.3 Add to INSTALLED_APPS.......................................5 2.4 Add to urls.py..............................................6 2.5 Settings..................................................7 2.6 Set up each service............................................8 3 Flickr 9 3.1 Set-up...................................................9 3.2 Models.................................................. 10 3.3 Managers................................................. 10 3.4 Template tags............................................... 11 3.5 Management commands......................................... 13 4 Last.fm 17 4.1 Set-up................................................... 17 4.2 Models.................................................. 17 4.3 Managers................................................. 18 4.4 Template tags............................................... 19 4.5 Management commands......................................... 22 5 Pinboard 23 5.1 Set-up................................................... 23 5.2 Models.................................................. 23 5.3 Managers................................................. 23 5.4 Template tags............................................... 24 5.5 Management commands......................................... 25 6 Twitter 27 6.1 Set-up................................................... 27 6.2 Models.................................................. 27 6.3 Managers................................................. 28 i 6.4 Template tags............................................... 29 6.5 Management commands......................................... 31 7 Development 35 7.1 Tests................................................... 35 7.2 Other notes for development....................................... 36 ii Django Ditto Documentation, Release 0.9.0 A collection of Django apps for copying things from Flickr, Twitter and Pinboard, and displaying them on your Django site. Contents 1 Django Ditto Documentation, Release 0.9.0 2 Contents CHAPTER 1 Introduction A collection of Django apps for copying things from third-party sites and services. This is still in-progress and things may change. If something doesn’t make sense, email Phil Gyford and I’ll try and clarify it. Requires Python 3.4, 3.5 or 3.6, and Django 1.11, 2.0 or 2.1. See screenshots of a site using the supplied templates. 1.1 Services covered Currently, Ditto can copy these things from these services: • Flickr – Photos – Photosets – Original image and video files – Users • Last.fm – Scrobbles (Artist, Track and Album) • Pinboard – Bookmarks • Twitter – Tweets – Favorites/Likes – Images and Animated GIFs (but not videos) – Users 3 Django Ditto Documentation, Release 0.9.0 It can save these things for one or more account on each service. See possible future services, and overall progress, in this issue. Public and private Photos, Bookmarks and Tweets are saved, but only public ones are used in the included Views, Templates and Template tags; non-public data are only visible in the Django admin. Ditto does not sync data – it’s a one-way fetch of data from the service to Ditto. You can repeatedly fetch the same Photos, Tweets, etc and their data will be overwritten in Ditto. You could do a single fetch of all your data as a snapshot/archive. And/or, after that, keep fetching the latest items to keep it up-to-date. For each item fetched, the original JSON data is saved on its object. 1.2 What Ditto includes The Ditto apps provide: • Models • Admin • Management commands to fetch the data/files • Views and URLs • Templates (that use Bootstrap 4.1) • Template tags for common things (eg, most recent Tweets, or Flickr photos uploaded on a particular day) You could use the whole lot to create a minimal site that displays your Tweets, photos, etc – see the devproject/ for a bare-bones example. Or you might want to use the management commands, Models and Admin to fetch and store your data, but use that data in your own Views and Templates, maybe using the Template tags. Or some other combination. 4 Chapter 1. Introduction CHAPTER 2 Installation 2.1 Pillow Ditto uses Pillow which has some prerequisites of its own. You may need to install libjpeg and zlib. (On a Mac, zlib was installed for me by XCode, and I used Homebrew to install libjpeg.) 2.2 Install django-ditto Ditto can be installed using pip: $ pip install django-ditto 2.3 Add to INSTALLED_APPS To use Ditto in your own project (untested as yet), add the core ditto.core application to your project’s INSTALLED_APPS in your settings.py, and add the applications for the services you need. This example includes Flickr, Last.fm, Pinboard and Twitter: INSTALLED_APPS=( # other apps listed here. # ... 'imagekit', # Required only to use downloaded images and videos 'sortedm2m', # Required only for ditto.flickr 'taggit', # Required only for ditto.flickr and ditto.pinboard 'ditto.core', 'ditto.flickr', 'ditto.lastfm', 'ditto.pinboard', 'ditto.twitter', ) 5 Django Ditto Documentation, Release 0.9.0 If you only wanted to use the Flickr part, including displaying downloaded photos, you would do this: INSTALLED_APPS=( # other apps listed here. # ... 'imagekit', # Required only to use downloaded images and videos 'sortedm2m', # Required only for ditto.flickr 'taggit', # Required only for ditto.flickr and ditto.pinboard 'ditto.core', 'ditto.flickr', ) Or, to use only the Twitter part, and not worry about using local versions of images: INSTALLED_APPS=( # other apps listed here. # ... 'ditto.core', 'ditto.twitter', ) 2.4 Add to urls.py To use Ditto’s supplied views you can include each app’s URLs in your project’s own urls.py. Note that each app requires the correct namespace (flickr, lastfm, pinboard or twitter), eg: from django.conf.urls import include, url from django.contrib import admin urlpatterns=[ url(r'^admin/', include(admin.site.urls)), url(r'^flickr/', include('ditto.flickr.urls')), url(r'^lastfm/', include('ditto.lastfm.urls')), url(r'^pinboard/', include('ditto.pinboard.urls')), url(r'^twitter/', include('ditto.twitter.urls')), # To include the overall, aggregated views: url(r'ditto/', include('ditto.core.urls')), ] Change the URL include paths (eg, r'^ditto/pinboard/' as appropriate) to suit your project. See the urls.py in the devproject/ project for a full example. Each app’s URL conf is included under an appropriate app_name: • flickr • lastfm • pinboard • twitter • ditto (The Ditto Core URLs) 6 Chapter 2. Installation Django Ditto Documentation, Release 0.9.0 2.5 Settings There are some optional settings that can be placed in your project’s settings.py. 2.5.1 Core settings The ditto.core app has some optional settings for customing the formats used to display dates and times in the default templates (and the ditto_core.display_time() template tag). The formats are those used for strftime. Here they are, with their default values: # e.g. "07:34" DITTO_CORE_TIME_FORMAT='%H:%M' # e.g. "8 Apr 2018" DITTO_CORE_DATE_FORMAT=' %-d %b%Y' # Used when both a time and a date are displayed. # The [time] and [date] tokens are replaced with the formats from the # two settings above. # e.g. "07:34 on 8 Apr 2018" DITTO_CORE_DATETIME_FORMAT='[time] on [date]' # Used when only a year is displayed. # e.g. "2018" DITTO_CORE_DATE_YEAR_FORMAT='%Y' # Used when only a month and year are displayed. # e.g. "Apr 2018" DITTO_CORE_DATE_YEAR_MONTH_FORMAT='%b%Y' 2.5.2 Service-specific settings In addition, some of the other apps have their own optional settings. They’re described in detail in each service’s documentation. This is the complete list of service-specific settings with their default values: DITTO_FLICKR_DIR_BASE='flickr' DITTO_FLICKR_DIR_PHOTOS_FORMAT='%Y/%m/ %d' DITTO_FLICKR_USE_LOCAL_MEDIA= False DITTO_TWITTER_DIR_BASE='twitter' DITTO_TWITTER_USE_LOCAL_MEDIA= False 2.5.3 Other optional settings To have large numbers formatted nicely in the included templates, ensure these are in your settings.py: USE_L10N= True USE_THOUSAND_SEPARATOR= True 2.5. Settings 7 Django Ditto Documentation, Release 0.9.0 2.6 Set up each service Each service (such as Flickr or Twitter) you want to use will require some set-up in order to link your account(s) on the service with Django Ditto. See the documentation for each service for how to do this. 8 Chapter 2. Installation CHAPTER 3 Flickr You can fetch, store and display data about all your Photos and Photosets (Albums) for one or more Flickr Accounts. By default the included models and templates will link to the photo files on flickr.com, but you can also download the original files to store locally. These can then be used to generate images in all other sizes, to be served locally. See the Fetch Files management command below. 3.1 Set-up In the Django admin, create a new Account in the Flickr app, and add your Flickr API key and secret from https: //www.flickr.com/services/apps/create/apply/ (you can ignore the User for the moment). By default this will only allow the fetching of fully public photos. To fetch all photos your Flickr account can access, you’ll need to do this: 1. Enter your API key and secret in the indicated place in the file ditto/scripts/flickr_authorize.py. (If you’ve installed

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    40 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us