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
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()]
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)
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
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
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)
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)
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)
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)
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())
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