def show_current_meet(self, obj): from request_provider.signals import get_request request = get_request() test = request.session.get('meet') if not test or test['id'] != obj.id: return False return True
def failed_login(self, credentials, **kwargs): request = get_request() username = request.POST.get('username', 'Undefined') self.logger.instance.addFilter( ll_logger.ContextFilter(request, overrides={'user':username}) ) msg = 'User({0}) failed login'.format(username) self.logger.info(self.logger.to_request('Login.fail', msg))
def get_company(): request = get_request() if not request: return None user = request.user company = None if not user.is_anonymous(): company = user.company return company
def delete_spareparts_logs(sender, instance, **kwargs): request = get_request() table_name_logs = '%s' % sender action_type_logs = 'delete' record_id_logs = instance.id modified_by_logs = request.user modified_time_logs = timezone.now() log_add = SparepartsLog(table_name=table_name_logs, action_type=action_type_logs, record_id=record_id_logs, modified_by=modified_by_logs, modified_time=modified_time_logs) log_add.save() pass
def add_creator_permissions(sender, instance, **kwargs): try: instance_name = instance.__class__.__name__.lower() if isinstance(instance, User): user = instance elif isinstance(instance, UserProfile): user=instance.user else: user = get_request().user if instance_name in PERMISSION_MODELS: for perm in PERMISSIONS: assign_perm('{0}_{1}'.format(perm, instance_name), user, instance) except: pass
def add_creator_permissions(sender, instance, **kwargs): try: instance_name = instance.__class__.__name__.lower() if isinstance(instance, User): user = instance elif isinstance(instance, UserProfile): user = instance.user else: user = get_request().user if instance_name in PERMISSION_MODELS: for perm in PERMISSIONS: assign_perm('{0}_{1}'.format(perm, instance_name), user, instance) except: log.debug("Cannot generate perms. This is probably okay.")
def get_tenant_from_request(request=None): """ Gets the tenant for the user in the request. If we're not in a web request, or the user doesn't have a tenant defined, returns None. """ request = request or get_request() if request: tenant_model = get_tenant_model() user_id_field = "%s__id" % tenant_model._get_auth_user_field_name() # Query for a tenant who has the user defined in the request's session tenant_qs = tenant_model._tenant_manager.filter(**{user_id_field: request.session.get("_auth_user_id")}) num_tenants = tenant_qs.count() if num_tenants == 1: return tenant_qs.get()
def add_creator_permissions(sender, instance, **kwargs): try: instance_name = instance.__class__.__name__.lower() log.debug(instance_name) if instance_name == "user": user = instance elif instance_name == "userprofile": user = instance.user else: user = get_request().user if instance_name in PERMISSION_MODELS: for perm in PERMISSIONS: assign_perm("{0}_{1}".format(perm, instance_name), user, instance) except: pass
def add_creator_permissions(sender, instance, **kwargs): try: instance_name = instance.__class__.__name__.lower() if instance_name == "user": user = instance elif instance_name == "userprofile": user = instance.user else: user = get_request().user if instance_name in PERMISSION_MODELS: for perm in PERMISSIONS: assign_perm('{0}_{1}'.format(perm, instance_name), user, instance) except: pass
def post_save(sender, instance, created, *args, **kwargs): if created: message_context = Context({ 'question': instance, 'site': Site.objects.get_current(get_request()) }) text_message_template = get_template('question_email.txt') text_message = text_message_template.render(message_context) html_message_template = get_template('question_email.html') html_message = html_message_template.render(message_context) send_mail(u'Вопрос требующий ответа (№ %d)' % instance.id, text_message, settings.EMAIL_ADDRESS_FROM, EmailRecipient.objects.filter(email_type=EmailTypesEnum.QUESTION).values_list('recipient_email', flat=True), html_message=html_message )
def post_save(sender, instance, created, *args, **kwargs): if created: message_context = Context({ 'visit': instance, 'site': Site.objects.get_current(get_request()) }) text_message_template = get_template('visit_email.txt') text_message = text_message_template.render(message_context) html_message_template = get_template('visit_email.html') html_message = html_message_template.render(message_context) send_mail(u'Online запись на %s в %s (№ %d)' % (instance.visit_date.strftime('%Y.%m.%d'), instance.visit_time.strftime('%H:%M'), instance.id), text_message, settings.EMAIL_ADDRESS_FROM, EmailRecipient.objects.filter(email_type=EmailTypesEnum.VISIT).values_list('recipient_email', flat=True), html_message=html_message )
def post_save(sender, instance, created, *args, **kwargs): if created: message_context = Context({ 'callback': instance, 'site': Site.objects.get_current(get_request()) }) text_message_template = get_template('callback_email.txt') text_message = text_message_template.render(message_context) html_message_template = get_template('callback_email.html') html_message = html_message_template.render(message_context) send_mail(u'Перезвоните %s в %s (№ %d)' % (instance.get_callback_delta(), instance.callback_time.strftime('%Y.%m.%d %H:%M'), instance.id), text_message, settings.EMAIL_ADDRESS_FROM, EmailRecipient.objects.filter(email_type=EmailTypesEnum.CALLBACK).values_list('recipient_email', flat=True), html_message=html_message )
def add_basic_info_logs(sender, instance, created, **kwargs): request = get_request() table_name_logs = '%s' % sender if created: action_type_logs = 'insert' else: action_type_logs = 'update' record_id_logs = instance.id modified_by_logs = request.user modified_time_logs = timezone.now() log_add = BasicInfoLog(table_name=table_name_logs, action_type=action_type_logs, record_id=record_id_logs, modified_by=modified_by_logs, modified_time=modified_time_logs) log_add.save() pass
def post_save(sender, instance, created, *args, **kwargs): if created: message_context = Context({ 'question': instance, 'site': Site.objects.get_current(get_request()) }) text_message_template = get_template('question_email.txt') text_message = text_message_template.render(message_context) html_message_template = get_template('question_email.html') html_message = html_message_template.render(message_context) send_mail(u'Вопрос требующий ответа (№ %d)' % instance.id, text_message, settings.EMAIL_ADDRESS_FROM, EmailRecipient.objects.filter( email_type=EmailTypesEnum.QUESTION).values_list( 'recipient_email', flat=True), html_message=html_message)
def post_save(sender, instance, created, *args, **kwargs): if created: message_context = Context({ 'visit': instance, 'site': Site.objects.get_current(get_request()) }) text_message_template = get_template('visit_email.txt') text_message = text_message_template.render(message_context) html_message_template = get_template('visit_email.html') html_message = html_message_template.render(message_context) send_mail(u'Online запись на %s в %s (№ %d)' % (instance.visit_date.strftime('%Y.%m.%d'), instance.visit_time.strftime('%H:%M'), instance.id), text_message, settings.EMAIL_ADDRESS_FROM, EmailRecipient.objects.filter( email_type=EmailTypesEnum.VISIT).values_list( 'recipient_email', flat=True), html_message=html_message)
def post_save(sender, instance, created, *args, **kwargs): if created: message_context = Context({ 'callback': instance, 'site': Site.objects.get_current(get_request()) }) text_message_template = get_template('callback_email.txt') text_message = text_message_template.render(message_context) html_message_template = get_template('callback_email.html') html_message = html_message_template.render(message_context) send_mail(u'Перезвоните %s в %s (№ %d)' % (instance.get_callback_delta(), instance.callback_time.strftime('%Y.%m.%d %H:%M'), instance.id), text_message, settings.EMAIL_ADDRESS_FROM, EmailRecipient.objects.filter( email_type=EmailTypesEnum.CALLBACK).values_list( 'recipient_email', flat=True), html_message=html_message)
def display_succes_message_disconnect(backend, *args, **kwargs): if backend.name == "mediawiki": request = get_request() messages.success(request, _('Your wikimedia account is no longer linked.'))
def display_succes_message_link(backend, *args, **kwargs): if backend.name == "mediawiki" and kwargs['new_association']: request = get_request() messages.success(request, _('Successfully linked your wikimedia account!'))
def get_user(): request = get_request() if not request: return None return request.user
def __init__(self, *args, **kwargs): super(CustomCommentForm, self).__init__(*args, **kwargs) if not get_request().user.is_authenticated(): self.fields['captcha'] = ReCaptchaField(widget=ReCaptchaWidget())