Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.82 KB | None | 0 0
  1. from django import forms
  2. from django.conf import settings
  3. from django.contrib import admin
  4. from django.contrib.auth.admin import sensitive_post_parameters_m
  5. from django.core.exceptions import PermissionDenied
  6. from django.db import transaction, router
  7. from django.http import Http404
  8. from django.utils.html import format_html
  9. from django.utils.translation import ugettext_lazy as _
  10. from django_common.admin import csrf_protect_m
  11. from tabbed_admin import TabbedModelAdmin
  12.  
  13. from hogapage.hp_global.company.admin.company_user import CompanyUserInline
  14. from hogapage.hp_global.company.admin.company_office import CompanyOfficeInline
  15. from hogapage.hp_global.company.models import Company
  16. from hogapage.hp_global.email.email.employer.company_login_credentials import send_company_login_credentials_email
  17.  
  18.  
  19. def send_creation_email(modeladmin, request, queryset):
  20.     company = queryset[0]
  21.     send_company_login_credentials_email(user_id=company.users.first().id)
  22.  
  23.  
  24. send_creation_email.short_description = _("Sende Mail: Ihre Firma wurde erstellt")
  25.  
  26. class StupidForm(forms.ModelForm):
  27.     text = forms.CharField(label='Test')
  28.  
  29.     class Meta:
  30.         model = Company
  31.         fields = ("title",)
  32.         field_classes = {'title': forms.CharField}
  33.  
  34.         def __init__(self, *args, **kwargs):
  35.             super(StupidForm, self).__init__(*args, **kwargs)
  36.  
  37. @admin.register(Company)
  38. class CompanyAdmin(TabbedModelAdmin):
  39.     search_fields = ('title', 'typo3_uid')
  40.     list_display = ('image_tag', 'title', 'location', 'created', 'company_offices_count', 'active_job_offers')
  41.     raw_id_fields = ('location', 'category',)
  42.  
  43.     readonly_fields = ('created', 'modified')
  44.     actions = [send_creation_email]
  45.     add_form = StupidForm
  46.  
  47.     def get_tabs(self, request, obj=None):
  48.         if not obj:
  49.             return self.add_tabs
  50.         else:
  51.             return self.tabs
  52.  
  53.     def get_form(self, request, obj=None, **kwargs):
  54.         """
  55.        Use special form during user creation
  56.        """
  57.         defaults = {}
  58.         if obj is None:
  59.             print("asdfasdf")
  60.             defaults['form'] = self.add_form
  61.         defaults.update(kwargs)
  62.         return super(CompanyAdmin, self).get_form(request, obj, **defaults)
  63.  
  64.     add_tabs = [
  65.         ('Firma', (
  66.             (None, {
  67.                 'fields': ('title',),
  68.             }),
  69.         )),
  70.     ]
  71.  
  72.     tabs = [
  73.         ('Firma', (
  74.             (None, {
  75.                 'fields': ('title', 'slug', 'vat_number', 'legal_representative'),
  76.             }),
  77.         )),
  78.         ('Kontingent', (
  79.             (None, {
  80.                 'fields': ('contingent', 'contingent_valid_until',),
  81.             }),
  82.         )),
  83.         ('Kontaktdaten', (
  84.             (None, {
  85.                 'fields': ('location', 'email', 'phone', 'website', 'hide_contact_address'),
  86.             }),
  87.         )),
  88.         ('Kategoriesierung', (
  89.             (None, {
  90.                 'fields': ('category',),
  91.             }),
  92.         )),
  93.         ('Ansprechpartner', (
  94.             (None, {
  95.                 'fields': ('contact_gender', 'contact_first_name', 'contact_last_name', 'contact_email', 'contact_phone', 'contact_mobile',),
  96.             }),
  97.         )),
  98.         ('Firmenprofil', (
  99.             (None, {
  100.                 'fields': ('description', 'logo',),
  101.             }),
  102.         )),
  103.         ('Sonstiges', (
  104.             (None, {
  105.                 'fields': ('is_agency', 'typo3_uid', 'created', 'modified', 'is_public', 'is_buhl_company',),
  106.             }),
  107.         )),
  108.         ('Filialen', (
  109.            (CompanyOfficeInline),
  110.         )),
  111.         ('Benutzer', (
  112.            (CompanyUserInline),
  113.         )),
  114.     ]
  115.  
  116.     def image_tag(self, obj):
  117.         if obj.logo:
  118.             return format_html('<img width="100" src="{}" />'.format(obj.logo.url))
  119.  
  120.     image_tag.short_description = 'Image'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement