Exemplo n.º 1
0
def get_or_create_bbapp(user, modcol, modweight, modname):
    try:
        box = BbApps.objects.get(user=user, modname=modname)
        box.modcol = modcol
        box.modweight = modweight
        box.save()
    except ObjectDoesNotExist:
        box = BbApps(user=user,
                     modcol=modcol,
                     modweight=modweight,
                     modname=modname)
        box.save()
    return box
Exemplo n.º 2
0
    def render(self, context):
        obj_list = self.target.resolve(context, True)
        if obj_list == None:
            # target variable wasn't found in context; fail silently.
            context[self.var_name] = []
            return ''

        user = context['user']

        # initial saving
        for app in obj_list:
            modname = app['name']

            try:
                bbapp = BbApps.objects.get(user=user, modname=modname)

            except ObjectDoesNotExist:
                bbapp = BbApps(user=user,
                               modname=modname,
                               modcol=0,
                               modweight=0)
                bbapp.save()

        # here, all app list is saved into database
        items = []
        for col in [0, 1, 2]:
            new_obj_list = []
            bbapps = BbApps.objects.filter(user=user,
                                           modcol=col).order_by('modweight')
            for bbapp in bbapps:

                # populate obj_list
                for app in obj_list:
                    if app['name'] == bbapp.modname:  # obj exist
                        new_app = app
                        new_app['modcol'] = bbapp.modcol
                        new_app['modweight'] = bbapp.modweight

                        new_obj_list.append(new_app)

            items.append(new_obj_list)

        context[self.var_name] = items

        return ''