Ejemplo n.º 1
0
def new_tickets(requester, tipologies):
    tickets = []
    for i in range(0, 2):
        t = Ticket()
        t.requester = requester
        t.status = Ticket.STATUS.new
        t.content = 'foo ' * 20
        t.save()
        t.tipologies.add(*tipologies)
        t.initialize()
        tickets.append(t)
    return tickets
def new_tickets(requester, tipologies):
    tickets = []
    for i in range(0, 2):
        t = Ticket()
        t.requester = requester
        t.status = Ticket.STATUS.new
        t.content = 'foo ' * 20
        t.save()
        t.tipologies.add(*tipologies)
        t.initialize()
        tickets.append(t)
    return tickets
Ejemplo n.º 3
0
    def handle(self, *apps, **options):
        requester = None
        from django.conf import settings
        settings.INSTALLED_APPS = (
            list(settings.INSTALLED_APPS) + ['django.contrib.webdesign'])

        inithelpdesk.Command().execute(stdout=cStringIO(), stderr=cStringIO())

        default_site = Site.objects.get(pk=current_site_id())

        [source.sites.add(default_site) for source in Source.objects.all()]

        for c in range(0, 5):
            category, c_created = Category.objects.get_or_create(
                title='category {}'.format(c))
            for i in range(0, 5):
                category.tipologies.get_or_create(
                    title='tipology {}'.format(i))
            [t.sites.add(default_site) for t in category.tipologies.all()]

        for group_name, pc in [HELPDESK_REQUESTERS, HELPDESK_OPERATORS,
                               HELPDESK_ADMINS]:
            username = group_name.rstrip('s')

            try:
                huser = HelpdeskUser.objects.get(username=username)
                self.stdout.write('User "{}" is already exists'.format(
                    username))
            except HelpdeskUser.DoesNotExist:
                huser = HelpdeskUser.objects.create_user(
                    username, email='{}@example.com'.format(username),
                    password='******')
                self.stdout.write('User "{}" is created'.format(username))
            huser.is_staff = True
            huser.save()
            huser.groups.add(Group.objects.get(name=group_name))
            self.stdout.write('Group "{}" is added to "{}"'.format(group_name,
                                                                   username))

            t = Template("{% load webdesign %} {% lorem 5 w random %}.")
            tipologies = Tipology.objects.all()
            cursor = connection.cursor()
            user = User.objects.get(pk=huser.pk)
            if group_name == HELPDESK_REQUESTERS[0]:
                requester = user
                Ticket.objects.all().delete()
                for table in ['ticket', 'message']:
                    cursor.execute("SELECT setval("
                                   "'public.openhelpdesk_{}_id_seq',"
                                   "  1, true);".format(table))

                for n, priority in enumerate(PRIORITIES):
                    ticket = Ticket()
                    ticket.priority = priority[0]
                    ticket.requester = user
                    ticket.content = t.render(Context({}))
                    ticket.site = default_site
                    ticket.source = Source.objects.get(
                        code='web_site' if n % 2 == 1 else 'email')
                    ticket.save()
                    ticket.tipologies.add(*tipologies[0:2])
                    ticket.initialize()

                    [ticket.messages.create(
                        content=Template("{% load webdesign %} {% lorem 5 w"
                                         " random %}.").render(Context({})),
                        sender=user) for ti in range(0, 3)]

                print("Tickets: ", Ticket.objects.all())
                print("Messages: ", Message.objects.all())
                print("Reports: ", Report.objects.all())

            if group_name == HELPDESK_OPERATORS[0]:
                for n, ticket in enumerate(Ticket.objects.all()):
                    [Report.objects.create(
                        ticket=ticket, sender=user, recipient=requester,
                        content=Template("{% load webdesign %} {% lorem 5 w"
                                         " random %}.").render(Context({})))
                     for ri in range(0, 3)]
                    if n % 2 == 1:
                        ticket.opening(user)