예제 #1
0
 def get_queryset(self):
     queryset = super().get_queryset()
     if get_current_request() and (
             get_current_request().user.is_anonymous()
             or not get_current_request().user.is_supreme):
         queryset = queryset.filter(
             group=get_current_request().tenant.group)
     return queryset
예제 #2
0
def choice():
    request = get_current_request()
    if is_github_remote_enabled(request):
        return [
            (file.name, file.name)
            for file in get_github_repo(request).get_dir_contents('/')
            if file.name.endswith(".html") or file.name.endswith(".template")
        ]
    else:
        request = get_current_request()

        return [(template.id, template.slug)
                for template in Template.objects.filter(
                    owner__groups__in=request.user.groups.all()).all()]
예제 #3
0
def get_mailchimp_api():
    request = get_current_request()
    try:
        default_key = get_mailchimp_key(request)
    except MailChimpCredential.DoesNotExist:
        raise Exception(_("Check if your API key present."))
    return mailchimp.Mailchimp(default_key)
예제 #4
0
def get_mailchimp_api():
    request = get_current_request()
    try:
        default_key = get_mailchimp_key(request)
    except MailChimpCredential.DoesNotExist:
        raise Exception(_("Check if your API key present."))
    return mailchimp.Mailchimp(default_key)
예제 #5
0
def retrieve_template(template_id):
    request = get_current_request()
    if is_github_remote_enabled(request):
        template_slug = template_id
        variables = json.loads(
            get_github_repo(request).get_file_contents('/' + template_slug + '.defaults').decoded_content.decode())
    else:
        template_db = Template.objects.get(pk=int(template_id))
        template_slug = template_db.slug

        variables = {var["name"]: var["initial"] for var in parse_vars(template_db.variables)}

    engine = DjangoTemplates(
            {
                'NAME': 'mail',
                'APP_DIRS': False,
                'DIRS': [],
                'OPTIONS': {
                    'loaders': [
                        'events.loaders.MyLoader',
                    ],
                },
            })
    template = engine.get_template(template_slug)
    return template, variables
예제 #6
0
파일: admin.py 프로젝트: itkpi/itkpimail
    def save(self, commit=True):
        user = super().save(commit)

        request = get_current_request()
        if not request.user.is_supreme:  # supreme user can choose group after creation
            # ignore commit value to add groups
            user.save()
            for group in request.user.groups.all():
                user.groups.add(group)
            user.save()

        return user
예제 #7
0
    def save(self, commit=True):
        user = super().save(commit)

        request = get_current_request()
        if not request.user.is_supreme:  # supreme user can choose group after creation
            # ignore commit value to add groups
            user.save()
            for group in request.user.groups.all():
                user.groups.add(group)
            user.save()

        return user
예제 #8
0
    def load_template_source(self, template_name, template_dirs=None):
        request = get_current_request()
        if not request:
            raise TemplateDoesNotExist(template_name)
        if template_name.startswith("admin/"):
            raise TemplateDoesNotExist(template_name)

        if is_github_remote_enabled(request):
            return self.load_template_source_from_git(request, template_name,
                                                      template_dirs)
        else:
            return self.load_template_source_from_database(
                request, template_name, template_dirs)
예제 #9
0
    def __init__(self, *args, **kwargs):
        request = get_current_request()

        if is_github_remote_enabled(request):
            kwargs["initial"] = {"template": "main.html"}
        else:
            default_template = list(
                Template.objects.filter(
                    is_default=True,
                    owner__groups__in=request.user.groups.all()))
            if default_template:
                kwargs["initial"] = {"template": default_template[0].id}

        super().__init__(*args, **kwargs)
예제 #10
0
파일: forms.py 프로젝트: itkpi/itkpimail
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.attrs = {'onsubmit': "prepareForm()"}

        fields = [
            Fieldset(
                'Blog post',
                'title',
                'content',
            ),
            Fieldset(
                'Options',
                'tags',
                'slug',
                'date_published',
            ),
            ]
        if get_current_request().user.is_staff:
            fields += [ButtonHolder(Fieldset('Staff', 'personal'),)]
        fields += [ButtonHolder(Submit('submit', 'Save'),)]
        self.helper.layout = Layout(*fields)
예제 #11
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.attrs = {'onsubmit': "prepareForm()"}

        fields = [
            Fieldset(
                'Blog post',
                'title',
                'content',
            ),
            Fieldset(
                'Options',
                'tags',
                'slug',
                'date_published',
            ),
        ]
        if get_current_request().user.is_staff:
            fields += [ButtonHolder(Fieldset('Staff', 'personal'), )]
        fields += [ButtonHolder(Submit('submit', 'Save'), )]
        self.helper.layout = Layout(*fields)
예제 #12
0
 def can_edit(self):
     if not get_current_request():
         return False
     return get_current_request().user.is_staff or \
         (self.group in get_current_request().groups.all())
예제 #13
0
 def can_edit(self):
     if not get_current_request():
         return False
     return get_current_request(
     ).user.is_staff or self.owner == get_current_request().user