Esempio n. 1
0
 class Meta:
     verbose_name = _ug('Zip')
     verbose_name_plural = _ug('Zips')
     permissions = (
         ('query_zip', 'Query Zip'),
         ('list_zip', 'List Zip'),
     )
Esempio n. 2
0
def object_push(request, environment, pk=None):
    template_vars = dict()
    environment.load_data('', kwargs={'id': pk})
    instance = None
    if request.method == 'POST':
        new_instance, instance = push_post(request, pk, environment)
        if new_instance is not None:
            # At this point, create/update has succeeded
            if pk is not None:
                msgs.generate_msg(request, msgs.GREEN, msgs.SUCCESS,
                                  _ug('The changes have been saved.'))
            else:
                msgs.generate_msg(request, msgs.GREEN, msgs.SUCCESS,
                                  _ug('The creation was done successfully.'))
            return HttpResponseRedirect(urlresolvers.reverse(environment.redirect_urlname))
    elif request.method == 'GET':
        #Request the create/update form
        instance = push_get(request, pk, environment)

    formas = {'django_form': instance}
    return render_to_response(
        environment.template,
        formas,
        RequestContext(
            request,
            template_vars
        )
    )
Esempio n. 3
0
class URL(models.Model):
    url = models.CharField(max_length=hardcode.url_name_length,
                           blank=False,
                           null=False,
                           verbose_name=_ug('URL'))
    cached_until = models.DateTimeField(blank=True,
                                        null=True,
                                        verbose_name=_ug('Cached until'))
    utility = models.ForeignKey(utility_models.Utility,
                                related_name='url',
                                blank=False,
                                null=False,
                                verbose_name=_ug('Utility'))
    valid = models.BooleanField(default=False,
                                blank=True,
                                verbose_name=_ug('Valid'))
    hidden = models.BooleanField(default=False, blank=True)

    def __str__(self):
        return "%s" % self.url

    def delete(self, *args):
        if self.hidden is True:
            super(URL, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('URL')
        verbose_name_plural = _ug('URLs')
        permissions = (
            ('query_url', 'Query URL'),
            ('list_url', 'List URLs'),
        )
Esempio n. 4
0
class Project(models.Model):
    name = models.CharField(max_length=hardcode.project_name_length,
                            blank=False,
                            null=False,
                            verbose_name=_ug('Name'))
    description = models.CharField(
        max_length=hardcode.project_description_length,
        blank=True,
        null=True,
        verbose_name=_ug('Description'))
    parent = models.ForeignKey('Project',
                               related_name='sons',
                               blank=False,
                               null=False,
                               verbose_name=_ug('Parent'))
    hidden = models.BooleanField(default=False, blank=True)

    def __str__(self):
        return "%s" % self.name

    def delete(self, *args):
        if self.hidden is True:
            super(Project, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Project')
        verbose_name_plural = _ug('Projects')
        permissions = (
            ('query_project', 'Query Project'),
            ('list_project', 'List Projects'),
        )
Esempio n. 5
0
 class Meta:
     verbose_name = _ug('Role')
     verbose_name_plural = _ug('Roles')
     permissions = (
         ('query_role', 'Query Role'),
         ('list_role', 'List Roles'),
     )
Esempio n. 6
0
 class Meta:
     verbose_name = _ug('Political Area Utility')
     verbose_name_plural = _ug('Political Area Utilities')
     permissions = (
         ('query_politicalareautility', 'Query Political Area Utility'),
         ('list_politicalareautility', 'List Political Area Utilities'),
     )
Esempio n. 7
0
 class Meta:
     verbose_name = _ug('Company')
     verbose_name_plural = _ug('Companies')
     permissions = (
         ('query_company', 'Query Company'),
         ('list_company', 'List Companies'),
     )
Esempio n. 8
0
 class Meta:
     verbose_name = _ug('User')
     verbose_name_plural = _ug('Users')
     permissions = (
         ('query_customuser', 'Query User'),
         ('list_customuser', 'List Users'),
     )
Esempio n. 9
0
class Company(models.Model):
    name = models.CharField(max_length=hardcode.company_name_length,
                            blank=False,
                            null=False,
                            verbose_name=_ug('Name'))
    description = models.CharField(
        max_length=hardcode.company_description_length,
        blank=False,
        null=False,
        verbose_name=_ug('Description'))
    phone = models.CharField(max_length=hardcode.company_phone_length,
                             blank=False,
                             null=False,
                             verbose_name=_ug('Phone'))
    active = models.BooleanField(default=True,
                                 blank=True,
                                 verbose_name=_ug('Active'))

    def __str__(self):
        return "%s" % self.name

    def delete(self, *args):
        if self.hidden is True:
            super(Company, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Company')
        verbose_name_plural = _ug('Companies')
        permissions = (
            ('query_company', 'Query Company'),
            ('list_company', 'List Companies'),
        )
Esempio n. 10
0
 class Meta:
     verbose_name = _ug('Utility')
     verbose_name_plural = _ug('Utilities')
     permissions = (
         ('query_utility', 'Query Utility'),
         ('list_utility', 'List Utilities'),
     )
Esempio n. 11
0
 class Meta:
     verbose_name = _ug('Post')
     verbose_name_plural = _ug('Posts')
     permissions = (
         ('query_post', 'Query Post'),
         ('list_post', 'List Posts'),
     )
Esempio n. 12
0
 class Meta:
     verbose_name = _ug('Unit')
     verbose_name_plural = _ug('Units')
     permissions = (
         ('query_unit', 'Query Unit'),
         ('list_unit', 'List Units'),
     )
Esempio n. 13
0
 class Meta:
     verbose_name = _ug('Project')
     verbose_name_plural = _ug('Projects')
     permissions = (
         ('query_project', 'Query Project'),
         ('list_project', 'List Projects'),
     )
Esempio n. 14
0
File: forms.py Progetto: letops/BKi
class CustomUserSignUpForm(UserCreationForm):
    password1 = forms.CharField(label=_ug('Password'), widget=forms.PasswordInput)
    password2 = forms.CharField(label=_ug('Password confirmation'), widget=forms.PasswordInput)

    class Meta(UserCreationForm.Meta):
        model = models.CustomUser
        fields = ('username', 'email',)

    def clean_username(self):
        username = self.cleaned_data['username']
        try:
            models.CustomUser.objects.get(username=username) #FIXME: _default_manager instead of objects?
        except models.CustomUser.DoesNotExist:
            return username
        raise forms.ValidationError(_ug("A user with that username already exists."))

    def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        if not password1 or not password2 or password1 != password2:
            raise forms.ValidationError(_ug("The two password fields didn't match."))
        return password2

    def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)
        user.set_password(self.cleaned_data['password1'])
        if commit:
            user.save()
        return user
Esempio n. 15
0
 class Meta:
     verbose_name = _ug('Raw Rebate')
     verbose_name_plural = _ug('Raw Rebates')
     permissions = (
         ('query_rawrebate', 'Query Raw Rebate'),
         ('list_rawrebate', 'List Raw Rebates'),
     )
Esempio n. 16
0
 class Meta:
     verbose_name = _ug('URL Monitor')
     verbose_name_plural = _ug('URL Monitors')
     permissions = (
         ('query_urlmonitor', 'Query URL Monitor'),
         ('list_urlmonitor', 'List URL Monitors'),
     )
Esempio n. 17
0
class Unit(models.Model):
    name = models.CharField(max_length=hardcode.unit_name_length,
                            blank=False,
                            null=False,
                            verbose_name=_ug('Name'))
    description = models.CharField(max_length=hardcode.unit_description_length,
                                   blank=True,
                                   null=True,
                                   verbose_name=_ug('Description'))
    hidden = models.BooleanField(default=False, blank=True)

    def __str__(self):
        return "%s" % self.name

    def delete(self, *args):
        if self.hidden is True:
            super(Unit, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Unit')
        verbose_name_plural = _ug('Units')
        permissions = (
            ('query_unit', 'Query Unit'),
            ('list_unit', 'List Units'),
        )
Esempio n. 18
0
 class Meta:
     verbose_name = _ug('Privilege')
     verbose_name_plural = _ug('Privileges')
     permissions = (
         ('query_privilege', 'Query Privilege'),
         ('list_privilege', 'List Privileges'),
     )
Esempio n. 19
0
 class Meta:
     verbose_name = _ug('Approval')
     verbose_name_plural = _ug('Approvals')
     permissions = (
         ('query_approval', 'Query Approval'),
         ('list_approval', 'List Approvals'),
     )
Esempio n. 20
0
class Utility(models.Model):
    name = models.CharField(
        max_length=hardcode.utility_name_length,
        blank=False,
        null=False,
        verbose_name=_ug('Name')
    )
    shortname = models.CharField(
        max_length=hardcode.utility_shortname_length,
        blank=True,
        null=True,
        verbose_name=_ug('Short Name')
    )
    web = models.CharField(
        max_length=hardcode.utility_web_length,
        blank=True,
        null=True,
        verbose_name=_ug('Web')
    )
    phone = models.CharField(
        max_length=hardcode.utility_phone_length,
        blank=True,
        null=True,
        verbose_name=_ug('Phone')
    )
    utility_type = models.ForeignKey(
        UtilityType,
        related_name='utilities',
        blank=False,
        null=False,
        verbose_name=_ug('Utility Type')
    )
    hidden = models.BooleanField(
        default=False,
        blank=True
    )

    def __str__(self):
        return "%s" % self.name

    def delete(self, *args):
        if self.hidden is True:
            super(Utility, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Utility')
        verbose_name_plural = _ug('Utilities')
        permissions = (
            ('query_utility', 'Query Utility'),
            ('list_utility', 'List Utilities'),
        )
Esempio n. 21
0
File: forms.py Progetto: letops/BKi
    def clean_password2(self):
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")

        if not password1 or not password2 or password1 != password2:
            raise forms.ValidationError(_ug("The two password fields didn't match."))
        return password2
Esempio n. 22
0
File: forms.py Progetto: letops/BKi
 def clean_username(self):
     username = self.cleaned_data['username']
     try:
         models.CustomUser.objects.get(username=username) #FIXME: _default_manager instead of objects?
     except models.CustomUser.DoesNotExist:
         return username
     raise forms.ValidationError(_ug("A user with that username already exists."))
Esempio n. 23
0
File: forms.py Progetto: letops/BKi
    def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        if not password1 or not password2 or password1 != password2:
            raise forms.ValidationError(_ug("The two password fields didn't match."))
        return password2
Esempio n. 24
0
File: forms.py Progetto: letops/BKi
 def clean_username(self):
     username = self.cleaned_data["username"]
     try:
         models.CustomUser.objects.get(username=username)  # FIXME: _default_manager instead of objects?
     except models.CustomUser.DoesNotExist:
         return username
     raise forms.ValidationError(_ug("A user with that username already exists."))
Esempio n. 25
0
File: forms.py Progetto: letops/BKi
class CustomUserChangeForm(UserChangeForm):
    password = ReadOnlyPasswordHashField(label='password', help_text=_ug("Raw passwords are not stored."))

    class Meta(UserChangeForm.Meta):
        model = models.CustomUser
        fields = ('username', 'email', 'password', 'is_active', 'is_staff', 'is_superuser', 'user_permissions')

    def clean_password(self):
        return self.initial['password', ]
Esempio n. 26
0
def push_get(request, pk=None, env=None):
    instance = None
    if pk is not None and request.user.has_perm('%s.change_%s' % (env.data_model._meta.app_label, env.model.lower())):
        new_instance = env.data_model.objects.get(pk=pk)
        instance = env.serializer(instance=new_instance)
    elif pk is None and request.user.has_perm('%s.add_%s' % (env.data_model._meta.app_label, env.model.lower())):
        instance = env.serializer()
    else:
        msgs.generate_msg(request, msgs.RED, msgs.ERROR, _ug('A problem occurred. The action could not be completed.'))

    return instance
Esempio n. 27
0
class Approval(models.Model):
    rawrebate = models.ForeignKey(RawRebate,
                                  related_name='approvals',
                                  blank=False,
                                  null=False,
                                  verbose_name=_ug('Raw Rebate'))
    user = models.ForeignKey(main_models.CustomUser,
                             related_name='approvals',
                             blank=False,
                             null=False,
                             verbose_name=_ug('User'))
    approved = models.BooleanField(default=False,
                                   blank=True,
                                   verbose_name=_ug('Approved?'))
    submitted = models.BooleanField(default=False,
                                    blank=True,
                                    verbose_name=_ug('Submitted?'))
    rejected = models.BooleanField(default=False,
                                   blank=True,
                                   verbose_name=_ug('Rejected?'))
    stalled = models.BooleanField(default=False,
                                  blank=True,
                                  verbose_name=_ug('Stalled?'))
    post = models.ForeignKey(Post,
                             related_name='approvals',
                             blank=False,
                             null=False,
                             verbose_name=_ug('Post'))
    created_at = models.DateTimeField(auto_now_add=True,
                                      verbose_name=_ug('Created at'))
    hidden = models.BooleanField(default=False, blank=True)

    def __str__(self):
        return "%s - %s" % (self.name, self.rawrebate)

    def delete(self, *args):
        if self.hidden is True:
            super(Approval, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Approval')
        verbose_name_plural = _ug('Approvals')
        permissions = (
            ('query_approval', 'Query Approval'),
            ('list_approval', 'List Approvals'),
        )
Esempio n. 28
0
def object_push(request, environment, pk=None):
    template_vars = dict()
    environment.load_data('', kwargs={'id': pk})
    instance = None
    if request.method == 'POST':
        new_instance, instance = push_post(request, pk, environment)
        if new_instance is not None:
            # At this point, create/update has succeeded
            if pk is not None:
                msgs.generate_msg(request, msgs.GREEN, msgs.SUCCESS,
                                  _ug('The changes have been saved.'))
            else:
                msgs.generate_msg(request, msgs.GREEN, msgs.SUCCESS,
                                  _ug('The creation was done successfully.'))
            return HttpResponseRedirect(
                urlresolvers.reverse(environment.redirect_urlname))
    elif request.method == 'GET':
        #Request the create/update form
        instance = push_get(request, pk, environment)

    formas = {'django_form': instance}
    return render_to_response(environment.template, formas,
                              RequestContext(request, template_vars))
Esempio n. 29
0
class PoliticalAreaUtility(models.Model):
    utility = models.ForeignKey(
        Utility,
        related_name='political_area_utilities',
        blank=False,
        null=False,
        verbose_name=_ug('Utility')
    )
    political_area = models.ForeignKey(
        PoliticalArea,
        related_name='political_area_utilities',
        blank=False,
        null=False,
        verbose_name=_ug('Political Area')
    )
    hidden = models.BooleanField(
        default=False,
        blank=True
    )

    def __str__(self):
        return "%s %s" % (self.utility, self.political_area)

    def delete(self, *args):
        if self.hidden is True:
            super(PoliticalAreaUtility, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Political Area Utility')
        verbose_name_plural = _ug('Political Area Utilities')
        permissions = (
            ('query_politicalareautility', 'Query Political Area Utility'),
            ('list_politicalareautility', 'List Political Area Utilities'),
        )
Esempio n. 30
0
class Zip(models.Model):
    name = models.CharField(
        max_length=hardcode.zip_name_length,
        blank=False,
        null=False,
        verbose_name=_ug('Name')
    )
    political_area = models.ForeignKey(
        PoliticalArea,
        related_name='zips',
        blank=False,
        null=False,
        verbose_name=_ug('Political Area')
    )
    hidden = models.BooleanField(
        default=False,
        blank=True
    )

    def __str__(self):
        return "%s" % self.name

    def delete(self, *args):
        if self.hidden is True:
            super(Zip, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Zip')
        verbose_name_plural = _ug('Zips')
        permissions = (
            ('query_zip', 'Query Zip'),
            ('list_zip', 'List Zip'),
        )
Esempio n. 31
0
class PoliticalAreaType(models.Model):
    name = models.CharField(
        max_length=hardcode.politicalareatype_name_length,
        blank=False,
        null=False,
        verbose_name=_ug('Name')
    )
    parent = models.ForeignKey(
        'PoliticalAreaType',
        related_name='political_area_type',
        blank=True,
        null=True,
        verbose_name=_ug('Political Area Type')
    )
    hidden = models.BooleanField(
        default=False,
        blank=True
    )

    def __str__(self):
        return "%s" % self.name

    def delete(self, *args):
        if self.hidden is True:
            super(PoliticalAreaType, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Political Area Type')
        verbose_name_plural = _ug('Political Area Types')
        permissions = (
            ('query_politicalareatype', 'Query Political Area Type'),
            ('list_politicalareatype', 'List Political Area Types'),
        )
Esempio n. 32
0
class Privilege(models.Model):
    roles = models.ManyToManyField(Role,
                                   related_name='privileges',
                                   verbose_name=_ug('Roles'))
    created_by = models.ManyToManyField('CustomUser',
                                        related_name='privileges_created',
                                        verbose_name=_ug('Created by'))
    action = models.CharField(max_length=hardcode.privilege_action_length,
                              blank=False,
                              null=False,
                              verbose_name=_ug('Action'))
    can_read = models.BooleanField(default=False,
                                   blank=True,
                                   verbose_name=_ug('Can read?'))
    can_create = models.BooleanField(default=False,
                                     blank=True,
                                     verbose_name=_ug('Can create?'))
    can_update = models.BooleanField(default=False,
                                     blank=True,
                                     verbose_name=_ug('Can update?'))
    can_delete = models.BooleanField(default=False,
                                     blank=True,
                                     verbose_name=_ug('Can delete?'))
    can_execute = models.BooleanField(default=False,
                                      blank=True,
                                      verbose_name=_ug('Can execute?'))
    hidden = models.BooleanField(default=False, blank=True)

    def __str__(self):
        return "%s" % self.action

    def delete(self, *args):
        if self.hidden is True:
            super(Privilege, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Privilege')
        verbose_name_plural = _ug('Privileges')
        permissions = (
            ('query_privilege', 'Query Privilege'),
            ('list_privilege', 'List Privileges'),
        )
Esempio n. 33
0
def push_get(request, pk=None, env=None):
    instance = None
    if pk is not None and request.user.has_perm(
            '%s.change_%s' %
        (env.data_model._meta.app_label, env.model.lower())):
        new_instance = env.data_model.objects.get(pk=pk)
        instance = env.serializer(instance=new_instance)
    elif pk is None and request.user.has_perm(
            '%s.add_%s' % (env.data_model._meta.app_label, env.model.lower())):
        instance = env.serializer()
    else:
        msgs.generate_msg(
            request, msgs.RED, msgs.ERROR,
            _ug('A problem occurred. The action could not be completed.'))

    return instance
Esempio n. 34
0
def push_post(request, pk=None, env=None):
    # handle update after new data has been posted
    new_instance = instance_form = None
    if pk is not None and request.user.has_perm('%s.change_%s' % (env.data_model._meta.app_label, env.model.lower())):
        instance = env.data_model.objects.get(pk=pk)
        instance_form = env.serializer(data=request.POST, instance=instance)

        if instance_form.is_valid():
            new_instance = instance_form.save(user=request.user)

    # handle creation of new instances
    elif pk is None and request.user.has_perm('%s.add_%s' % (env.data_model._meta.app_label, env.model.lower())):
        instance_form = env.serializer(data=request.POST)
        if instance_form.is_valid():
            new_instance = instance_form.save(user=request.user)
    else:
        msgs.generate_msg(request, msgs.RED, msgs.ERROR, _ug('A problem occurred. The action could not be completed.'))
    return new_instance, instance_form
Esempio n. 35
0
class Post(models.Model):
    name = models.CharField(max_length=hardcode.post_name_length,
                            blank=False,
                            null=False,
                            verbose_name=_ug('Name'))
    description = models.CharField(max_length=hardcode.post_description_length,
                                   blank=True,
                                   null=True,
                                   verbose_name=_ug('Description'))
    rawrebate = models.ForeignKey(RawRebate,
                                  related_name='posts',
                                  blank=False,
                                  null=False,
                                  verbose_name=_ug('Raw Rebate'))
    created_at = models.DateTimeField(auto_now_add=True,
                                      verbose_name=_ug('Created at'))
    updated_at = models.DateTimeField(auto_now=True,
                                      verbose_name=_ug('Updated at'))
    parent = models.ForeignKey('Post',
                               related_name='sons',
                               blank=True,
                               null=True,
                               verbose_name=_ug('Parent Post'))
    user = models.ForeignKey(main_models.CustomUser,
                             related_name='posts',
                             blank=True,
                             null=True,
                             verbose_name=_ug('User'))
    hidden = models.BooleanField(default=False, blank=True)

    def __str__(self):
        return "%s" % self.name

    def delete(self, *args):
        if self.hidden is True:
            super(Post, self).delete(*args)
        else:
            self.hidden = True
            self.save()

    class Meta:
        verbose_name = _ug('Post')
        verbose_name_plural = _ug('Posts')
        permissions = (
            ('query_post', 'Query Post'),
            ('list_post', 'List Posts'),
        )
Esempio n. 36
0
from django.contrib import messages
from django.utils.translation import ugettext as _ug

GREEN = 'green'
BLUE = 'blue'
YELLOW = 'yellow'
RED = 'red'

SUCCESS = _ug('Success')
ERROR = _ug('Error')
WARNING = _ug('We are sorry')

errors_list = {
    'title': {
        '400': _ug('Bad Request'),
        '401': _ug('Unauthorized'),
        '403': _ug('Forbidden'),
        '404': _ug('Not Found'),
        '405': _ug('Method not allowed'),
        '406': _ug('Not Acceptable'),
        '409': _ug('Conflict'),
        '415': _ug('Unsupported Media Type'),
        '500': _ug('Internal Server Error'),
        '503': _ug('Service Unavailable'),
    },
    'body': {
        'no_action': _ug('We are sorry. You are trying to execute an unknown or prohibited action.'),
        'bad_login': _ug('The user/password combination is invalid. Please try again.'),
        'no_perm': _ug('You do not have enough permissions to execute this action. If this is a mistake, '
                       'please contact the administrator.'),
        'ticket': _ug('An internal error has occurred. The administrator has been notified.')