def __init__(self, *args, **kwargs): super(AudioFile, self).__init__(*args, **kwargs) #allows the override of anything that follows the _attrname caching pattern for attr in dir(self): if attr in kwargs: setattr(self, '_' + attr, kwargs[attr]) self.backend = \ GenericBackend('ARMSTRONG_EXTERNAL_AUDIO_METADATA_BACKEND')\ .get_backend()
data.update({ "amount": donation.amount, "description": description, "first_name": unicode(donor.first_name), "last_name": unicode(donor.last_name), # TODO: extract and be conditional "address": donor.address.address, "city": donor.address.city, "state": donor.address.state, "zip": donor.address.zipcode, }) if self.testing: data["test_request"] = u"TRUE" response = api.transaction(**data) status = response["reason_code"] == u"1" return { "status": status, "reason": response["reason_text"], "response": response, } raw_backend = GenericBackend( "ARMSTRONG_DONATIONS_BACKEND", defaults=[ "armstrong.apps.donations.backends.AuthorizeNetBackend", ]) get_backend = raw_backend.get_backend
def get_context_data(self, recipient, recipient_list): context_backend = GenericBackend('TT_DAILYEMAILBLAST_CONTEXT', defaults=['tt_dailyemailblast.context_backends.basic']) return context_backend.get_backend(self, recipient, recipient_list)
from armstrong.utils.backends import GenericBackend RICH_TEXT_BACKEND = GenericBackend( 'ARMSTRONG_HATBAND_RICHTEXTEDITOR', defaults="armstrong.hatband.widgets.ckeditor.CKEditorWidget") #RichTextWidget = RICH_TEXT_BACKEND.get_backend class RichTextWidget(object): def __new__(cls, *args, **kwargs): return RICH_TEXT_BACKEND.get_backend(*args, **kwargs)
from django.conf import settings from django.db import models from mptt.models import MPTTModel from mptt.fields import TreeForeignKey from armstrong.utils.backends import GenericBackend SECTION_ITEM_BACKEND = GenericBackend('ARMSTRONG_SECTION_ITEM_BACKEND', defaults="armstrong.core.arm_sections.backends.find_related_models")\ .get_backend class SectionManager(models.Manager): def get(self, **kwargs): defaults = {} defaults.update(kwargs) if 'full_slug' in defaults: if defaults['full_slug'] and defaults['full_slug'][-1] != "/": defaults['full_slug'] += "/" return super(SectionManager, self).get(**defaults) class Section(MPTTModel): title = models.CharField(max_length=255) summary = models.TextField(default="", blank=True) slug = models.SlugField() full_slug = models.CharField(max_length=255, blank=True) parent = TreeForeignKey('self', null=True, blank=True) objects = SectionManager()
import warnings import django from django.db import models from django.core.exceptions import ImproperlyConfigured from mptt.models import MPTTModel from mptt.managers import TreeManager from mptt.fields import TreeForeignKey from armstrong.utils.backends import GenericBackend from .utils import get_section_many_to_many_relations __BACKEND_MODULE = "armstrong.core.arm_sections.backends.%s" SECTION_ITEM_BACKEND = GenericBackend('ARMSTRONG_SECTION_ITEM_BACKEND', defaults=__BACKEND_MODULE % "ItemFilter").get_backend() SECTION_PUBLISHED_BACKEND = GenericBackend( 'ARMSTRONG_SECTION_PUBLISHED_BACKEND', defaults=__BACKEND_MODULE % "PublishedItemFilter").get_backend() class SectionManager(models.Manager): def get_queryset(self): # DROP_WITH_DJANGO15 """Use the same ordering as TreeManager""" args = (self.model._mptt_meta.tree_id_attr, self.model._mptt_meta.left_attr) method = 'get_query_set' if django.VERSION < (1, 6) else 'get_queryset' return getattr(super(SectionManager, self), method)().order_by(*args) # DEPRECATED: To be removed in ArmSections 2.0 for Django 1.6+ def get_query_set(self): # pragma: no cover
class AudioFile(FieldFile): """ A mixin for use alongside django.core.files.base.File, which provides additional features for dealing with audio files. """ def __init__(self, *args, **kwargs): super(AudioFile, self).__init__(*args, **kwargs) #allows the override of anything that follows the _attrname caching pattern for attr in dir(self): if attr in kwargs: setattr(self, '_' + attr, kwargs[attr]) self.backend = \ GenericBackend('ARMSTRONG_EXTERNAL_AUDIO_METADATA_BACKEND')\ .get_backend() def _transcode(self, toformat): """ returns a transcoded file perhaps should do more complex and different things like transcode via zencoder """ raise NotImplementedError def render(self, *args, **kwargs): audio_player_template = get_template('audio/player.html') return audio_player_template.render( Context( {'url': self.url, 'filetype': self.filetype, 'name': self.metadata['title'], 'fileno': str(self.fileno()) } ) ) @property def filetype(self): """ get the encoding of the file """ if not hasattr(self, '_filetype'): self._filetype = self.backend.filetype(self.file) return self._filetype @property def playtime(self): """ get the playtime of the file """ if not hasattr(self, '_playtime'): self._playtime = self.backend.playtime(self.file) return self._playtime @property def bitrate(self): """ get the bit rate """ if not hasattr(self, '_bitrate'): self._bitrate = self.backend.bitrate(self.file) return self._bitrate @property def metadata(self): """ get the all metadata as a dictionary """ if not hasattr(self, '_metadata'): self._metadata = self.backend.metadata(self.file) return self._metadata
import pkg_resources pkg_resources.declare_namespace(__name__) from armstrong.utils.backends import GenericBackend from django.conf import settings as default_settings from django.utils.importlib import import_module from .youtube import YouTubeBackend from .vimeo import VimeoBackend backend = GenericBackend("ARMSTRONG_EXTERNAL_VIDEO_BACKEND") get_backend = backend.get_backend