else:
            return _('None')

    project__name.short_description = _('Project')
    project__name.admin_order_field = 'project__name'

    def project__organization__name(self, obj):
        if obj.project and obj.project.organization:
            return obj.project.organization.name
        else:
            return _('None')

    project__organization__name.short_description = _('Organization')
    project__organization__name.project__organization__name = 'project__organization__name'

    def project__address(self, obj):
        if obj.project:
            return obj.project.address
        else:
            return _('None')

    project__address.short_description = _('Address')
    project__address.admin_order_field = 'project__address'

    def get_queryset(self, request):
        qs = super(ApplyAdmin, self).get_queryset(request)
        return self.filter_by_country(request, qs, 'project__address')


admin_site.register(Apply, ApplyAdmin)
from django import forms
from django.utils.translation import ugettext_lazy as _

from ovp.apps.channels.admin import admin_site
from ovp.apps.channels.admin import ChannelModelAdmin
from ovp.apps.channels.admin import TabularInline
from ovp.apps.projects.models import JobDate


class JobDateInline(TabularInline):
  model = JobDate
  exclude = ['channel']
  fields = ['name', 'start_date', 'end_date']
  verbose_name = _('Job Date')
  verbose_name_plural = _('Job Dates')


class JobDateAdmin(ChannelModelAdmin):
  list_display = ['id', 'start_date', 'end_date']
  raw_id_fields = ['job']
  exclude = ['channel']


admin_site.register(JobDate, JobDateAdmin)
Ejemplo n.º 3
0
from django import forms

from ovp.apps.channels.admin import admin_site
from ovp.apps.channels.admin import ChannelModelAdmin
from ovp.apps.faq.models import Faq


class FaqAdmin(ChannelModelAdmin):
    list_display = ['id', 'question']
    fields = ['category', 'question', 'answer']
    search_fields = ['question']


admin_site.register(Faq, FaqAdmin)
Ejemplo n.º 4
0
class UserAdmin(ImportExportModelAdmin, ChannelModelAdmin,
                ForeignKeyAutocompleteAdmin):
    fields = [('id', 'name', 'email'), 'slug', 'phone', 'password',
              (
                  'is_staff',
                  'is_superuser',
                  'is_active',
                  'is_email_verified',
                  'public',
              ), 'groups']

    resource_class = UserResource

    list_display = [
        'id', 'email', 'name', 'last_login', 'is_active', 'is_staff',
        'is_email_verified'
    ]

    list_filter = ['is_active', 'is_staff', ('joined_date', DateRangeFilter)]

    list_editable = ['is_active', 'is_staff', 'is_email_verified']

    search_fields = ['email', 'name']

    readonly_fields = ['id']
    raw_id_fields = []


admin_site.register(User, UserAdmin)
from django import forms
from django.utils.translation import ugettext_lazy as _

from ovp.apps.channels.admin import admin_site
from ovp.apps.channels.admin import ChannelModelAdmin
from ovp.apps.channels.admin import TabularInline
from ovp.apps.core.models import Skill


class SkillInline(TabularInline):
    model = Skill


class SkillAdmin(ChannelModelAdmin):
    fields = ['id', 'name', 'slug']

    list_display = ['id', 'name']

    list_filter = []

    list_editable = ['name']

    search_fields = ['id', 'name']

    readonly_fields = ['id']

    raw_id_fields = []


admin_site.register(Skill, SkillAdmin)
Ejemplo n.º 6
0
from ovp.apps.projects.models import Work


class WorkAdmin(ChannelModelAdmin):
    fields = [
        ('id', 'project'),
        'weekly_hours',
        'description',
        'can_be_done_remotely',
    ]

    list_display = ['id', 'project', 'weekly_hours', 'can_be_done_remotely']

    list_filter = []

    list_editable = ['can_be_done_remotely']

    search_fields = ['project__name', 'project__organization__name']

    readonly_fields = ['id']

    raw_id_fields = []


class WorkInline(TabularInline):
    model = Work
    exclude = ['channel']


admin_site.register(Work, WorkAdmin)
Ejemplo n.º 7
0
from django import forms
from django.utils.translation import ugettext_lazy as _

from ovp.apps.channels.admin import admin_site
from ovp.apps.channels.admin import ChannelModelAdmin
from ovp.apps.projects.models.category import Category

class CategoryAdmin(ChannelModelAdmin):
  list_display = ['id', 'name']
  fields = ["name", "slug", "description", "image", "highlighted"]

admin_site.register(Category, CategoryAdmin)
Ejemplo n.º 8
0
class PostAdmin(ChannelModelAdmin):
    fields = [
        'id', 'user', 'gallery', ('published', 'deleted'), 'content',
        ('created_date', 'modified_date', 'deleted_date')
    ]

    list_display = ['id', 'post', 'title', 'published', 'deleted']

    list_filter = []

    list_editable = []

    search_fields = ['id', 'content']

    readonly_fields = ['id', 'created_date', 'modified_date', 'deleted_date']

    raw_id_fields = []

    formfield_overrides = {
        models.TextField: {
            'widget': AdminMartorWidget
        },
    }

    def post(self, obj):
        return obj.__str__()


admin_site.register(Post, PostAdmin)
from django import forms
from django.utils.translation import ugettext_lazy as _

from ovp.apps.channels.admin import admin_site
from ovp.apps.channels.admin import ChannelModelAdmin
from ovp.apps.channels.admin import TabularInline
from ovp.apps.core.models import Cause


class CauseInline(TabularInline):
    model = Cause


class CauseAdmin(ChannelModelAdmin):
    fields = ['id', 'name', 'image', 'slug']

    list_display = ['id', 'name']

    list_filter = []

    list_editable = ['name']

    search_fields = ['id', 'name']

    readonly_fields = ['id']

    raw_id_fields = []


admin_site.register(Cause, CauseAdmin)
    fields = ['id', 'typed_address', 'typed_address2']

    list_display = ['id', 'typed_address', 'typed_address2']

    list_filter = []

    list_editable = []

    search_fields = ['typed_address', 'typed_address2', 'address_line']

    readonly_fields = ['id']

    raw_id_fields = []


admin_site.register(GoogleAddress, GoogleAddressAdmin)


class SimpleAddressAdmin(ChannelModelAdmin):
    fields = [
        'id', 'zipcode', 'street', 'number', 'supplement', 'neighbourhood',
        'city', 'state'
    ]

    list_display = ['id', 'street', 'city']

    list_filter = []

    list_editable = []

    search_fields = ['street', 'city']
    fields = ["name", "slug", "catalogue", "amount", "type"]
    list_display = ["name", "slug", "catalogue"]
    search_fields = [
        "id", "name", "slug", "catalogue__name", "catalogue__slug"
    ]
    inlines = [SectionFilterInline]


class SectionFilterAdmin(FilterObjectMixin, ChannelModelAdmin):
    fields = ["section", "type", "filter_object", "filter_information"]
    list_display = ["section", "type"]
    readonly_fields = ["filter_object", "filter_information"]
    search_fields = []


admin_site.register(Catalogue, CatalogueAdmin)
admin_site.register(Section, SectionAdmin)
admin_site.register(SectionFilter, SectionFilterAdmin)


##################################
# Filters admin                  #
##################################
class CategoryFilterAdmin(ChannelModelAdmin):
    fields = ["categories"]

    def get_model_perms(self, request):
        return {'change': False, 'add': False, 'delete': False}


class DateDeltaFilterAdmin(ChannelModelAdmin):
        model = Lead
        fields = ('name', 'email', 'phone', 'city', 'type', 'employee_number')


class LeadAdmin(ImportExportModelAdmin, ChannelModelAdmin):
    fields = ['id', 'name', 'email', 'phone', 'type', 'employee_number']
    list_display = ['id', 'name', 'email', 'phone', 'type']
    list_filter = []
    list_editable = ['name']
    search_fields = ['id', 'name', 'email', 'phone', 'type']
    readonly_fields = ['id']
    raw_id_fields = []

    resource_class = LeadResource

    actions = [export_all_as_csv]

    def changelist_view(self, request, extra_context=None):
        if 'action' in request.POST and request.POST[
                'action'] == 'export_all_as_csv':
            # Make a list with all ids to make a 'export all'
            if not request.POST.getlist(admin.ACTION_CHECKBOX_NAME):
                post = request.POST.copy()
                for u in Lead.objects.all():
                    post.update({admin.ACTION_CHECKBOX_NAME: str(u.id)})
                request._set_post(post)
        return super(LeadAdmin, self).changelist_view(request, extra_context)


admin_site.register(Lead, LeadAdmin)

class JobInline(TabularInline):
    exclude = ['title', 'channel', 'can_be_done_remotely']
    readonly_fields = ['admin_link', 'start_date', 'end_date']
    model = Job
    verbose_name = _('Job')
    verbose_name_plural = _('Job')

    def admin_link(self, instance):
        url = reverse('admin:%s_%s_change' %
                      (instance._meta.app_label, instance._meta.model_name),
                      args=(instance.id, ))
        return format_html('<a href="{}">Edit</a>', url)


class JobAdmin(ChannelModelAdmin, CountryFilterMixin):
    list_display = ['id', 'project', 'start_date', 'end_date']
    search_fields = ['id', 'project__name', 'project__nonprofit__name']
    exclude = ['channel']
    readonly_fields = ['start_date', 'end_date']

    inlines = (JobDateInline, )

    def get_queryset(self, request):
        qs = super(JobAdmin, self).get_queryset(request)
        return self.filter_by_country(request, qs, 'project__address')


admin_site.register(Job, JobAdmin)
from ovp.apps.channels.admin import admin_site
from ovp.apps.items.models import Item, ItemImage, ItemDocument

admin_site.register(Item)
admin_site.register(ItemImage)
admin_site.register(ItemDocument)
    owner__email.short_description = _('Owner email')
    owner__email.admin_order_field = 'owner__email'

    def owner__phone(self, obj):
        return obj.owner and obj.owner.phone or _('Owner not assigned')

    owner__phone.short_description = _('Owner phone')
    owner__phone.admin_order_field = 'owner__phone'

    def get_queryset(self, request):
        qs = super(ProjectAdmin, self).get_queryset(request)
        return self.filter_by_country(request, qs, 'address')

    def city_state(self, obj):
        if isinstance(obj.address, GoogleAddress):
            return obj.address.city_state
        else:
            return ""

    def volunteers__list(self, obj):
        site_url = os.environ.get('ADMIN_URL', None)
        if site_url:
            return format_html("<a href='" + site_url +
                               "admin/projects/apply/?q=" + obj.name +
                               "' target='__blank'>Lista de Voluntários</a>")

        return ""


admin_site.register(Project, ProjectAdmin)

class UploadedDocumentAdmin(ChannelModelAdmin):
  fields = [
    'id',  'uuid', 'document', 'user', ('created_date', 'modified_date')
  ]

  list_display = [
    'id', 'uuid', 'user'
  ]

  list_filter = []

  list_editable = []

  search_fields = [
    'id', 'user__name', 'user__email'
  ]

  readonly_fields = [
    'id', 'uuid', 'created_date', 'modified_date'
  ]

  raw_id_fields = [
    'user'
  ]


admin_site.register(UploadedDocument, UploadedDocumentAdmin)
admin_site.register(UploadedImage, UploadedImageAdmin)
Ejemplo n.º 17
0
class GalleryAdmin(ChannelModelAdmin):
    fields = [
        'id', 'uuid', 'name', 'description', 'owner', 'images',
        ('created_date', 'modified_date')
    ]

    list_display = ['id', 'uuid', 'name']

    list_filter = []

    list_editable = []

    search_fields = ['id', 'content']

    readonly_fields = ['id', 'uuid', 'created_date', 'modified_date']

    raw_id_fields = []

    formfield_overrides = {
        models.TextField: {
            'widget': AdminMartorWidget
        },
    }

    def post(self, obj):
        return obj.__str__()


admin_site.register(Gallery, GalleryAdmin)
  def owner__phone(self, obj): #pragma: no cover
    if obj.owner:
      return obj.owner.phone
    else:
      return _('None')
  owner__phone.short_description = _("Owner's Phone")
  owner__phone.admin_order_field = 'owner__phone'

  def volunteers(self, obj):
    project = Project.objects.filter(organization=obj)
    total = 0
    for p in project:
      total += p.applied_count

    return total

  def city_state(self, obj):
    if obj.address is not None:
      if isinstance(obj.address, GoogleAddress):
        return obj.address.city_state
      if isinstance(obj.address, SimpleAddress):
        return obj.address.city

  def get_queryset(self, request): #pragma: no cover
    qs = super(OrganizationAdmin, self).get_queryset(request)
    return self.filter_by_country(request, qs, 'address')


admin_site.register(Organization, OrganizationAdmin)